From 89ede8a208c4f6b2dd561076dfad12e519e65935 Mon Sep 17 00:00:00 2001 From: Joseph Goulden Date: Thu, 18 Jul 2024 14:04:06 +0100 Subject: [PATCH] plugins/sql: allow datetime functions Changelog-Changed: Plugins: now allows date and time sqlite functions. --- contrib/msggen/msggen/schema.json | 9 ++++++++- doc/schemas/lightning-sql-template.json | 9 ++++++++- plugins/sql.c | 14 ++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/contrib/msggen/msggen/schema.json b/contrib/msggen/msggen/schema.json index f7f040d11497..54364243cdfa 100644 --- a/contrib/msggen/msggen/schema.json +++ b/contrib/msggen/msggen/schema.json @@ -28382,6 +28382,9 @@ "* avg", "* coalesce", "* count", + "* date", + "* datetime", + "* julianday", "* hex", "* quote", "* length", @@ -28390,8 +28393,12 @@ "* upper", "* min", "* max", + "* strftime", "* sum", - "* total" + "* time", + "* timediff", + "* total", + "* unixepoch" ], "tables": [ "Note that the first column of every table is a unique integer called `rowid`: this is used for related tables to refer to specific rows in their parent. sqlite3 usually has this as an implicit column, but we make it explicit as the implicit version is not allowed to be used as a foreign key.", diff --git a/doc/schemas/lightning-sql-template.json b/doc/schemas/lightning-sql-template.json index efd9415b316f..135f895e5e38 100644 --- a/doc/schemas/lightning-sql-template.json +++ b/doc/schemas/lightning-sql-template.json @@ -90,6 +90,9 @@ "* avg", "* coalesce", "* count", + "* date", + "* datetime", + "* julianday", "* hex", "* quote", "* length", @@ -98,8 +101,12 @@ "* upper", "* min", "* max", + "* strftime", "* sum", - "* total" + "* time", + "* timediff", + "* total", + "* unixepoch" ], "tables": [ "Note that the first column of every table is a unique integer called `rowid`: this is used for related tables to refer to specific rows in their parent. sqlite3 usually has this as an implicit column, but we make it explicit as the implicit version is not allowed to be used as a foreign key.", diff --git a/plugins/sql.c b/plugins/sql.c index bafe6e70c10b..b4f55dfc51a9 100644 --- a/plugins/sql.c +++ b/plugins/sql.c @@ -334,6 +334,20 @@ static int sqlite_authorize(void *dbq_, int code, return SQLITE_OK; if (streq(b, "total")) return SQLITE_OK; + if (streq(b, "date")) + return SQLITE_OK; + if (streq(b, "datetime")) + return SQLITE_OK; + if (streq(b, "julianday")) + return SQLITE_OK; + if (streq(b, "strftime")) + return SQLITE_OK; + if (streq(b, "time")) + return SQLITE_OK; + if (streq(b, "timediff")) + return SQLITE_OK; + if (streq(b, "unixepoch")) + return SQLITE_OK; } /* See https://www.sqlite.org/c3ref/c_alter_table.html to decode these! */