Permalink
Browse files

Shorter way to get the last insertion ID.

  • Loading branch information...
1 parent a0e4dce commit 6de0cf7ef5b5edfba1affe7a0ef8b11ae1622a2f @kgaughan committed Oct 12, 2012
Showing with 8 additions and 8 deletions.
  1. +5 −0 dbkit.py
  2. +3 −8 examples/notary/notary.py
View
@@ -619,6 +619,11 @@ def wrapper(*args, **kwargs):
return functools.update_wrapper(wrapper, wrapped)
+def last_row_id():
+ """Return the row ID of the last (insert) statement."""
+ return Context.current().last_row_id
+
+
def execute(stmt, args=()):
"""Execute an SQL statement. Returns the number of affected rows."""
cursor = Context.current().execute(stmt, args)
@@ -43,11 +43,6 @@ def slugify(s):
return re.sub('[^a-z0-9]+', ' ', s).strip().replace(' ', '-')
-def get_last_row_id():
- """Returns the row ID of the last insert statement."""
- return dbkit.query_value("SELECT LAST_INSERT_ROWID()")
-
-
def get_projects():
return dbkit.query("""
SELECT slug, project, COUNT(note_id) AS notes
@@ -70,9 +65,9 @@ def get_project(slug):
def add_project(project):
slug = slugify(project)
dbkit.execute("""
- INSERT INTO projects (project, slug) VALUES (?, ?)
+ INSERT INTO projects (project, slug, overview) VALUES (?, ?, '')
""", (project, slug))
- return (get_last_row_id(), slug)
+ return (dbkit.last_row_id(), slug)
def get_notes(project_id):
@@ -89,7 +84,7 @@ def save_note(project_id, note):
dbkit.execute("""
INSERT INTO notes (project_id, note) VALUES (?, ?)
""", (project_id, note))
- return get_last_row_id()
+ return dbkit.last_row_id()
class Frontpage(object):

0 comments on commit 6de0cf7

Please sign in to comment.