sync: insert if the primary key (usually an auto-incrementing serial
authorMark Huang <mlhuang@cs.princeton.edu>
Tue, 10 Oct 2006 20:27:43 +0000 (20:27 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Tue, 10 Oct 2006 20:27:43 +0000 (20:27 +0000)
identifier) has not been specified, or the primary key is the only field
in the table.

PLC/Table.py

index 1300cf1..be126a6 100644 (file)
@@ -59,7 +59,10 @@ class Row(dict):
         keys = fields.keys()
         values = [self.api.db.param(key, value) for (key, value) in fields.items()]
 
-        if not self.has_key(self.primary_key):
+        # 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]:
             # Insert new row
             sql = "INSERT INTO %s (%s) VALUES (%s);" % \
                   (self.table_name, ", ".join(keys), ", ".join(values))