DEF_DLL_FN (SQLITE_API int, sqlite3_bind_double, (sqlite3_stmt*, int, double));
DEF_DLL_FN (SQLITE_API int, sqlite3_bind_null, (sqlite3_stmt*, int));
DEF_DLL_FN (SQLITE_API int, sqlite3_bind_int, (sqlite3_stmt*, int, int));
+DEF_DLL_FN (SQLITE_API int, sqlite3_extended_errcode, (sqlite3*));
DEF_DLL_FN (SQLITE_API const char*, sqlite3_errmsg, (sqlite3*));
DEF_DLL_FN (SQLITE_API const char*, sqlite3_errstr, (int));
DEF_DLL_FN (SQLITE_API int, sqlite3_step, (sqlite3_stmt*));
# undef sqlite3_bind_double
# undef sqlite3_bind_null
# undef sqlite3_bind_int
+# undef sqlite3_extended_errcode
# undef sqlite3_errmsg
# undef sqlite3_errstr
# undef sqlite3_step
# define sqlite3_bind_double fn_sqlite3_bind_double
# define sqlite3_bind_null fn_sqlite3_bind_null
# define sqlite3_bind_int fn_sqlite3_bind_int
+# define sqlite3_extended_errcode fn_sqlite3_extended_errcode
# define sqlite3_errmsg fn_sqlite3_errmsg
# define sqlite3_errstr fn_sqlite3_errstr
# define sqlite3_step fn_sqlite3_step
LOAD_DLL_FN (library, sqlite3_bind_double);
LOAD_DLL_FN (library, sqlite3_bind_null);
LOAD_DLL_FN (library, sqlite3_bind_int);
+ LOAD_DLL_FN (library, sqlite3_extended_errcode);
LOAD_DLL_FN (library, sqlite3_errmsg);
LOAD_DLL_FN (library, sqlite3_errstr);
LOAD_DLL_FN (library, sqlite3_step);
init_sqlite_functions ();
CHECK_SQLITE (db);
if (is_statement && !XSQLITE (db)->is_statement)
- xsignal1 (Qerror, build_string ("Invalid set object"));
+ xsignal1 (Qsqlite_error, build_string ("Invalid set object"));
else if (!is_statement && XSQLITE (db)->is_statement)
- xsignal1 (Qerror, build_string ("Invalid database object"));
+ xsignal1 (Qsqlite_error, build_string ("Invalid database object"));
if (!is_statement && !XSQLITE (db)->db)
- xsignal1 (Qerror, build_string ("Database closed"));
+ xsignal1 (Qsqlite_error, build_string ("Database closed"));
else if (is_statement && !XSQLITE (db)->db)
- xsignal1 (Qerror, build_string ("Statement closed"));
+ xsignal1 (Qsqlite_error, build_string ("Statement closed"));
}
static int db_count = 0;
#endif
if (!init_sqlite_functions ())
- xsignal1 (Qerror, build_string ("sqlite support is not available"));
+ xsignal1 (Qsqlite_error, build_string ("sqlite support is not available"));
if (!NILP (file))
name = ENCODE_FILE (Fexpand_file_name (file, Qnil));
name = CALLN (Fformat, memory_fmt, make_int (++db_count));
flags |= SQLITE_OPEN_MEMORY;
#else
- xsignal1 (Qerror, build_string ("sqlite in-memory is not available"));
+ xsignal1 (Qsqlite_error, build_string ("sqlite in-memory is not available"));
#endif
}
if (blob)
{
if (SBYTES (value) != SCHARS (value))
- xsignal1 (Qerror, build_string ("BLOB values must be unibyte"));
+ xsignal1 (Qsqlite_error, build_string ("BLOB values must be unibyte"));
ret = sqlite3_bind_blob (stmt, i + 1,
SSDATA (value), SBYTES (value),
NULL);
}
static Lisp_Object
-sqlite_prepare_errmsg (int code, sqlite3 *sdb)
+sqlite_prepare_errdata (int code, sqlite3 *sdb)
{
- Lisp_Object errmsg = build_string (sqlite3_errstr (code));
+ Lisp_Object errstr = build_string (sqlite3_errstr (code));
+ Lisp_Object errcode = make_fixnum (code);
/* More details about what went wrong. */
- const char *sql_error = sqlite3_errmsg (sdb);
- if (sql_error)
- return CALLN (Fformat, build_string ("%s (%s)"),
- errmsg, build_string (sql_error));
- else
- return errmsg;
+ Lisp_Object ext_errcode = make_fixnum (sqlite3_extended_errcode (sdb));
+ const char *errmsg = sqlite3_errmsg (sdb);
+ return list4 (errstr, errmsg ? build_string (errmsg) : Qnil,
+ errcode, ext_errcode);
}
DEFUN ("sqlite-execute", Fsqlite_execute, Ssqlite_execute, 2, 3, 0,
check_sqlite (db, false);
CHECK_STRING (query);
if (!(NILP (values) || CONSP (values) || VECTORP (values)))
- xsignal1 (Qerror, build_string ("VALUES must be a list or a vector"));
+ xsignal1 (Qsqlite_error, build_string ("VALUES must be a list or a vector"));
sqlite3 *sdb = XSQLITE (db)->db;
Lisp_Object errmsg = Qnil,
sqlite3_reset (stmt);
}
- errmsg = sqlite_prepare_errmsg (ret, sdb);
+ errmsg = sqlite_prepare_errdata (ret, sdb);
goto exit;
}
exit:
sqlite3_finalize (stmt);
xsignal1 (ret == SQLITE_LOCKED || ret == SQLITE_BUSY?
- Qsqlite_locked_error: Qerror,
+ Qsqlite_locked_error: Qsqlite_error,
errmsg);
}
CHECK_STRING (query);
if (!(NILP (values) || CONSP (values) || VECTORP (values)))
- xsignal1 (Qerror, build_string ("VALUES must be a list or a vector"));
+ xsignal1 (Qsqlite_error, build_string ("VALUES must be a list or a vector"));
sqlite3 *sdb = XSQLITE (db)->db;
Lisp_Object retval = Qnil, errmsg = Qnil,
{
if (stmt)
sqlite3_finalize (stmt);
- errmsg = sqlite_prepare_errmsg (ret, sdb);
+ errmsg = sqlite_prepare_errdata (ret, sdb);
goto exit;
}
exit:
if (! NILP (errmsg))
- xsignal1 (Qerror, errmsg);
+ xsignal1 (Qsqlite_error, errmsg);
return retval;
}
}
if (!do_allow)
- xsignal (Qerror, build_string ("Module name not on allowlist"));
+ xsignal1 (Qsqlite_error, build_string ("Module name not on allowlist"));
int result = sqlite3_load_extension
(XSQLITE (db)->db,
int ret = sqlite3_step (XSQLITE (set)->stmt);
if (ret != SQLITE_ROW && ret != SQLITE_OK && ret != SQLITE_DONE)
- xsignal1 (Qerror, build_string (sqlite3_errmsg (XSQLITE (set)->db)));
+ xsignal1 (Qsqlite_error, build_string (sqlite3_errmsg (XSQLITE (set)->db)));
if (ret == SQLITE_DONE)
{
defsubr (&Ssqlitep);
defsubr (&Ssqlite_available_p);
+ DEFSYM (Qsqlite_error, "sqlite-error");
+ Fput (Qsqlite_error, Qerror_conditions,
+ Fpurecopy (list2 (Qsqlite_error, Qerror)));
+ Fput (Qsqlite_error, Qerror_message,
+ build_pure_c_string ("Database error"));
+
DEFSYM (Qsqlite_locked_error, "sqlite-locked-error");
Fput (Qsqlite_locked_error, Qerror_conditions,
- Fpurecopy (list2 (Qsqlite_locked_error, Qerror)));
+ Fpurecopy (list3 (Qsqlite_locked_error, Qsqlite_error, Qerror)));
Fput (Qsqlite_locked_error, Qerror_message,
build_pure_c_string ("Database locked"));