From: Mark Huang Date: Tue, 10 Oct 2006 20:27:43 +0000 (+0000) Subject: sync: insert if the primary key (usually an auto-incrementing serial X-Git-Tag: pycurl-7_13_1~630 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=04b3661f520ea3b487d98d9e5caf153f8d307077;p=plcapi.git sync: insert 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. --- diff --git a/PLC/Table.py b/PLC/Table.py index 1300cf14..be126a65 100644 --- a/PLC/Table.py +++ b/PLC/Table.py @@ -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))