Skip to content

Commit 74b9f1a

Browse files
committed
Minor improvements to the ai_logger function
1 parent fa744eb commit 74b9f1a

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/sqlite-ai.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ SQLITE_EXTENSION_INIT1
4646
#define MIN_ALLOC_MESSAGES 256
4747
#define MAX_LORAS 64 // max 2 or 3 LoRa adapters are used (usually just one)
4848

49-
#define LOG_TABLE_DECLARATION "CREATE TEMP TABLE ai_log (id INTEGER PRIMARY KEY, stamp DATETIME DEFAULT CURRENT_TIMESTAMP, type TEXT, message TEXT);"
49+
#define LOG_TABLE_DECLARATION "CREATE TEMP TABLE IF NOT EXISTS ai_log (id INTEGER PRIMARY KEY, stamp DATETIME DEFAULT CURRENT_TIMESTAMP, type TEXT, message TEXT);"
5050
#define LOG_TABLE_INSERT_STMT "INSERT INTO ai_log (type, message) VALUES (?, ?);"
5151

5252
// CONTEXT OPTIONS
@@ -747,7 +747,7 @@ void ai_logger (enum ggml_log_level level, const char *text, void *user_data) {
747747
// printf("%s %s\n", type, text);
748748

749749
const char *values[] = {type, text};
750-
int types[] = {SQLITE_TEXT, SQLITE_TEXT};
750+
int types[] = {(type == NULL) ? SQLITE_NULL : SQLITE_TEXT, SQLITE_TEXT};
751751
int lens[] = {-1, -1};
752752
sqlite_db_write(NULL, ai->db, LOG_TABLE_INSERT_STMT, values, types, lens, 2);
753753
}

src/sqlite-ai.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
extern "C" {
2525
#endif
2626

27-
#define SQLITE_AI_VERSION "0.7.2"
27+
#define SQLITE_AI_VERSION "0.7.3"
2828

2929
SQLITE_AI_API int sqlite3_ai_init (sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi);
3030

src/utils.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,19 @@ bool sqlite_sanity_function (sqlite3_context *context, const char *func_name, in
289289
}
290290

291291
int sqlite_db_write (sqlite3_context *context, sqlite3 *db, const char *sql, const char **values, int types[], int lens[], int count) {
292-
sqlite3_stmt *pstmt = NULL;
293-
294292
// compile sql
293+
sqlite3_stmt *pstmt = NULL;
295294
int rc = sqlite3_prepare_v2(db, sql, -1, &pstmt, NULL);
296295
if (rc != SQLITE_OK) goto cleanup;
297296

297+
// ensure parameter count matches
298+
int nparams = sqlite3_bind_parameter_count(pstmt);
299+
if (nparams != count) {rc = SQLITE_MISMATCH; goto cleanup;}
300+
298301
// check bindings
299302
for (int i=0; i<count; ++i) {
300-
// sanity check input
301-
if ((types[i] != SQLITE_NULL) && (values[i] == NULL)) {
303+
// treat NULL value as NULL binding
304+
if (values[i] == NULL) {
302305
rc = sqlite3_bind_null(pstmt, i+1);
303306
continue;
304307
}

0 commit comments

Comments
 (0)