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

LIB: Add functions to accept string views in other lektor parts

parent 7a01d701
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!177Add the query to the `update` command to filter karas to update
......@@ -8,6 +8,7 @@ extern "C" {
#include <lektor/common.h>
#include <lektor/mkv.h>
#include <lektor/uri.h>
#include <lektor/lib/strv.h>
#include <sqlite3.h>
#include <mpv/client.h>
......@@ -181,6 +182,7 @@ bool database_queue_skip_current(lkt_db *db, char filepath[PATH_MAX]);
/* Set a value in the config table */
bool database_validate_conf (lkt_db *db);
bool database_config_set (lkt_db *db, const char *section, const char *key, const char *value);
bool database_config_set_strv_1_2 (lkt_db *db, const char *section, const struct strv, const struct strv);
bool database_config_get_text (lkt_db *db, const char *section, const char *key, char *value, size_t len);
bool database_config_get_text_nospace (lkt_db *db, const char *section, const char *key, char *value, size_t len);
bool database_config_get_int (lkt_db *db, const char *section, const char *key, int *value);
......
......@@ -35,6 +35,15 @@ bool database_unprotected_attach(lkt_db *, const char *, const char *);
} \
}
#define SQLITE_BIND_STRV(db, stmt, pos, strv, error) \
{ \
if (sqlite3_bind_text(stmt, pos, (strv).data, (strv).count, 0) != SQLITE_OK) { \
___LOCAL_DEBUG("Failed to bind text " STRV_FMT " at pos %d: %s", STRV_ARG(strv), 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) { \
......
#include <lektor/common.h>
#include <lektor/database.h>
#include <lektor/lib/strv.h>
#include <lektor/internal/dbmacro.h>
bool
database_config_set_strv_1_2(lkt_db *db, const char *section, const struct strv key,
const struct strv value)
{
static const char *SQL_STMT = "INSERT OR REPLACE INTO"
" config (section, key, value)"
" VALUES (?, ?, ?);\n";
sqlite3_stmt *stmt = 0;
bool ret = false;
int code;
SQLITE_PREPARE(db, stmt, SQL_STMT, error);
SQLITE_BIND_TEXT(db, stmt, 1, section, error);
SQLITE_BIND_STRV(db, stmt, 2, key, error);
SQLITE_BIND_STRV(db, stmt, 3, value, error);
code = sqlite3_step(stmt);
if (code != SQLITE_OK && code != SQLITE_DONE) {
LOG_ERROR("DB", "Failed to insert or replace: %s", sqlite3_errmsg((sqlite3 *)db));
goto error;
}
LOG_DEBUG("CONFIG", "Set [%s/"STRV_FMT"] to "STRV_FMT, section, STRV_ARG(key),
STRV_ARG(value));
ret = true;
error:
sqlite3_finalize(stmt);
return ret;
}
bool
database_config_set(lkt_db *db, const char *section, const char *key, const char *value)
{
......
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