diff --git a/modules/plugin_dbui/dbsvc.py b/modules/plugin_dbui/dbsvc.py index 18084be1b3b45aae3af45bfdb8a51aee4f87854a..8145f6b38d63ea45c9e946f4a587ade41c3ad6ca 100644 --- a/modules/plugin_dbui/dbsvc.py +++ b/modules/plugin_dbui/dbsvc.py @@ -18,6 +18,7 @@ RECORD_INSERTED = "Record is inserted with id %i." RECORD_NOT_IN_DB = "The record '%s' doesn't exist in the table %s." RECORD_UPDATED = "Record %s is updated." TABLE_NOT_IN_DB = "The table '%s' doesn't exist in the database." +TO_MANY_RECORDS = "To many records !!!" class DbSvcException(BaseException): pass @@ -135,7 +136,7 @@ class DbSvc(BaseSvc): [(table1, field1), (table1, field2), (table2, field3), ...] records (ROOT) - A dictionary containing the new / update values for field + List of dictionary containing the new / update values for field as well as the identifier of the record to be updated (id) Return a dictionary {fieldName: value, ...} @@ -145,21 +146,26 @@ class DbSvc(BaseSvc): fields = {} table = arg['tableName'] + # protection + if len(arg[ROOT]) > 1: + raise DbSvcException(TO_MANY_RECORDS) + # Remove fields in the record which do not belong to the table. # The JsonStore send the foreign key and the the pointing field # when manipulating table with foreign keys. the latter belongs # to another table. - for record in arg[ROOT]: - for table_field in record: - tablename, fieldname = decode_field(table_field) - if tablename == table: - fields[fieldname.encode('utf8')] = record[table_field] + record = arg[ROOT][0] + for table_field in record: + tablename, fieldname = decode_field(table_field) + if tablename == table: + fields[fieldname.encode('utf8')] = record[table_field] # Validate field contents di = self._is_fields_values_valid(table, fields) if di: table_id = encode_field(table, 'id') - return {SUCCESS: False, "errors": di, ROOT: {table_id: -1}} + record[table_id] = "" + return {SUCCESS: False, "errors": di, ROOT: record} return fields