Commit 43267dc8 authored by Max Kellermann's avatar Max Kellermann

sticker/Database: make variables more local

parent 3ec6c26e
...@@ -92,10 +92,8 @@ LogError(sqlite3 *db, const char *msg) ...@@ -92,10 +92,8 @@ LogError(sqlite3 *db, const char *msg)
static sqlite3_stmt * static sqlite3_stmt *
sticker_prepare(const char *sql, Error &error) sticker_prepare(const char *sql, Error &error)
{ {
int ret;
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
int ret = sqlite3_prepare_v2(sticker_db, sql, -1, &stmt, nullptr);
ret = sqlite3_prepare_v2(sticker_db, sql, -1, &stmt, nullptr);
if (ret != SQLITE_OK) { if (ret != SQLITE_OK) {
error.Format(sticker_domain, ret, error.Format(sticker_domain, ret,
"sqlite3_prepare_v2() failed: %s", "sqlite3_prepare_v2() failed: %s",
...@@ -209,7 +207,6 @@ std::string ...@@ -209,7 +207,6 @@ std::string
sticker_load_value(const char *type, const char *uri, const char *name) sticker_load_value(const char *type, const char *uri, const char *name)
{ {
sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_GET]; sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_GET];
int ret;
assert(sticker_enabled()); assert(sticker_enabled());
assert(type != nullptr); assert(type != nullptr);
...@@ -224,6 +221,7 @@ sticker_load_value(const char *type, const char *uri, const char *name) ...@@ -224,6 +221,7 @@ sticker_load_value(const char *type, const char *uri, const char *name)
if (!BindAll(stmt, type, uri, name)) if (!BindAll(stmt, type, uri, name))
return std::string(); return std::string();
int ret;
do { do {
ret = sqlite3_step(stmt); ret = sqlite3_step(stmt);
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
...@@ -250,7 +248,6 @@ sticker_list_values(std::map<std::string, std::string> &table, ...@@ -250,7 +248,6 @@ sticker_list_values(std::map<std::string, std::string> &table,
const char *type, const char *uri) const char *type, const char *uri)
{ {
sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_LIST]; sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_LIST];
int ret;
assert(type != nullptr); assert(type != nullptr);
assert(uri != nullptr); assert(uri != nullptr);
...@@ -261,6 +258,7 @@ sticker_list_values(std::map<std::string, std::string> &table, ...@@ -261,6 +258,7 @@ sticker_list_values(std::map<std::string, std::string> &table,
if (!BindAll(stmt, type, uri)) if (!BindAll(stmt, type, uri))
return false; return false;
int ret;
do { do {
ret = sqlite3_step(stmt); ret = sqlite3_step(stmt);
switch (ret) { switch (ret) {
...@@ -294,7 +292,6 @@ sticker_update_value(const char *type, const char *uri, ...@@ -294,7 +292,6 @@ sticker_update_value(const char *type, const char *uri,
const char *name, const char *value) const char *name, const char *value)
{ {
sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_UPDATE]; sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_UPDATE];
int ret;
assert(type != nullptr); assert(type != nullptr);
assert(uri != nullptr); assert(uri != nullptr);
...@@ -309,6 +306,7 @@ sticker_update_value(const char *type, const char *uri, ...@@ -309,6 +306,7 @@ sticker_update_value(const char *type, const char *uri,
if (!BindAll(stmt, value, type, uri, name)) if (!BindAll(stmt, value, type, uri, name))
return false; return false;
int ret;
do { do {
ret = sqlite3_step(stmt); ret = sqlite3_step(stmt);
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
...@@ -332,7 +330,6 @@ sticker_insert_value(const char *type, const char *uri, ...@@ -332,7 +330,6 @@ sticker_insert_value(const char *type, const char *uri,
const char *name, const char *value) const char *name, const char *value)
{ {
sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_INSERT]; sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_INSERT];
int ret;
assert(type != nullptr); assert(type != nullptr);
assert(uri != nullptr); assert(uri != nullptr);
...@@ -347,6 +344,7 @@ sticker_insert_value(const char *type, const char *uri, ...@@ -347,6 +344,7 @@ sticker_insert_value(const char *type, const char *uri,
if (!BindAll(stmt, type, uri, name, value)) if (!BindAll(stmt, type, uri, name, value))
return false; return false;
int ret;
do { do {
ret = sqlite3_step(stmt); ret = sqlite3_step(stmt);
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
...@@ -385,7 +383,6 @@ bool ...@@ -385,7 +383,6 @@ bool
sticker_delete(const char *type, const char *uri) sticker_delete(const char *type, const char *uri)
{ {
sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_DELETE]; sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_DELETE];
int ret;
assert(sticker_enabled()); assert(sticker_enabled());
assert(type != nullptr); assert(type != nullptr);
...@@ -396,6 +393,7 @@ sticker_delete(const char *type, const char *uri) ...@@ -396,6 +393,7 @@ sticker_delete(const char *type, const char *uri)
if (!BindAll(stmt, type, uri)) if (!BindAll(stmt, type, uri))
return false; return false;
int ret;
do { do {
ret = sqlite3_step(stmt); ret = sqlite3_step(stmt);
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
...@@ -416,7 +414,6 @@ bool ...@@ -416,7 +414,6 @@ bool
sticker_delete_value(const char *type, const char *uri, const char *name) sticker_delete_value(const char *type, const char *uri, const char *name)
{ {
sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_DELETE_VALUE]; sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_DELETE_VALUE];
int ret;
assert(sticker_enabled()); assert(sticker_enabled());
assert(type != nullptr); assert(type != nullptr);
...@@ -427,6 +424,7 @@ sticker_delete_value(const char *type, const char *uri, const char *name) ...@@ -427,6 +424,7 @@ sticker_delete_value(const char *type, const char *uri, const char *name)
if (!BindAll(stmt, type, uri, name)) if (!BindAll(stmt, type, uri, name))
return false; return false;
int ret;
do { do {
ret = sqlite3_step(stmt); ret = sqlite3_step(stmt);
} while (ret == SQLITE_BUSY); } while (ret == SQLITE_BUSY);
...@@ -493,7 +491,6 @@ sticker_find(const char *type, const char *base_uri, const char *name, ...@@ -493,7 +491,6 @@ sticker_find(const char *type, const char *base_uri, const char *name,
void *user_data) void *user_data)
{ {
sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_FIND]; sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_FIND];
int ret;
assert(type != nullptr); assert(type != nullptr);
assert(name != nullptr); assert(name != nullptr);
...@@ -508,6 +505,7 @@ sticker_find(const char *type, const char *base_uri, const char *name, ...@@ -508,6 +505,7 @@ sticker_find(const char *type, const char *base_uri, const char *name,
if (!BindAll(stmt, type, base_uri, name)) if (!BindAll(stmt, type, base_uri, name))
return false; return false;
int ret;
do { do {
ret = sqlite3_step(stmt); ret = sqlite3_step(stmt);
switch (ret) { switch (ret) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment