On 2014/04/17 20:43, aperi2007 wrote:
Hi to all,

There is in sqlite a command to run a query build at runtime ?

Our use-case is a list of query build from a sql script and stored in a table.

something like this:

select EXECUTE([field_query]) from table1;

where "table1" is the table and "field1" is the field where the builded query 
was previous stored.

the queries could be of kind "create ...", "insert ...", "update ...." and so 
on.


This is not only impossible in the current SQLite implementation, it is also inconceivable. By that I mean that the query output can be of any form, there is no way a prepare statement can know before-hand what the query would look like, it might not even be a SELECT as you point out. Let's say the format issue is overcome, whereto will errors in the secondary query be reported? And would the secondary query be able to refer to another in-table-pre-saved query? If so a infinite loop may quickly arise.

You could of course implement it given you know exactly what to expect from the Queries, I believe it is even done somewhere - but you'd have to do something like this (pseudo coded for brevity):

....
mResult = RunSelectQuery('SELECT field_query FROM table1');
if (mResult != Error) {
  mResult = Execute(mResult); //[1]
}
...

[1] <-- Of course at this point you need to parse the sql a bit to know what 
kind of query result is expected, if any...




_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to