sticker/Database: move code to BindFind()
This commit is contained in:
parent
204a1de3fd
commit
71ece56470
@ -80,6 +80,19 @@ BindAll(Error &error, sqlite3_stmt *stmt, Args&&... args)
|
|||||||
return BindAll2(error, stmt, 1, std::forward<Args>(args)...);
|
return BindAll2(error, stmt, 1, std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper for BindAll() that returns the specified sqlite3_stmt* on
|
||||||
|
* success and nullptr on error.
|
||||||
|
*/
|
||||||
|
template<typename... Args>
|
||||||
|
static sqlite3_stmt *
|
||||||
|
BindAllOrNull(Error &error, sqlite3_stmt *stmt, Args&&... args)
|
||||||
|
{
|
||||||
|
return BindAll(error, stmt, std::forward<Args>(args)...)
|
||||||
|
? stmt
|
||||||
|
: nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call sqlite3_stmt() repepatedly until something other than
|
* Call sqlite3_stmt() repepatedly until something other than
|
||||||
* SQLITE_BUSY is returned.
|
* SQLITE_BUSY is returned.
|
||||||
|
@ -368,6 +368,20 @@ sticker_load(const char *type, const char *uri, Error &error)
|
|||||||
return new sticker(std::move(s));
|
return new sticker(std::move(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static sqlite3_stmt *
|
||||||
|
BindFind(const char *type, const char *base_uri, const char *name,
|
||||||
|
Error &error)
|
||||||
|
{
|
||||||
|
assert(type != nullptr);
|
||||||
|
assert(name != nullptr);
|
||||||
|
|
||||||
|
if (base_uri == nullptr)
|
||||||
|
base_uri = "";
|
||||||
|
|
||||||
|
return BindAllOrNull(error, sticker_stmt[STICKER_SQL_FIND],
|
||||||
|
type, base_uri, name);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
sticker_find(const char *type, const char *base_uri, const char *name,
|
sticker_find(const char *type, const char *base_uri, const char *name,
|
||||||
void (*func)(const char *uri, const char *value,
|
void (*func)(const char *uri, const char *value,
|
||||||
@ -375,17 +389,11 @@ sticker_find(const char *type, const char *base_uri, const char *name,
|
|||||||
void *user_data,
|
void *user_data,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
sqlite3_stmt *const stmt = sticker_stmt[STICKER_SQL_FIND];
|
|
||||||
|
|
||||||
assert(type != nullptr);
|
|
||||||
assert(name != nullptr);
|
|
||||||
assert(func != nullptr);
|
assert(func != nullptr);
|
||||||
assert(sticker_enabled());
|
assert(sticker_enabled());
|
||||||
|
|
||||||
if (base_uri == nullptr)
|
sqlite3_stmt *const stmt = BindFind(type, base_uri, name, error);
|
||||||
base_uri = "";
|
if (stmt == nullptr)
|
||||||
|
|
||||||
if (!BindAll(error, stmt, type, base_uri, name))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const bool success = ExecuteForEach(stmt, error,
|
const bool success = ExecuteForEach(stmt, error,
|
||||||
|
Loading…
Reference in New Issue
Block a user