3 ms·
>The generated code always checks the various return codes and always uses the correct column ordinals and column types when binding or reading data to or from
by jbandela1 3y ago
>The generated code always checks the various return codes and always uses the correct column ordinals and column types when binding or reading data to or from the SQLite system — areas that are notoriously difficult to get right and keep right.
If you care mostly about this part, and are using C++20, you can use meta programming to accomplish this with some annotations of your SQL statements, and avoid code generators and separate syntax.
https://github.com/google/cpp-from-the-sky-down/blob/master/cpp20_sql/example.cpp https://github.com/google/cpp-from-the-sky-down/blob/master/...
ftsd::prepared_statement<
"INSERT INTO orders(item , customerid , price, discount_code ) "
"VALUES (?/*:item:text*/, ?/*:customerid:integer*/, ?/*:price:real*/, "
"?/*:discount_code:text?*/ );" //
>
insert_order{sqldb};
insert_order.execute({bind<"item">("Phone"), bind<"price">(1444.44),
bind<"customerid">(customer_id)});
insert_order.execute({bind<"item">("Laptop"), bind<"price">(1300.44),
bind<"customerid">(customer_id)});
insert_order.execute({bind<"customerid">(customer_id), bind<"price">(2000),
bind<"item">("MacBook"),
ftsd::bind<"discount_code">("BIGSALE")});
You can bind the parameters in any order, as long as the names are correct. If you don't bind any non-optional parameters or have the incorrect type, you will get a compile time error.
My talk going over how to implement this: https://youtu.be/1AYrd9iLQCw https://youtu.be/1AYrd9iLQCw
- noduerme 3y agowho in their right mind would trust this shit on a production database?
- keithalewis 3y agoPeople who write tests for the OSS they use?