From 31d7dd03175a11cdd613d8b7d80b74ec0ced8f05 Mon Sep 17 00:00:00 2001 From: Alexander McLin Date: Wed, 24 May 2017 13:55:02 -0400 Subject: [PATCH] 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 --- racket/collects/db/private/sqlite3/connection.rkt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/racket/collects/db/private/sqlite3/connection.rkt b/racket/collects/db/private/sqlite3/connection.rkt index 79e312c7c5..440c973b07 100644 --- a/racket/collects/db/private/sqlite3/connection.rkt +++ b/racket/collects/db/private/sqlite3/connection.rkt @@ -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?