db: Add method to count changed rows of a db_stmt

I was hoping to get rid of these by using "ON CONFLICT" upserts, however
sqlite3 only started supporting them in version 3.24.0 which is newer than
some of our deployment targets.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker
2019-08-03 18:13:31 +02:00
committed by Rusty Russell
parent d0027b1036
commit a2b5b1561e
4 changed files with 16 additions and 0 deletions

View File

@@ -167,6 +167,12 @@ static void db_sqlite3_stmt_free(struct db_stmt *stmt)
stmt->inner_stmt = NULL;
}
static size_t db_sqlite3_count_changes(struct db_stmt *stmt)
{
sqlite3 *s = stmt->db->conn;
return sqlite3_changes(s);
}
struct db_config db_sqlite3_config = {
.name = "sqlite3",
.queries = db_sqlite3_queries,
@@ -185,6 +191,8 @@ struct db_config db_sqlite3_config = {
.column_bytes_fn = &db_sqlite3_column_bytes,
.column_blob_fn = &db_sqlite3_column_blob,
.column_text_fn = &db_sqlite3_column_text,
.count_changes_fn = &db_sqlite3_count_changes,
};
AUTODATA(db_backends, &db_sqlite3_config);