Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 83570873 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

BUILD: Move the private sqlite defines to a private header

parent 18b7f27e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!105Refactor and more
Pipeline #1879 réussi
...@@ -118,53 +118,9 @@ typedef volatile enum { ...@@ -118,53 +118,9 @@ typedef volatile enum {
#define BUFFER_OUT_MAX 16 #define BUFFER_OUT_MAX 16
#define MPD_VERSION "0.21.16" #define MPD_VERSION "0.21.16"
#define SQLITE_PREPARE(db, stmt, SQL, goto_label) \
if (sqlite3_prepare_v2((sqlite3 *) db, SQL, -1, &(stmt), 0) != SQLITE_OK) { \
LOG_ERROR("DB", "Failed to prepare statement: %s", \
sqlite3_errmsg((sqlite3 *) db)); \
goto goto_label; \
}
#define SQLITE_EXEC(db, SQL, goto_label) \
if (sqlite3_exec((sqlite3 *) db, SQL, NULL, NULL, NULL) != SQLITE_OK) { \
LOG_ERROR("DB", "Failed to exec statement: %s", \
sqlite3_errmsg((sqlite3 *) db)); \
goto goto_label; \
}
#define SQLITE_BIND_TEXT(db, stmt, pos, text, error) { \
if (sqlite3_bind_text(stmt, pos, text, -1, 0) != SQLITE_OK) { \
LOG_ERROR("DB", "Failed to bind text %s at pos %d: %s", \
(const char *) text, pos, \
sqlite3_errmsg((sqlite3 *) db)); \
goto error; \
}}
#define SQLITE_BIND_INT(db, stmt, pos, integer, error) { \
if (sqlite3_bind_int(stmt, pos, integer) != SQLITE_OK) { \
LOG_ERROR("DB", "Failed to bind int %d at pos %d: %s", \
integer, pos, sqlite3_errmsg((sqlite3 *) db)); \
goto error; \
}}
#define SQLITE_STEP(db, stmt, code, error) \
if (sqlite3_step(stmt) != code) { \
LOG_ERROR("DB", "Failed to step: %s", \
sqlite3_errmsg((sqlite3 *) db)); \
goto error; \
}
#define SQLITE_STEP_ROW(db, stmt, error) SQLITE_STEP(db, stmt, SQLITE_ROW, error)
#define SQLITE_STEP_DONE(db, stmt, error) SQLITE_STEP(db, stmt, SQLITE_DONE, error)
#define SQLITE_DO_ROLLBACK(db) \
sqlite3_exec((sqlite3 *) db, "ROLLBACK TRANSACTION;\n", NULL, NULL, NULL);
#define STR_MATCH(str1, str2) (! strcasecmp(str1, str2)) #define STR_MATCH(str1, str2) (! strcasecmp(str1, str2))
#define STR_NMATCH(str1, str2, n) (! strncasecmp(str1, str2, n)) #define STR_NMATCH(str1, str2, n) (! strncasecmp(str1, str2, n))
#define sqlite3_column_chars (const char *) sqlite3_column_text
#define GET_VA_COUNT(...) PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) #define GET_VA_COUNT(...) PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
#define PP_NARG_(...) PP_ARG_N(__VA_ARGS__) #define PP_NARG_(...) PP_ARG_N(__VA_ARGS__)
#define PP_ARG_N( _1, _2, _3, _4, _5, _6, _7, _8, _9,_10,_11,_12,_13,_14, \ #define PP_ARG_N( _1, _2, _3, _4, _5, _6, _7, _8, _9,_10,_11,_12,_13,_14, \
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <string.h> #include <string.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "macro.h"
bool bool
database_config_set(volatile sqlite3 *db, const char *section, const char *key, database_config_set(volatile sqlite3 *db, const char *section, const char *key,
const char *value) const char *value)
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <string.h> #include <string.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "macro.h"
static inline int static inline int
__check_sticker_type(const char *type) __check_sticker_type(const char *type)
{ {
......
#if ! defined(__LKT_DATABASE_MACRO_H__)
#define __LKT_DATABASE_MACRO_H__
#define SQLITE_PREPARE(db, stmt, SQL, goto_label) \
if (sqlite3_prepare_v2((sqlite3 *) db, SQL, -1, &(stmt), 0) != SQLITE_OK) { \
LOG_ERROR("DB", "Failed to prepare statement: %s", \
sqlite3_errmsg((sqlite3 *) db)); \
goto goto_label; \
}
#define SQLITE_EXEC(db, SQL, goto_label) \
if (sqlite3_exec((sqlite3 *) db, SQL, NULL, NULL, NULL) != SQLITE_OK) { \
LOG_ERROR("DB", "Failed to exec statement: %s", \
sqlite3_errmsg((sqlite3 *) db)); \
goto goto_label; \
}
#define SQLITE_BIND_TEXT(db, stmt, pos, text, error) { \
if (sqlite3_bind_text(stmt, pos, text, -1, 0) != SQLITE_OK) { \
LOG_ERROR("DB", "Failed to bind text %s at pos %d: %s", \
(const char *) text, pos, \
sqlite3_errmsg((sqlite3 *) db)); \
goto error; \
}}
#define SQLITE_BIND_INT(db, stmt, pos, integer, error) { \
if (sqlite3_bind_int(stmt, pos, integer) != SQLITE_OK) { \
LOG_ERROR("DB", "Failed to bind int %d at pos %d: %s", \
integer, pos, sqlite3_errmsg((sqlite3 *) db)); \
goto error; \
}}
#define SQLITE_STEP(db, stmt, code, error) \
if (sqlite3_step(stmt) != code) { \
LOG_ERROR("DB", "Failed to step: %s", \
sqlite3_errmsg((sqlite3 *) db)); \
goto error; \
}
#define SQLITE_STEP_ROW(db, stmt, error) SQLITE_STEP(db, stmt, SQLITE_ROW, error)
#define SQLITE_STEP_DONE(db, stmt, error) SQLITE_STEP(db, stmt, SQLITE_DONE, error)
#define SQLITE_DO_ROLLBACK(db) \
sqlite3_exec((sqlite3 *) db, "ROLLBACK TRANSACTION;\n", NULL, NULL, NULL);
#define sqlite3_column_chars (const char *) sqlite3_column_text
#endif /* __LKT_DATABASE_MACRO_H__ */
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <pthread.h> #include <pthread.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "macro.h"
extern unsigned char ___src_database_memory_sql[]; extern unsigned char ___src_database_memory_sql[];
extern unsigned char ___src_database_disk_sql[]; extern unsigned char ___src_database_disk_sql[];
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <strings.h> #include <strings.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "macro.h"
/* Find it in database/open.c */ /* Find it in database/open.c */
extern int extern int
is_sql_str_invalid(const char *str); is_sql_str_invalid(const char *str);
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <string.h> #include <string.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "macro.h"
// *INDENT-OFF* // *INDENT-OFF*
#define sqlite_just_exec(func, query) \ #define sqlite_just_exec(func, query) \
bool func (volatile sqlite3 *db) { \ bool func (volatile sqlite3 *db) { \
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <stdio.h> #include <stdio.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "macro.h"
static inline int static inline int
__check_type(const char *type) __check_type(const char *type)
{ {
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#include <time.h> #include <time.h>
#include <linux/limits.h> #include <linux/limits.h>
#include "macro.h"
static inline bool static inline bool
__add_kara_to_update_job(volatile sqlite3 *db, size_t id) __add_kara_to_update_job(volatile sqlite3 *db, size_t id)
{ {
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include <stdio.h> #include <stdio.h>
#include <sqlite3.h> #include <sqlite3.h>
#include "macro.h"
bool bool
database_user_authentificate(volatile sqlite3 *db, const char *password) database_user_authentificate(volatile sqlite3 *db, const char *password)
{ {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter