diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2014-02-01 15:56:19 -0800 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2014-02-01 15:56:19 -0800 |
commit | 602723f894c1b6dcee29193fd83359690c0f18c4 (patch) | |
tree | 1a05902f2e293ebafd07344fa45ee6cff313f285 /lib/impure/db_sqlite.nim | |
parent | fccb0170d4a015b1d7f38873ccdf77e2cf146b4f (diff) | |
parent | d07f86b1597b17bf13ae51cc7912f378b56aa9f3 (diff) | |
download | Nim-602723f894c1b6dcee29193fd83359690c0f18c4.tar.gz |
Merge pull request #855 from gradha/pr_fixes_try_insert_id
Avoids raising exceptions in tryInsertID.
Diffstat (limited to 'lib/impure/db_sqlite.nim')
-rw-r--r-- | lib/impure/db_sqlite.nim | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/impure/db_sqlite.nim b/lib/impure/db_sqlite.nim index a3499a6df..809ee7039 100644 --- a/lib/impure/db_sqlite.nim +++ b/lib/impure/db_sqlite.nim @@ -148,7 +148,8 @@ proc getValue*(db: TDbConn, query: TSqlQuery, if finalize(stmt) != SQLITE_OK: dbError(db) proc tryInsertID*(db: TDbConn, query: TSqlQuery, - args: varargs[string, `$`]): int64 {.tags: [FWriteDb].} = + args: varargs[string, `$`]): int64 + {.tags: [FWriteDb], raises: [].} = ## executes the query (typically "INSERT") and returns the ## generated ID for the row or -1 in case of an error. var q = dbFormat(query, args) @@ -157,7 +158,8 @@ proc tryInsertID*(db: TDbConn, query: TSqlQuery, if prepare_v2(db, q, q.len.cint, stmt, nil) == SQLITE_OK: if step(stmt) == SQLITE_DONE: result = last_insert_rowid(db) - if finalize(stmt) != SQLITE_OK: dbError(db) + if finalize(stmt) != SQLITE_OK: + result = -1 proc insertID*(db: TDbConn, query: TSqlQuery, args: varargs[string, `$`]): int64 {.tags: [FWriteDb].} = |