Skip to content

Commit

Permalink
Get better errors by using prepare_v2
Browse files Browse the repository at this point in the history
  • Loading branch information
rassilon authored and jgoerzen committed Mar 30, 2011
1 parent 02e9b17 commit 256145d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Database/HDBC/Sqlite3/Statement.hsc
Expand Up @@ -153,9 +153,11 @@ fstep dbo p =
{seState = "",
seNativeError = 0,
seErrorMsg = "In HDBC step, internal processing error (got SQLITE_ERROR with no error)"})
x -> throwSqlError $ SqlError {seState = "",
seNativeError = fromIntegral x,
seErrorMsg = "In HDBC step, unexpected result from sqlite3_step"}
x -> checkError "step" dbo x
>> (throwSqlError $ SqlError
{seState = "",
seNativeError = fromIntegral x,
seErrorMsg = "In HDBC step, internal processing error (got error code with no error)"})

fexecute sstate args = modifyMVar (stomv sstate) doexecute
where doexecute (Executed sto) = doexecute (Prepared sto)
Expand Down Expand Up @@ -216,7 +218,7 @@ fexecuteRaw dbo query =
case result of
#{const SQLITE_OK} -> return ()
s -> do
checkError "exec" dbo #{const SQLITE_ERROR}
checkError "exec" dbo s
throwSqlError $ SqlError
{seState = "",
seNativeError = fromIntegral s,
Expand Down
6 changes: 6 additions & 0 deletions hdbc-sqlite3-helper.c
Expand Up @@ -91,8 +91,14 @@ int sqlite3_prepare2(finalizeonce *fdb, const char *zSql,
#ifdef DEBUG_HDBC_SQLITE3
fprintf(stderr, "\nCalling prepare on %p", db);
#endif
#if SQLITE_VERSION_NUMBER > 3003011
res = sqlite3_prepare_v2(db, zSql, nBytes, &ppst,
pzTail);
#else
res = sqlite3_prepare(db, zSql, nBytes, &ppst,
pzTail);
#endif

/* We don't try to deallocate this in Haskell if there
was an error. */
if (res != SQLITE_OK) {
Expand Down

0 comments on commit 256145d

Please sign in to comment.