Skip to content
Snippets Groups Projects
Commit b1c2eb47 authored by Renaud Le Gac's avatar Renaud Le Gac
Browse files

First version of the service delete.

parent 437089d6
No related branches found
No related tags found
No related merge requests found
......@@ -16,11 +16,13 @@ __version__ = "$Revision"
import re
from gluon.contrib import simplejson as json
#from tools import debug
import sqlite3
RECORD_IS_DELETED = "Record id %i deleted"
FIELD_BAD_SYNTAX = "The syntax of the request field %s is wrong: db.table.field"
FIELD_BAD_TABLE = "Table defined in the request field %s doesn't exist."
FIELD_BAD_FIELD = "Field defined in the request field %s doesn't exist."
ID_MISSING = "The keyword id is not defined."
INSERT_SUCCESSFUL = "Data insert successfully."
SVC_INVALID = "Requested service doesn't exist."
SVC_NOT_DEFINED = "The keyword service is not defined."
......@@ -168,11 +170,36 @@ class HttpDb:
def delete(self):
"""Delete data in the database.
Delete a record identified by its id.
Mandatory steering keywords are: service, table and id.
Return a dictionary with status and error message:
{success: False, msg: 'blalbla'}
"""
return {"success": False, "msg": SVC_NOT_IMPLEMENTED}
if self._debug():
print "Start HttpDb.debug service."
# Check table
if "table" not in self._vars:
resp = {"success": False, "msg": TABLE_MISSING}
return resp
# Check id
if "id" not in self._vars:
resp = {"success": False, "msg": ID_MISSING}
return resp
# Delete the record
id = int(self._vars.id)
table = self._vars.table
try:
del self._db[table][id]
except sqlite3.Error, e:
return {"success": False, "msg": e.message}
return {"success": True, "msg": RECORD_IS_DELETED % id}
def get_defaults(self): pass
def get_fields(self): pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment