aboutsummaryrefslogtreecommitdiffstats
path: root/src/sqlite.c
diff options
context:
space:
mode:
authorLars Ingebrigtsen2022-10-09 16:17:22 +0200
committerLars Ingebrigtsen2022-10-09 16:17:22 +0200
commitb5dc0513d53cf0e520c8e9c4ca197cb7ccdf2b23 (patch)
treea3e6212633cf1a2c1c4510a20e8b71b0fdaa3985 /src/sqlite.c
parent0ce91ed8b478364a69502751d86bf5c5568a429c (diff)
downloademacs-b5dc0513d53cf0e520c8e9c4ca197cb7ccdf2b23.tar.gz
emacs-b5dc0513d53cf0e520c8e9c4ca197cb7ccdf2b23.zip
Make Fsqlite_select error data better
* src/sqlite.c (Fsqlite_select): Add more the more specific error text to the error data (bug#58363).
Diffstat (limited to 'src/sqlite.c')
-rw-r--r--src/sqlite.c18
1 files changed, 11 insertions, 7 deletions
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
521 xsignal1 (Qerror, build_string ("VALUES must be a list or a vector")); 521 xsignal1 (Qerror, build_string ("VALUES must be a list or a vector"));
522 522
523 sqlite3 *sdb = XSQLITE (db)->db; 523 sqlite3 *sdb = XSQLITE (db)->db;
524 Lisp_Object retval = Qnil; 524 Lisp_Object retval = Qnil, errmsg = Qnil,
525 const char *errmsg = NULL; 525 encoded = encode_string (query);
526 Lisp_Object encoded = encode_string (query);
527 526
528 sqlite3_stmt *stmt = NULL; 527 sqlite3_stmt *stmt = NULL;
529 int ret = sqlite3_prepare_v2 (sdb, SSDATA (encoded), SBYTES (encoded), 528 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
532 { 531 {
533 if (stmt) 532 if (stmt)
534 sqlite3_finalize (stmt); 533 sqlite3_finalize (stmt);
535 errmsg = sqlite3_errstr (ret); 534 errmsg = build_string (sqlite3_errstr (ret));
535 /* More details about what went wrong. */
536 const char *sql_error = sqlite3_errmsg (sdb);
537 if (sql_error)
538 errmsg = CALLN (Fformat, build_string ("%s (%s)"),
539 errmsg, build_string (sql_error));
536 goto exit; 540 goto exit;
537 } 541 }
538 542
@@ -543,7 +547,7 @@ which means that we return a set object that can be queried with
543 if (err != NULL) 547 if (err != NULL)
544 { 548 {
545 sqlite3_finalize (stmt); 549 sqlite3_finalize (stmt);
546 errmsg = err; 550 errmsg = build_string (err);
547 goto exit; 551 goto exit;
548 } 552 }
549 } 553 }
@@ -567,8 +571,8 @@ which means that we return a set object that can be queried with
567 sqlite3_finalize (stmt); 571 sqlite3_finalize (stmt);
568 572
569 exit: 573 exit:
570 if (errmsg != NULL) 574 if (! NILP (errmsg))
571 xsignal1 (Qerror, build_string (errmsg)); 575 xsignal1 (Qerror, errmsg);
572 576
573 return retval; 577 return retval;
574} 578}