Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print more detailed ("extended") error code in SQLite3 code #1479

Merged
merged 2 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions patch/sqlite3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e

patch src/database/shell.c patches/sqlite3/0001-print-FTL-version-in-interactive-shell.patch
patch src/database/sqlite3.c patches/sqlite3/0002-make-sqlite3ErrName-public.patch
30 changes: 30 additions & 0 deletions patch/sqlite3/0001-print-FTL-version-in-interactive-shell.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/src/database/shell.c b/src/database/shell.c
index 6280ebf6..a5e82f70 100644
--- a/src/database/shell.c
+++ b/src/database/shell.c
@@ -126,6 +126,8 @@ typedef unsigned char u8;
#endif
#include <ctype.h>
#include <stdarg.h>
+// print_FTL_version()
+#include "../log.h"

#if !defined(_WIN32) && !defined(WIN32)
# include <signal.h>
@@ -25855,7 +25857,7 @@ static char *cmdline_option_value(int argc, char **argv, int i){
#endif

#if SQLITE_SHELL_IS_UTF8
-int SQLITE_CDECL main(int argc, char **argv){
+int SQLITE_CDECL sqlite3_shell_main(int argc, char **argv){
#else
int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
char **argv;
@@ -26377,6 +26379,7 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
char *zHome;
char *zHistory;
int nHistory;
+ print_FTL_version();
printf(
"SQLite version %s %.19s\n" /*extra-version-info*/
"Enter \".help\" for usage hints.\n",
22 changes: 22 additions & 0 deletions patch/sqlite3/0002-make-sqlite3ErrName-public.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/src/database/sqlite3.c b/src/database/sqlite3.c
index 2763b1b4..55f88efb 100644
--- a/src/database/sqlite3.c
+++ b/src/database/sqlite3.c
@@ -173885,8 +173885,7 @@ SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
** Return a static string containing the name corresponding to the error code
** specified in the argument.
*/
-#if defined(SQLITE_NEED_ERR_NAME)
-SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
+SQLITE_API const char *sqlite3ErrName(int rc){
const char *zName = 0;
int i, origRc = rc;
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
@@ -173991,7 +173990,6 @@ SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
}
return zName;
}
-#endif

/*
** Return a static string that describes the kind of error specified in the
4 changes: 2 additions & 2 deletions src/database/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ int dbquery(sqlite3* db, const char *format, ...)

int rc = sqlite3_exec(db, query, NULL, NULL, NULL);
if( rc != SQLITE_OK ){
logg("ERROR: SQL query \"%s\" failed: %s",
query, sqlite3_errstr(rc));
logg("ERROR: SQL query \"%s\" failed: %s (%s)",
query, sqlite3_errstr(rc), sqlite3ErrName(sqlite3_extended_errcode(db)));
sqlite3_free(query);
checkFTLDBrc(rc);
return rc;
Expand Down
3 changes: 3 additions & 0 deletions src/database/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ bool FTLDBerror(void) __attribute__ ((pure));
// Check SQLite3 non-success return codes for possible database corruption
bool checkFTLDBrc(const int rc);

// Get human-readable *extended* error codes (defined in sqlite3.c)
extern const char *sqlite3ErrName(int rc);

// Database macros
#define SQL_bool(db, ...) {\
int ret;\
Expand Down
2 changes: 1 addition & 1 deletion src/database/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -26580,4 +26580,4 @@ void fiddle_exec(const char * zSql){
shellState.wasm.zInput = shellState.wasm.zPos = 0;
}
}
#endif /* SQLITE_SHELL_FIDDLE */
#endif /* SQLITE_SHELL_FIDDLE */
6 changes: 2 additions & 4 deletions src/database/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -173885,8 +173885,7 @@ SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
** Return a static string containing the name corresponding to the error code
** specified in the argument.
*/
#if defined(SQLITE_NEED_ERR_NAME)
SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
SQLITE_API const char *sqlite3ErrName(int rc){
const char *zName = 0;
int i, origRc = rc;
for(i=0; i<2 && zName==0; i++, rc &= 0xff){
Expand Down Expand Up @@ -173991,7 +173990,6 @@ SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
}
return zName;
}
#endif

/*
** Return a static string that describes the kind of error specified in the
Expand Down Expand Up @@ -243517,4 +243515,4 @@ SQLITE_API int sqlite3_stmt_init(
/************** End of stmt.c ************************************************/
/* Return the source-id for this library */
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
/************************** End of sqlite3.c ******************************/
/************************** End of sqlite3.c ******************************/
2 changes: 1 addition & 1 deletion src/database/sqlite3.h
Original file line number Diff line number Diff line change
Expand Up @@ -12884,4 +12884,4 @@ struct fts5_api {

#endif /* _FTS5_H */

/******** End of fts5.h *********/
/******** End of fts5.h *********/