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

Do things in a better way to init the database

parent 13dba81b
Branches
Étiquettes
1 requête de fusion!80Arch pkg
Ce commit fait partie de la requête de fusion !80. Les commentaires créés ici seront créés dans le contexte de cette requête de fusion.
...@@ -85,7 +85,11 @@ mthread_deps = [ declare_dependency( link_with: static_library( 'mthread' ...@@ -85,7 +85,11 @@ mthread_deps = [ declare_dependency( link_with: static_library( 'mthread'
generated_deps = [ declare_dependency( link_with: static_library( 'generated' generated_deps = [ declare_dependency( link_with: static_library( 'generated'
, [ custom_target( 'sqlinit' , [ custom_target( 'sqlinit'
, output: 'sqlinit.c' , output: 'sqlinit.c'
, input: 'scripts/init.sql' , input: 'src/database/disk.sql'
, command: [ find_program('xxd'), '-i', '@INPUT@', '@OUTPUT@' ] ) ]
, [ custom_target( 'sqlmemory'
, output: 'sqlmemory.c'
, input: 'src/database/memory.sql'
, command: [ find_program('xxd'), '-i', '@INPUT@', '@OUTPUT@' ] ) ] , command: [ find_program('xxd'), '-i', '@INPUT@', '@OUTPUT@' ] ) ]
, [ custom_target( 'manpath' , [ custom_target( 'manpath'
, output: 'manpath.c' , output: 'manpath.c'
......
Fichier déplacé
-- This schema is used to initialize the in-memory database.
-- Some notes about the queue_state table
-- - There's one and only row.
-- - `paused` 0 = play, 1 = paused
-- - `random` whether the queue is played randomly
-- - `repeat` whether the queue loops
-- - `single` whether only one kara loops
-- - `current` the position in the queue of the kara being played
-- - `elapsed` the number of seconds from the beginning of the current kara
-- - `duration` the total duration of the playing kara
CREATE TABLE IF NOT EXISTS queue_state
( id INTEGER PRIMARY KEY DEFAULT 42 CHECK(id = 42)
, volume INTEGER NOT NULL DEFAULT 100 CHECK(0 <= volume AND volume <= 100)
, paused INTEGER NOT NULL DEFAULT 1
, random INTEGER NOT NULL DEFAULT 0
, repeat INTEGER NOT NULL DEFAULT 0
, single INTEGER NOT NULL DEFAULT 0
, consume INTEGER NOT NULL DEFAULT 0
, current INTEGER CHECK(current > 0)
, duration INTEGER CHECK(duration >= 0)
, elapsed INTEGER CHECK(elapsed >= 0)
);
INSERT INTO queue_state (id) VALUES (42);
-- Used to store the content of the ini configuration file.
CREATE TABLE IF NOT EXISTS config
( section TEXT NOT NULL
, key TEXT NOT NULL
, value TEXT
, PRIMARY KEY (section, key)
) WITHOUT ROWID;
...@@ -7,40 +7,8 @@ ...@@ -7,40 +7,8 @@
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
/* Some notes: extern unsigned char ___src_database_disk_sql[];
- There's one and only row. extern unsigned char ___src_database_memory_sql[];
- `paused` 0 = play, 1 = paused
- `random` whether the queue is played randomly
- `repeat` whether the queue loops
- `single` whether only one kara loops
- `current` the position in the queue of the kara being played
- `elapsed` the number of seconds from the beginning of the current kara
- `duration` the total duration of the playing kara
This schema is used to initialize the in-memory database. */
static const char *const SQL_MEM_SCHEM =
"CREATE TABLE IF NOT EXISTS queue_state"
" ( id INTEGER PRIMARY KEY DEFAULT 42 CHECK(id = 42)"
" , volume INTEGER NOT NULL DEFAULT 100 CHECK(0 <= volume AND volume <= 100)"
" , paused INTEGER NOT NULL DEFAULT 1"
" , random INTEGER NOT NULL DEFAULT 0"
" , repeat INTEGER NOT NULL DEFAULT 0"
" , single INTEGER NOT NULL DEFAULT 0"
" , consume INTEGER NOT NULL DEFAULT 0"
" , current INTEGER CHECK(current > 0)"
" , duration INTEGER CHECK(duration >= 0)"
" , elapsed INTEGER CHECK(elapsed >= 0)"
" );\n"
"INSERT INTO queue_state (id) VALUES (42);\n"
"CREATE TABLE IF NOT EXISTS config"
" ( section TEXT NOT NULL"
" , key TEXT NOT NULL"
" , value TEXT"
" , PRIMARY KEY (section, key)"
" ) WITHOUT ROWID;\n";
/* Should be, defined scripts_init_sql and its length scripts_init_sql_len */
extern unsigned char ___scripts_init_sql[];
extern int ___scripts_init_sql_len;
#define INVALID_CHARS_DBPATH ":?!'\"" #define INVALID_CHARS_DBPATH ":?!'\""
#define HEAP_LIMIT_SOFT 100 * 1024 * 1024 #define HEAP_LIMIT_SOFT 100 * 1024 * 1024
...@@ -64,7 +32,7 @@ database_new(volatile sqlite3 **db) ...@@ -64,7 +32,7 @@ database_new(volatile sqlite3 **db)
RETURN_IF(sqlite3_soft_heap_limit64(HEAP_LIMIT_SOFT) < 0, "Failed to set soft heap limit", false); RETURN_IF(sqlite3_soft_heap_limit64(HEAP_LIMIT_SOFT) < 0, "Failed to set soft heap limit", false);
RETURN_IF(sqlite3_hard_heap_limit64(HEAP_LIMIT_HARD) < 0, "Failed to set soft heap limit", false); RETURN_IF(sqlite3_hard_heap_limit64(HEAP_LIMIT_HARD) < 0, "Failed to set soft heap limit", false);
RETURN_IF(SQLITE_OK != sqlite3_open_v2(":memory:", (sqlite3 **) db, flags, NULL), "Failed to open :memory:", false); RETURN_IF(SQLITE_OK != sqlite3_open_v2(":memory:", (sqlite3 **) db, flags, NULL), "Failed to open :memory:", false);
SQLITE_EXEC(*db, SQL_MEM_SCHEM, err_not_init); SQLITE_EXEC(*db, (const char *) ___src_database_memory_sql, err_not_init);
return true; return true;
err_not_init: err_not_init:
*db = NULL; *db = NULL;
...@@ -182,7 +150,7 @@ database_init(const char *dbpath) ...@@ -182,7 +150,7 @@ database_init(const char *dbpath)
{ {
sqlite3 *db; sqlite3 *db;
GOTO_IF(SQLITE_OK != sqlite3_open(dbpath, &db), "Failed to open the database", error); GOTO_IF(SQLITE_OK != sqlite3_open(dbpath, &db), "Failed to open the database", error);
SQLITE_EXEC(db, (const char *) ___scripts_init_sql, error); SQLITE_EXEC(db, (const char *) ___src_database_disk_sql, error);
LOG_INFO_SCT("DB", "Initialized the 'disk' database successfully, path was '%s'", dbpath); LOG_INFO_SCT("DB", "Initialized the 'disk' database successfully, path was '%s'", dbpath);
return true; return true;
error: error:
......
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