Constexpr parsing of sql statement
(1) By Marco Bubke (marcob) on 2021-03-19 14:56:08 [source]
I know the Sqlite parser is generated and it would be nice to have some information at compile time. So would it be possible to change the parser to use constexpr so I could get some information about the statements like the count of columns of the select statement?
Best regards, Marco
(2) By ddevienne on 2021-03-19 15:28:12 in reply to 1 [link] [source]
To my surprise,
constexpr SQL parsing is a thing :)
That one even tests against SQLite, according to its doc, so maybe you're in luck.
Constexpr, i.e. compile-time processing, is a C++17 (or newer) thing, and SQLite is pure C.
So you're quite unlikely to get it from the official SQLite authors I'm guessing.
(3) By Marco Bubke (marcob) on 2021-03-19 15:39:27 in reply to 2 [link] [source]
To my understanding this is more a very simple constexpr database. Actually constexpr was already introduced in C++11 but hardly useful. With C++ 20 they even added dynamic allocations. So why not use the C parser? C++ doesn't mean that you have to use every C++ feature. ;-)
(4) By Larry Brasfield (larrybr) on 2021-03-19 15:49:38 in reply to 3 [link] [source]
So why not use the C parser?
I presume you mean "why not use the C++ compiler?"
The SQLite library is designed to be used on a wide variety of systems, including embedded systems where, typically, C++ compilers either do not exist or lag far behind the modern (and still evolving) C++ language.
I agree that C code can be made to compile as C++ (without using non-C features), and is sometimes made better for it. But that does not make it sensible for every project.
(5) By Marco Bubke (marcob) on 2021-03-20 14:37:29 in reply to 4 [link] [source]
To my understanding the parser is generated. So it could generate constexpr C++. In C++ 20 you have even constexpr dynamic allocations so I guess it can work. But I decided now to write my own simple 'parser'. Should be enough for what I need. But it would be nice if they add constexpr to C too.