Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
sql_debug.h File Reference

Checked wrappers around the sqlite3_* calls: trace the statement, assert the return code, report the connection's error message when it is not SQLITE_OK. More...

#include "common/logging.h"
#include "database/database.h"
#include <sqlite3.h>
#include <stdio.h>
+ Include dependency graph for sql_debug.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define __DT_DEBUG_SQL_QUERY__(value)
 
#define __DT_DEBUG_ASSERT__(xin)
 
#define __DT_DEBUG_ASSERT_WITH_QUERY__(xin, query)
 
#define DT_DEBUG_SQLITE3_EXEC(a, b, c, d, e)
 
#define DT_DEBUG_SQLITE3_PREPARE_V2(a, b, c, d, e)
 
#define DT_DEBUG_SQLITE3_BIND_INT(a, b, c)   __DT_DEBUG_ASSERT__(sqlite3_bind_int(a, b, c))
 
#define DT_DEBUG_SQLITE3_BIND_INT64(a, b, c)   __DT_DEBUG_ASSERT__(sqlite3_bind_int64(a, b, c))
 
#define DT_DEBUG_SQLITE3_BIND_DOUBLE(a, b, c)   __DT_DEBUG_ASSERT__(sqlite3_bind_double(a, b, c))
 
#define DT_DEBUG_SQLITE3_BIND_TEXT(a, b, c, d, e)   __DT_DEBUG_ASSERT__(sqlite3_bind_text(a, b, c, d, e))
 
#define DT_DEBUG_SQLITE3_BIND_BLOB(a, b, c, d, e)   __DT_DEBUG_ASSERT__(sqlite3_bind_blob(a, b, c, d, e))
 
#define DT_DEBUG_SQLITE3_CLEAR_BINDINGS(a)   __DT_DEBUG_ASSERT__(sqlite3_clear_bindings(a))
 
#define DT_DEBUG_SQLITE3_RESET(a)   __DT_DEBUG_ASSERT__(sqlite3_reset(a))
 

Detailed Description

Checked wrappers around the sqlite3_* calls: trace the statement, assert the return code, report the connection's error message when it is not SQLITE_OK.

Warning
This header is scaffolding, and it is counted. It exists because SQL is still written outside src/database – every file that issues a query includes it, and every one of those is a translation unit holding a raw sqlite3 * that the module cannot account for. tools/check_module_boundaries.sh ratchets the number of such files downwards; the header is deleted when the count reaches zero and the macros become private to the repositories.

So: do not include this from new code. A new query belongs in a repository under src/database/, reached through a named function. See src/database/README.md.

Note
It used to live in common/debug.h, which meant that a file wanting nothing but DT_DEBUG_TRACE_WRAPPER – a generic tracing helper with no relation to SQL – pulled in database.h and <sqlite3.h> as well. That was 42 translation units, of which 5 never issued a query. common/debug.h now carries only the tracing wrapper.

Definition in file sql_debug.h.

Macro Definition Documentation

◆ __DT_DEBUG_ASSERT__

#define __DT_DEBUG_ASSERT__ (   xin)
Value:
{ \
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wshadow\"") const int x = xin; \
if(x != SQLITE_OK) \
{ \
fprintf(stderr, "sqlite3 error: %s:%d, function %s(): %s\n", __FILE__, __LINE__, __FUNCTION__, \
} \
_Pragma("GCC diagnostic pop") \
}
static const float x
if(L< 0.5f) C
sqlite3 * dt_database_get_sqlite3_global(void)
Definition database.c:3753

Definition at line 106 of file sql_debug.h.

◆ __DT_DEBUG_ASSERT_WITH_QUERY__

#define __DT_DEBUG_ASSERT_WITH_QUERY__ (   xin,
  query 
)
Value:
{ \
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wshadow\"") const int x = xin; \
if(x != SQLITE_OK) \
{ \
fprintf(stderr, "sqlite3 error: %s:%d, function %s(), query \"%s\": %s\n", __FILE__, __LINE__, __FUNCTION__,\
} \
_Pragma("GCC diagnostic pop") \
}

Definition at line 116 of file sql_debug.h.

◆ __DT_DEBUG_SQL_QUERY__

#define __DT_DEBUG_SQL_QUERY__ (   value)

Definition at line 77 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_BIND_BLOB

#define DT_DEBUG_SQLITE3_BIND_BLOB (   a,
  b,
  c,
  d,
 
)    __DT_DEBUG_ASSERT__(sqlite3_bind_blob(a, b, c, d, e))

Definition at line 149 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_BIND_DOUBLE

#define DT_DEBUG_SQLITE3_BIND_DOUBLE (   a,
  b,
 
)    __DT_DEBUG_ASSERT__(sqlite3_bind_double(a, b, c))

Definition at line 147 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_BIND_INT

#define DT_DEBUG_SQLITE3_BIND_INT (   a,
  b,
 
)    __DT_DEBUG_ASSERT__(sqlite3_bind_int(a, b, c))

Definition at line 145 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_BIND_INT64

#define DT_DEBUG_SQLITE3_BIND_INT64 (   a,
  b,
 
)    __DT_DEBUG_ASSERT__(sqlite3_bind_int64(a, b, c))

Definition at line 146 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_BIND_TEXT

#define DT_DEBUG_SQLITE3_BIND_TEXT (   a,
  b,
  c,
  d,
 
)    __DT_DEBUG_ASSERT__(sqlite3_bind_text(a, b, c, d, e))

Definition at line 148 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_CLEAR_BINDINGS

#define DT_DEBUG_SQLITE3_CLEAR_BINDINGS (   a)    __DT_DEBUG_ASSERT__(sqlite3_clear_bindings(a))

Definition at line 150 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_EXEC

#define DT_DEBUG_SQLITE3_EXEC (   a,
  b,
  c,
  d,
 
)
Value:
do \
{ \
dt_print(DT_DEBUG_SQL, "[sql] %s:%d, function %s(): exec \"%s\"\n", __FILE__, __LINE__, __FUNCTION__, (b)); \
} while(0)
@ DT_DEBUG_SQL
Definition logging.h:44

Definition at line 129 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_PREPARE_V2

#define DT_DEBUG_SQLITE3_PREPARE_V2 (   a,
  b,
  c,
  d,
 
)
Value:
do \
{ \
dt_print(DT_DEBUG_SQL, "[sql] %s:%d, function %s(): prepare \"%s\"\n", __FILE__, __LINE__, __FUNCTION__, (b));\
} while(0)

Definition at line 137 of file sql_debug.h.

◆ DT_DEBUG_SQLITE3_RESET

#define DT_DEBUG_SQLITE3_RESET (   a)    __DT_DEBUG_ASSERT__(sqlite3_reset(a))

Definition at line 151 of file sql_debug.h.