sticker/Database: move sticker_prepare() to lib/sqlite/Util.hxx

This commit is contained in:
Max Kellermann 2019-04-25 11:57:29 +02:00
parent 34d483a34a
commit c88d5616f7
2 changed files with 13 additions and 13 deletions

View File

@ -28,6 +28,18 @@
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.
*/

View File

@ -83,18 +83,6 @@ static const char sticker_sql_create[] =
static sqlite3 *sticker_db;
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
sticker_global_init(Path path)
{
@ -125,7 +113,7 @@ sticker_global_init(Path path)
for (unsigned i = 0; i < ARRAY_SIZE(sticker_sql); ++i) {
assert(sticker_sql[i] != nullptr);
sticker_stmt[i] = sticker_prepare(sticker_sql[i]);
sticker_stmt[i] = Prepare(sticker_db, sticker_sql[i]);
}
}