Skip to content

Commit

Permalink
Print extended error code if anything in dbquery() fails. This will b…
Browse files Browse the repository at this point in the history
…e helpful in a lot of cases where we'd only be logging 'disk I/O error' but a more specififc error is available

Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Nov 16, 2022
1 parent 7af658b commit d2adf1c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
# SQLITE_ENABLE_DBPAGE_VTAB: Enables the SQLITE_DBPAGE virtual table. Warning: writing to the SQLITE_DBPAGE virtual table can very easily cause unrecoverably database corruption.
# SQLITE_OMIT_DESERIALIZE: This option causes the the sqlite3_serialize() and sqlite3_deserialize() interfaces to be omitted from the build (was the default before 3.36.0)
# HAVE_READLINE: Enable readline support to allow easy editing, history and auto-completion
set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_DQS=0 -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_OMIT_DESERIALIZE -DHAVE_READLINE")
# SQLITE_NEED_ERR_NAME: Enable a debugging feature in SQLite3 that allows translating extended error code into human-readable strings
set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_DQS=0 -DSQLITE_ENABLE_DBPAGE_VTAB -DSQLITE_OMIT_DESERIALIZE -DHAVE_READLINE -DSQLITE_NEED_ERR_NAME")

# Code hardening and debugging improvements
# -fstack-protector-strong: The program will be resistant to having its stack overflowed
Expand Down
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
4 changes: 4 additions & 0 deletions src/database/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@

#include "sqlite3.h"

// Return a static string containing the name corresponding to the error code
// specified in the argument. Defined in sqlite3.c
extern const char *sqlite3ErrName(int rc);

// Database table "ftl"
enum ftl_table_props {
DB_VERSION,
Expand Down
6 changes: 3 additions & 3 deletions src/database/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -13717,7 +13717,7 @@ struct fts5_api {
(defined(SQLITE_DEBUG) && SQLITE_OS_WIN)
# define SQLITE_NEED_ERR_NAME
#else
# undef SQLITE_NEED_ERR_NAME
//# undef SQLITE_NEED_ERR_NAME
#endif

/*
Expand Down Expand Up @@ -20254,7 +20254,7 @@ SQLITE_PRIVATE u8 sqlite3HexToInt(int h);
SQLITE_PRIVATE int sqlite3TwoPartName(Parse *, Token *, Token *, Token **);

#if defined(SQLITE_NEED_ERR_NAME)
SQLITE_PRIVATE const char *sqlite3ErrName(int);
const char *sqlite3ErrName(int);
#endif

#ifndef SQLITE_OMIT_DESERIALIZE
Expand Down Expand Up @@ -172072,7 +172072,7 @@ SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3 *db, int tripCode){
** specified in the argument.
*/
#if defined(SQLITE_NEED_ERR_NAME)
SQLITE_PRIVATE const char *sqlite3ErrName(int rc){
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

0 comments on commit d2adf1c

Please sign in to comment.