Permalink
Browse files

make primary key options for db insert

  • Loading branch information...
1 parent 5e68b90 commit a6e9462642ab84da6434f8028d880ec86f5d2798 @artnez committed May 13, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 src/faceoff/db.py
View
@@ -235,14 +235,15 @@ def insert(self, table, pk=None, **fields):
Creates a record with primary key `pk` in `table` with the given data.
If no `pk` is specified, it is uniquely generated.
"""
- fields['id'] = pk or self.generate_pk(table)
+ if pk is not False:
+ fields['id'] = pk or self.generate_pk(table)
query = 'INSERT INTO "%(table)s" ("%(names)s") VALUES (%(param)s)' % {
'table': self.clean(table),
'names': '","'.join(map(self.clean, fields.keys())),
'param': ','.join(['?'] * len(fields))
}
self.execute(query, fields.values())
- return fields['id']
+ return fields['id'] if fields.has_key('id') else True
def update(self, table, pk, **fields):
"""

0 comments on commit a6e9462

Please sign in to comment.