From 5270c149e3f71eb6431380a9770055fec8e5b23d Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Wed, 17 Jul 2019 18:11:19 +0200 Subject: [PATCH] wallet: Add macro to annotate SQL statements These two simple macros have a twofold use: 1) They serve as annotations for the query extraction tool to find them when extracting queries from the C source code. 2) They replace the actual queries with names that can be used to lookup the queries in a table again, once they have been rewritten into the target SQL dialect. Signed-off-by: Christian Decker --- wallet/db.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/wallet/db.h b/wallet/db.h index 03e849548..3f58e057c 100644 --- a/wallet/db.h +++ b/wallet/db.h @@ -25,6 +25,28 @@ struct db { const char **changes; }; +/** + * Macro to annotate a named SQL query. + * + * This macro is used to annotate SQL queries that might need rewriting for + * different SQL dialects. It is used both as a marker for the query + * extraction logic in devtools/sql-rewrite.py to identify queries, as well as + * a way to swap out the query text with it's name so that the query execution + * engine can then look up the rewritten query using its name. + * + */ +#define NAMED_SQL(name,x) x + +/** + * Simple annotation macro that auto-generates names for NAMED_SQL + * + * If this macro is changed it is likely that the extraction logic in + * devtools/sql-rewrite.py needs to change as well, since they need to + * generate identical names to work correctly. + */ +#define SQL(x) NAMED_SQL( __FILE__ ":" stringify(__LINE__) ":" stringify(__COUNTER__), x) + + /** * db_setup - Open a the lightningd database and update the schema *