simplified error message generation

This commit is contained in:
2025-12-15 14:10:51 +05:00
parent 52a19d8db8
commit 3a528c00c2
4 changed files with 20 additions and 174 deletions

View File

@@ -8,12 +8,16 @@ void tsqlite_deinit();
ErrorCodePage_declare(SQLITE);
#define RESULT_ERROR_SQLITE_CODE(CONN, SHORT_CODE) RESULT_ERROR_CODE(SQLITE, SHORT_CODE, tsqlite_error_toStr(CONN, SHORT_CODE), true)
/// @param code SQLITE_* result code
/// @return heap-allocated string
str tsqlite_error_toStr(i32 code, cstr msg);
#define RESULT_ERROR_SQLITE_CODE(CODE, MSG) RESULT_ERROR_CODE(SQLITE, CODE, tsqlite_error_toStr(CODE, MSG), true)
#define _try_sqlite3(CONN, CALL, N) do {\
i32 _rname(N) = CALL;\
if((_rname(N) & 0xff) != SQLITE_OK){\
return RESULT_ERROR_SQLITE_CODE(CONN, _rname(N));\
return RESULT_ERROR_SQLITE_CODE(_rname(N), sqlite3_errmsg(CONN));\
}\
} while(0)
@@ -29,12 +33,6 @@ Result(tsqlite_connection*) tsqlite_connection_open(cstr file_path);
/// all statements and blobs must be destroyed before calling this
Result(void) tsqlite_connection_close(tsqlite_connection* db);
/// @param conn a database connection with error code and error message
/// @return heap-allocated string
str tsqlite_error_toStr(tsqlite_connection* conn, i32 short_code);
void tsqlite_resultCode_append(StringBuilder* sb, i32 short_code, i32 extended_code);
void tsqlite_resultCodeAndMsg_append(StringBuilder* sb, i32 short_code, i32 extended_code, str msg);
typedef struct tsqlite_statement {
tsqlite_connection* conn;