Certain malformed queries such as "SELECT ,* FROM SomeTable" (which has an incorrect extra comma) raise "multiple statements given" error while Sqlite3 actually generates a syntax error that doesn't get returned as a raised exception.

The same problem is encountered when executing a DDL statement such as "Create Table" more than once after the table had already been created by the first execution.

The cause is when sqlite3_prepare_v2 encounters a bad statement, it aborts the preparation, sets prep-status flag to non-zero and also sets tail? to be non-false.

The previous code ignored the prep-status flag and only checked tail? and raises "multiple statements given" exception when tail? is non-false.

The new code takes prep-status into account and extracts the actual Sqlite3 error message by evaluating get-error-message and raising it as an exception.

See Issue #1702
This commit is contained in:
Alexander McLin 2017-05-24 13:55:02 -04:00 committed by Ryan Culpepper
parent 5dbeb39a01
commit 31d7dd0317

View File

@ -212,10 +212,16 @@
;; entry of stmt in table.
(A (let-values ([(prep-status stmt tail?)
(sqlite3_prepare_v2 db sql)])
(when tail?
(when stmt (sqlite3_finalize stmt))
(error* fsym "multiple statements given"
'("given" value) sql))
(cond
[(not (= 0 prep-status))
(when stmt (sqlite3_finalize stmt))
(error* fsym (get-error-message)
'("given" value) sql)]
[else
(when tail?
(when stmt (sqlite3_finalize stmt))
(error* fsym "multiple statements given"
'("given" value) sql))])
(when stmt (hash-set! stmt-table stmt #t))
(values prep-status stmt))))])
(when DEBUG?