sticker/Database: move sticker_prepare() to lib/sqlite/Util.hxx
This commit is contained in:
parent
34d483a34a
commit
c88d5616f7
@ -28,6 +28,18 @@
|
|||||||
|
|
||||||
namespace Sqlite {
|
namespace Sqlite {
|
||||||
|
|
||||||
|
static inline sqlite3_stmt *
|
||||||
|
Prepare(sqlite3 *db, const char *sql)
|
||||||
|
{
|
||||||
|
sqlite3_stmt *stmt;
|
||||||
|
int ret = sqlite3_prepare_v2(db, sql, -1, &stmt, nullptr);
|
||||||
|
if (ret != SQLITE_OK)
|
||||||
|
throw SqliteError(db, ret,
|
||||||
|
"sqlite3_prepare_v2() failed");
|
||||||
|
|
||||||
|
return stmt;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws #SqliteError on error.
|
* Throws #SqliteError on error.
|
||||||
*/
|
*/
|
||||||
|
@ -83,18 +83,6 @@ static const char sticker_sql_create[] =
|
|||||||
static sqlite3 *sticker_db;
|
static sqlite3 *sticker_db;
|
||||||
static sqlite3_stmt *sticker_stmt[ARRAY_SIZE(sticker_sql)];
|
static sqlite3_stmt *sticker_stmt[ARRAY_SIZE(sticker_sql)];
|
||||||
|
|
||||||
static sqlite3_stmt *
|
|
||||||
sticker_prepare(const char *sql)
|
|
||||||
{
|
|
||||||
sqlite3_stmt *stmt;
|
|
||||||
int ret = sqlite3_prepare_v2(sticker_db, sql, -1, &stmt, nullptr);
|
|
||||||
if (ret != SQLITE_OK)
|
|
||||||
throw SqliteError(sticker_db, ret,
|
|
||||||
"sqlite3_prepare_v2() failed");
|
|
||||||
|
|
||||||
return stmt;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
sticker_global_init(Path path)
|
sticker_global_init(Path path)
|
||||||
{
|
{
|
||||||
@ -125,7 +113,7 @@ sticker_global_init(Path path)
|
|||||||
for (unsigned i = 0; i < ARRAY_SIZE(sticker_sql); ++i) {
|
for (unsigned i = 0; i < ARRAY_SIZE(sticker_sql); ++i) {
|
||||||
assert(sticker_sql[i] != nullptr);
|
assert(sticker_sql[i] != nullptr);
|
||||||
|
|
||||||
sticker_stmt[i] = sticker_prepare(sticker_sql[i]);
|
sticker_stmt[i] = Prepare(sticker_db, sticker_sql[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user