Skip to content

Sqlite updates #8418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,6 @@ int main(void)
return 0;
}
/*END*/
var=HAVE_SQLITE3_EXPANDED_SQL
desc=sqlite3_expanded_sql
style=DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE
link=$SQLITE3_LDLIBS
code=
#include <sqlite3.h>
#include <stdio.h>

int main(void)
{
printf("%p\n", sqlite3_expanded_sql);
return 0;
}
/*END*/
var=HAVE_SQLITE3
desc=sqlite3
style=DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE
Expand Down
47 changes: 5 additions & 42 deletions db/db_sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,6 @@ static bool have_same_data_version(sqlite3 *a, sqlite3 *b)
return version_a == version_b;
}

#if !HAVE_SQLITE3_EXPANDED_SQL
/* Prior to sqlite3 v3.14, we have to use tracing to dump statements */
struct db_sqlite3_trace {
struct db_sqlite3 *wrapper;
struct db_stmt *stmt;
};

static void trace_sqlite3(void *stmtv, const char *stmt)
{
struct db_sqlite3_trace *trace = (struct db_sqlite3_trace *)stmtv;
struct db_sqlite3 *wrapper = trace->wrapper;
struct db_stmt *s = trace->stmt;
db_sqlite3_changes_add(wrapper, s, stmt);
}
#endif

static const char *db_sqlite3_fmt_error(struct db_stmt *stmt)
{
return tal_fmt(stmt, "%s: %s: %s", stmt->location, stmt->query->query,
Expand Down Expand Up @@ -269,49 +253,27 @@ static bool db_sqlite3_query(struct db_stmt *stmt)
static bool db_sqlite3_exec(struct db_stmt *stmt)
{
int err;
bool success;
char *expanded_sql;
struct db_sqlite3 *wrapper = (struct db_sqlite3 *) stmt->db->conn;

#if !HAVE_SQLITE3_EXPANDED_SQL
/* Register the tracing function if we don't have an explicit way of
* expanding the statement. */
struct db_sqlite3_trace trace;
trace.wrapper = wrapper;
trace.stmt = stmt;
sqlite3_trace(conn2sql(stmt->db->conn), trace_sqlite3, &trace);
#endif

if (!db_sqlite3_query(stmt)) {
/* If the prepare step caused an error we hand it up. */
success = false;
goto done;
return false;
}

err = sqlite3_step(stmt->inner_stmt);
if (err != SQLITE_DONE) {
tal_free(stmt->error);
stmt->error = db_sqlite3_fmt_error(stmt);
success = false;
goto done;
return false;
}

#if HAVE_SQLITE3_EXPANDED_SQL
/* Manually expand and call the callback */
char *expanded_sql;
expanded_sql = sqlite3_expanded_sql(stmt->inner_stmt);
db_sqlite3_changes_add(wrapper, stmt, expanded_sql);
sqlite3_free(expanded_sql);
#endif
success = true;

done:
#if !HAVE_SQLITE3_EXPANDED_SQL
/* Unregister the trace callback to avoid it accessing the potentially
* stale pointer to stmt */
sqlite3_trace(conn2sql(stmt->db->conn), NULL, NULL);
#endif

return success;
return true;
}

static bool db_sqlite3_step(struct db_stmt *stmt)
Expand Down Expand Up @@ -570,6 +532,7 @@ static bool complete_table_manip(struct db *db,
return true;
}

/* FIXME: sqlite3 version 3.25.0 (2018-09-15) supports ALTER TABLE RENAME */
static bool db_sqlite3_rename_column(struct db *db,
const char *tablename,
const char *from, const char *to)
Expand Down
4 changes: 2 additions & 2 deletions plugins/sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -873,8 +873,8 @@ static struct command_result *channels_refresh(struct command *cmd,

plugin_log(cmd->plugin, LOG_DBG, "Refreshing channel: %s",
fmt_short_channel_id(tmpctx, scid));
/* FIXME: sqlite 3.24.0 (2018-06-04) added UPSERT, but
* we don't require it. */
/* FIXME: sqlite3 version 3.24.0 (2018-06-04) added
* UPSERT, but we don't require it. */
delete_channel_from_db(cmd, scid);
req = jsonrpc_request_start(cmd, "listchannels",
listchannels_one_done,
Expand Down
4 changes: 4 additions & 0 deletions tools/headerversions.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ static const char template[] =
" if (SQLITE_VERSION_NUMBER + 1000000 < sqlite3_libversion_number())\n"
" errx(1, \"SQLITE major version mismatch: compiled %%u, now %%u\",\n"
" SQLITE_VERSION_NUMBER, sqlite3_libversion_number());\n"
" /* Earliest supported sqlite3 version */\n"
" if (SQLITE_VERSION_NUMBER < 3026000)\n"
" errx(1, \"SQLITE version %%u too old (minimum 3.26)\",\n"
" SQLITE_VERSION_NUMBER);\n"
)
"}\n";

Expand Down
4 changes: 2 additions & 2 deletions wallet/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1631,8 +1631,8 @@ static void migrate_channels_scids_as_integers(struct lightningd *ld,
/* FIXME: We cannot use ->delete_columns to remove
* short_channel_id, as other tables reference the channels
* (and sqlite3 has them referencing a now-deleted table!).
* When we can assume sqlite3 2021-04-19 (3.35.5), we can
* simply use DROP COLUMN (yay!) */
* When we can assume sqlite3 version 3.35.5 (2021-04-19),
* we can simply use DROP COLUMN (yay!) */

/* So null-out the unused column, at least! */
stmt = db_prepare_v2(db, SQL("UPDATE channels"
Expand Down
Loading