From: Lars Ingebrigtsen Date: Sun, 9 Oct 2022 14:17:22 +0000 (+0200) Subject: Make Fsqlite_select error data better X-Git-Tag: emacs-29.0.90~1616^2~681 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=b5dc0513d53cf0e520c8e9c4ca197cb7ccdf2b23;p=emacs.git Make Fsqlite_select error data better * src/sqlite.c (Fsqlite_select): Add more the more specific error text to the error data (bug#58363). --- diff --git a/src/sqlite.c b/src/sqlite.c index a46acf8523a..ababa73b99f 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -521,9 +521,8 @@ which means that we return a set object that can be queried with xsignal1 (Qerror, build_string ("VALUES must be a list or a vector")); sqlite3 *sdb = XSQLITE (db)->db; - Lisp_Object retval = Qnil; - const char *errmsg = NULL; - Lisp_Object encoded = encode_string (query); + Lisp_Object retval = Qnil, errmsg = Qnil, + encoded = encode_string (query); sqlite3_stmt *stmt = NULL; int ret = sqlite3_prepare_v2 (sdb, SSDATA (encoded), SBYTES (encoded), @@ -532,7 +531,12 @@ which means that we return a set object that can be queried with { if (stmt) sqlite3_finalize (stmt); - errmsg = sqlite3_errstr (ret); + errmsg = build_string (sqlite3_errstr (ret)); + /* More details about what went wrong. */ + const char *sql_error = sqlite3_errmsg (sdb); + if (sql_error) + errmsg = CALLN (Fformat, build_string ("%s (%s)"), + errmsg, build_string (sql_error)); goto exit; } @@ -543,7 +547,7 @@ which means that we return a set object that can be queried with if (err != NULL) { sqlite3_finalize (stmt); - errmsg = err; + errmsg = build_string (err); goto exit; } } @@ -567,8 +571,8 @@ which means that we return a set object that can be queried with sqlite3_finalize (stmt); exit: - if (errmsg != NULL) - xsignal1 (Qerror, build_string (errmsg)); + if (! NILP (errmsg)) + xsignal1 (Qerror, errmsg); return retval; }