From 0fbebfdc6c24eb8a2a71c6f389330fc4a9b82535 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Tue, 10 Oct 2006 21:53:12 +0000 Subject: [PATCH] - sync: support forced insertion, e.g. if primary key is being explicitly provided --- PLC/Table.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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)) -- 2.47.0