mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-19 23:24:27 +01:00
wallet: Add read-only flag to extracted queries
This gets rid of the two parallel execution paths of read-only and write queries, by explicitly stating with each query whether it is a read-only query, we only need to remember the ones marked as write queries. Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
committed by
Rusty Russell
parent
455aa48da0
commit
70e8da4fbd
@@ -28,7 +28,8 @@ struct db_query db_${f}_queries[] = {
|
|||||||
{
|
{
|
||||||
.name = "${elem['name']}",
|
.name = "${elem['name']}",
|
||||||
.query = "${elem['query']}",
|
.query = "${elem['query']}",
|
||||||
.placeholders = ${elem['placeholders']}
|
.placeholders = ${elem['placeholders']},
|
||||||
|
.readonly = ${elem['readonly']},
|
||||||
},
|
},
|
||||||
% endfor
|
% endfor
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <ccan/autodata/autodata.h>
|
#include <ccan/autodata/autodata.h>
|
||||||
#include <ccan/short_types/short_types.h>
|
#include <ccan/short_types/short_types.h>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
/* For testing, we want to catch fatal messages. */
|
/* For testing, we want to catch fatal messages. */
|
||||||
#ifndef db_fatal
|
#ifndef db_fatal
|
||||||
@@ -33,13 +34,11 @@ struct db_query {
|
|||||||
|
|
||||||
/* How many placeholders are in the query (and how many will we have
|
/* How many placeholders are in the query (and how many will we have
|
||||||
to allocate when instantiating this query)? */
|
to allocate when instantiating this query)? */
|
||||||
size_t placeholders;
|
size_t placeholders;
|
||||||
};
|
|
||||||
|
|
||||||
struct db_config {
|
/* Is this a read-only query? If it is there's no need to tell plugins
|
||||||
const char *name;
|
* about it. */
|
||||||
struct db_query *queries;
|
bool readonly;
|
||||||
size_t num_queries;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum db_binding_type {
|
enum db_binding_type {
|
||||||
@@ -63,6 +62,9 @@ struct db_binding {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct db_stmt {
|
struct db_stmt {
|
||||||
|
/* Database we are querying */
|
||||||
|
struct db *db;
|
||||||
|
|
||||||
/* Which SQL statement are we trying to execute? */
|
/* Which SQL statement are we trying to execute? */
|
||||||
struct db_query *query;
|
struct db_query *query;
|
||||||
|
|
||||||
@@ -71,6 +73,42 @@ struct db_stmt {
|
|||||||
|
|
||||||
/* Where are we calling this statement from? */
|
/* Where are we calling this statement from? */
|
||||||
const char *location;
|
const char *location;
|
||||||
|
|
||||||
|
const char *error;
|
||||||
|
|
||||||
|
/* Pointer to DB-specific statement. */
|
||||||
|
void *inner_stmt;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct db_config {
|
||||||
|
const char *name;
|
||||||
|
struct db_query *queries;
|
||||||
|
size_t num_queries;
|
||||||
|
|
||||||
|
/* Function used to get a string representation of the executed query
|
||||||
|
* for the `db_write` plugin hook. */
|
||||||
|
const char *(*expand_fn)(struct db_stmt *stmt);
|
||||||
|
|
||||||
|
/* Function used to execute a statement that doesn't result in a
|
||||||
|
* response. */
|
||||||
|
bool (*exec_fn)(struct db_stmt *stmt);
|
||||||
|
|
||||||
|
/* Function to execute a query that will result in a response. */
|
||||||
|
bool (*query_fn)(struct db_stmt *stmt);
|
||||||
|
|
||||||
|
/* Function used to step forwards through query results. Returns
|
||||||
|
* `false` if there are no more rows to return. */
|
||||||
|
bool (*step_fn)(struct db_stmt *stmt);
|
||||||
|
|
||||||
|
bool (*begin_tx_fn)(struct db *db);
|
||||||
|
bool (*commit_tx_fn)(struct db *db);
|
||||||
|
|
||||||
|
/* The free function must make sure that any associated state stored
|
||||||
|
* in `stmt->inner_stmt` is freed correctly, setting the pointer to
|
||||||
|
* NULL after cleaning up. It will ultmately be called by the
|
||||||
|
* destructor of `struct db_stmt`, before clearing the db_stmt
|
||||||
|
* itself. */
|
||||||
|
void (*stmt_free_fn)(struct db_stmt *db_stmt);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Provide a way for DB backends to register themselves */
|
/* Provide a way for DB backends to register themselves */
|
||||||
|
|||||||
Reference in New Issue
Block a user