]> git.eshelyaron.com Git - emacs.git/commitdiff
Make Fsqlite_select error data better
authorLars Ingebrigtsen <larsi@gnus.org>
Sun, 9 Oct 2022 14:17:22 +0000 (16:17 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Sun, 9 Oct 2022 14:17:22 +0000 (16:17 +0200)
* src/sqlite.c (Fsqlite_select): Add more the more specific error
text to the error data (bug#58363).

src/sqlite.c

index a46acf8523ac22d913e296a90661ba55c4665f3b..ababa73b99f1339fe3c2e72fe7912585ae1e5d29 100644 (file)
@@ -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;
 }