0
votes

I am using sqlite3 (maybe sqlite4 in the future) and I need something like dynamic tables. I have many tables with the same format: values_2012_12_27, values_2012_12_28, ... (number of tables is dynamic) and I want to select dynamically the table that receives some data.
I am using _sqlite3_prepare with INSERT INTO ? VALUES(?,?,?). Ofcourse this fails to compile (syntax error near ?). There is a nice and simple way to do this in sqlite ?

Thanks

1
Why don't you snprintf() the table name into the query? - user529758
Because I will need to _sqlite3_prepare and keep a statement for every table I have. This is what i want to avoid (if possibile). Thanks - vlg789

1 Answers

1
votes

Using SQL parameters is not possible for identifiers such as table or column names.

If you don't want to keep so many prepared statements around, just prepare them on the fly whenever you need one.


If your database were properly normalized, you would have a single big values table with an extra date column. This organization is usually to be preferred, unless you have measured both and found that the better performance (if it actually exists) outweighs the overhead of managing multiple tables.