git://git.onelab.eu
/
plcapi.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0f1a34a
)
obtain integer primary keys by calling nextval() on the sequence instead of quering...
author
Tony Mack
<tmack@cs.princeton.edu>
Tue, 3 Jun 2008 02:25:07 +0000
(
02:25
+0000)
committer
Tony Mack
<tmack@cs.princeton.edu>
Tue, 3 Jun 2008 02:25:07 +0000
(
02:25
+0000)
PLC/Table.py
patch
|
blob
|
history
diff --git
a/PLC/Table.py
b/PLC/Table.py
index
2362d61
..
74da3e9
100644
(file)
--- a/
PLC/Table.py
+++ b/
PLC/Table.py
@@
-1,4
+1,4
@@
-from types import StringTypes
+from types import StringTypes
, IntType, LongType
import time
import calendar
import time
import calendar
@@
-230,6
+230,14
@@
class Row(dict):
if not self.has_key(self.primary_key) or \
keys == [self.primary_key] or \
insert is True:
if not self.has_key(self.primary_key) or \
keys == [self.primary_key] or \
insert is True:
+
+ # If primary key id is a serial int, get next id
+ if self.fields[self.primary_key].type in (IntType, LongType):
+ pk_id = self.api.db.next_id(self.table_name, self.primary_key)
+ self[self.primary_key] = pk_id
+ db_fields[self.primary_key] = pk_id
+ keys = db_fields.keys()
+ values = [self.api.db.param(key, value) for (key, value) in db_fields.items()]
# Insert new row
sql = "INSERT INTO %s (%s) VALUES (%s)" % \
(self.table_name, ", ".join(keys), ", ".join(values))
# Insert new row
sql = "INSERT INTO %s (%s) VALUES (%s)" % \
(self.table_name, ", ".join(keys), ", ".join(values))
@@
-244,9
+252,6
@@
class Row(dict):
self.api.db.do(sql, db_fields)
self.api.db.do(sql, db_fields)
- if not self.has_key(self.primary_key):
- self[self.primary_key] = self.api.db.last_insert_id(self.table_name, self.primary_key)
-
if commit:
self.api.db.commit()
if commit:
self.api.db.commit()