Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Shorter way to get the last insertion ID.

  • Loading branch information...
commit 6de0cf7ef5b5edfba1affe7a0ef8b11ae1622a2f 1 parent a0e4dce
@kgaughan authored
Showing with 8 additions and 8 deletions.
  1. +5 −0 dbkit.py
  2. +3 −8 examples/notary/notary.py
View
5 dbkit.py
@@ -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)
View
11 examples/notary/notary.py
@@ -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):
Please sign in to comment.
Something went wrong with that request. Please try again.