20 #ifndef MPD_SQLITE_UTIL_HXX
21 #define MPD_SQLITE_UTIL_HXX
33 Bind(sqlite3_stmt *stmt,
unsigned i,
const char *value)
35 int result = sqlite3_bind_text(stmt, i, value, -1,
nullptr);
36 if (result != SQLITE_OK)
37 throw SqliteError(stmt, result,
"sqlite3_bind_text() failed");
40 template<
typename... Args>
44 assert(
int(i - 1) == sqlite3_bind_parameter_count(stmt));
47 template<
typename... Args>
50 const char *value, Args&&... args)
53 BindAll2(stmt, i + 1, std::forward<Args>(args)...);
59 template<
typename... Args>
61 BindAll(sqlite3_stmt *stmt, Args&&... args)
63 assert(
int(
sizeof...(args)) == sqlite3_bind_parameter_count(stmt));
65 BindAll2(stmt, 1, std::forward<Args>(args)...);
77 result = sqlite3_step(stmt);
78 }
while (result == SQLITE_BUSY);
92 if (result == SQLITE_ROW)
95 if (result != SQLITE_DONE)
96 throw SqliteError(stmt, result,
"sqlite3_step() failed");
111 if (result != SQLITE_DONE)
112 throw SqliteError(stmt, result,
"sqlite3_step() failed");
121 static inline unsigned
126 return sqlite3_changes(sqlite3_db_handle(stmt));
156 throw SqliteError(stmt, result,
"sqlite3_step() failed");
static unsigned ExecuteChanges(sqlite3_stmt *stmt)
Wrapper for ExecuteCommand() that returns the number of rows modified via sqlite3_changes().
static void ExecuteCommand(sqlite3_stmt *stmt)
Wrapper for ExecuteBusy() that interprets everything other than SQLITE_DONE as error.
static int ExecuteBusy(sqlite3_stmt *stmt)
Call sqlite3_stmt() repepatedly until something other than SQLITE_BUSY is returned.
static void Bind(sqlite3_stmt *stmt, unsigned i, const char *value)
Throws SqliteError on error.
static void ExecuteForEach(sqlite3_stmt *stmt, F &&f)
static bool ExecuteModified(sqlite3_stmt *stmt)
Wrapper for ExecuteChanges() that returns true if at least one row was modified.
static bool ExecuteRow(sqlite3_stmt *stmt)
Wrapper for ExecuteBusy() that returns true on SQLITE_ROW.
static void BindAll2(gcc_unused sqlite3_stmt *stmt, gcc_unused unsigned i)
static void BindAll(sqlite3_stmt *stmt, Args &&...args)
Throws SqliteError on error.