Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : __attribute__((format(printf,4,5))) // Without this we will get warning
4 : 8 : 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 [ + - ]: 8 : if(fmt != NULL)
14 : : {
15 : : va_list ap;
16 : 8 : va_start(ap,fmt);
17 : 8 : vsnprintf(context,sizeof(context),fmt,ap);
18 : 8 : va_end(ap);
19 : 8 : context[sizeof(context) - 1] = '\0';
20 : :
21 : : } else {
22 : 0 : snprintf(context,sizeof(context),"SQLite error");
23 : : }
24 : :
25 : 8 : const char *sqlite_msg = NULL;
26 : :
27 [ + - ]: 8 : if(db != NULL)
28 : : {
29 : 8 : sqlite_msg = sqlite3_errmsg(db);
30 : : }
31 : :
32 [ - + ]: 8 : if(sqlite_msg == NULL)
33 : : {
34 : 0 : sqlite_msg = sqlite3_errstr(rc);
35 : : }
36 : :
37 [ - + - - ]: 8 : 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 [ + - ]: 8 : slog(ERROR,"%s (%d): %s\n",
48 : : context,
49 : : rc,
50 : : sqlite_msg ? sqlite_msg : "unknown");
51 : : }
52 : 8 : }
|