On Thu, 2007-03-01 at 05:35 +0100, daan wrote: > I'm compiling a SQL statement (consisting of multiple statements separated > by semicolons) using sqlite3_prepare_v2 into a series of sqlite3_stmt > pointers, later to be executed with sqlite3_step(). > > A statement such as: > > DROP TABLE IF EXISTS test; > CREATE TABLE test (id INTEGER, name TEXT); > > is compiled into two sqlite3_stmt pointers that are subsequently fed > through sqlite3_step(): this works fine. That is, the first time I run the > program (and the database didn't exist upon program start). When I run the > program the 2nd time (and the database indeed exists upon program start) > the prepare_v2 bails out with ERROR and error 'table test already exists'. > > When the statement above is fed through sqlite3_exec() the error does not > occur. When I had a look at the sqlite3_exec code it struck me that it > interleaves the calls to prepare/step/reset in a different way: > > prepare/step/reset prepare/step/reset > > whereas I am trying to > > prepare/prepare step/step reset/reset > > When I change my code to a similar interleaving scheme as sqlite3_exec I > dont have any problems. > > My question is: is it indeed required to interleave the calls to > sqlite3_prepare_v2 and sqlite3_step in a similar way as sqlite3_exec does, > or should it be possible to fully precompile a series of statements which > then later can be executed?
When you compile a statement, it is compiled against the current database schema. In the second run it tried to compile "CREATE TABLE test" against a schema that already contained the table "test". Hence the error message. Precompiling a series of statements to be executed later will be fine, provided you are not modifying the database schema. Dan. ----------------------------------------------------------------------------- To unsubscribe, send email to [EMAIL PROTECTED] -----------------------------------------------------------------------------