Constexpr parsing of sql statement
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
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.
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. ;-)
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.
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.