Skip to content

Commit

Permalink
Cleanups, refs #353
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed May 14, 2014
1 parent bb50ff8 commit 7ba2d2a
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions peewee.py
Original file line number Diff line number Diff line change
Expand Up @@ -2528,21 +2528,23 @@ def _connect(self, database, **kwargs):

def last_insert_id(self, cursor, model):
meta = model._meta
seq = meta.primary_key.sequence
schema = ''
if meta.schema:
schema = '%s.' % meta.schema
result = None

if meta.primary_key.sequence:
seq = meta.primary_key.sequence
elif meta.auto_increment:
seq = '%s_%s_seq' % (meta.db_table, meta.primary_key.db_column)
else:
seq = None

if seq:
cursor.execute("SELECT CURRVAL('%s\"%s\"')" % (schema, seq))
result = cursor.fetchone()[0]
elif meta.auto_increment:
cursor.execute("SELECT CURRVAL('%s\"%s_%s_seq\"')" % (
schema, meta.db_table, meta.primary_key.db_column))
result = cursor.fetchone()[0]
if self.get_autocommit():
self.commit()
return result
if self.get_autocommit():
self.commit()
return result

def get_indexes_for_table(self, table):
res = self.execute_sql("""
Expand Down

0 comments on commit 7ba2d2a

Please sign in to comment.