Line data Source code
1 : #include "precizer.h"
2 :
3 : __attribute__((format(printf,4,5))) // Without this we will get warning
4 6 : void log_sqlite_error(
5 : sqlite3 *db,
6 : int rc,
7 : char *err_msg,
8 : const char *fmt,
9 : ...)
10 : {
11 : char context[MAX_CHARACTERS];
12 :
13 6 : if(fmt != NULL)
14 : {
15 : va_list ap;
16 6 : va_start(ap,fmt);
17 6 : vsnprintf(context,sizeof(context),fmt,ap);
18 6 : va_end(ap);
19 6 : context[sizeof(context) - 1] = '\0';
20 :
21 : } else {
22 0 : snprintf(context,sizeof(context),"SQLite error");
23 : }
24 :
25 6 : const char *sqlite_msg = NULL;
26 :
27 6 : if(db != NULL)
28 : {
29 6 : sqlite_msg = sqlite3_errmsg(db);
30 : }
31 :
32 6 : if(sqlite_msg == NULL)
33 : {
34 0 : sqlite_msg = sqlite3_errstr(rc);
35 : }
36 :
37 6 : if(err_msg != NULL && err_msg[0] != '\0')
38 : {
39 0 : slog(ERROR,"%s (%d): %s; detail: %s\n",
40 : context,
41 : rc,
42 : sqlite_msg ? sqlite_msg : "unknown",
43 : err_msg);
44 0 : sqlite3_free(err_msg);
45 :
46 : } else {
47 6 : slog(ERROR,"%s (%d): %s\n",
48 : context,
49 : rc,
50 : sqlite_msg ? sqlite_msg : "unknown");
51 : }
52 6 : }
|