From: Mark Huang Date: Tue, 10 Oct 2006 21:53:12 +0000 (+0000) Subject: - sync: support forced insertion, e.g. if primary key is being explicitly provided X-Git-Tag: pycurl-7_13_1~625 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=0fbebfdc6c24eb8a2a71c6f389330fc4a9b82535;p=plcapi.git - sync: support forced insertion, e.g. if primary key is being explicitly provided --- diff --git a/PLC/Table.py b/PLC/Table.py index be126a65..e76707d6 100644 --- a/PLC/Table.py +++ b/PLC/Table.py @@ -38,7 +38,7 @@ class Row(dict): validate = getattr(self, 'validate_' + key) self[key] = validate(value) - def sync(self, commit = True): + def sync(self, commit = True, insert = None): """ Flush changes back to the database. """ @@ -61,8 +61,10 @@ class Row(dict): # If the primary key (usually an auto-incrementing serial # identifier) has not been specified, or the primary key is the - # only field in the table. - if not self.has_key(self.primary_key) or all_fields == [self.primary_key]: + # only field in the table, or insert has been forced. + if not self.has_key(self.primary_key) or \ + all_fields == [self.primary_key] or \ + insert is True: # Insert new row sql = "INSERT INTO %s (%s) VALUES (%s);" % \ (self.table_name, ", ".join(keys), ", ".join(values))