John Stanton wrote:
I am not sure how to proceed with handling multiple SQL statements. Perhaps someone has some experiences they would be kind enough to share.

I want to store multi-statement SQL to implement an entire transaction in the form -
    BEGIN
     statement
     statement
     ...
    COMMIT

I can see that sqlite3_prepare has the capability of stepping through a multi statement string but it looks like each statement becomes a seperate vdbe object so if I had five statements I would have five sqlite3_stmt ptrs and would need to step through them in sequence.

Does anyone know if I see it correctly? Is there some way I have not seen to compile them all into one vdbe object?


John,

You see things correctly. You can't put multiple statements in one VDBE object (unless you use a trigger).

But I don't think you need to store multiple prepared statements unless you want to do so for speed.

Simply store the string that contains all the statements, and scan through them using sqlite3_prpeare in a loop. You can include the begin and commit statements as well. You are done after executing the last statement, for which sqlite3_prepare will return a null tail pointer. You will only ever have one statement prepared to execute at any point.

   char* sql_block = <multi statment sql>
   sqlite3_stmt* s;
   char* sql= sql_block;
   do {
       sqlite3_prepare_v2(db, sql, -1, &s, &sql);
      <execute statement s>
      sqlite3_finalize(s);
   } while (sql != NULL);

A trigger block can contain multiple SQL statements, so you might be able to use a trigger to do what you want if you execute a trigger in a transaction.

HTH
Dennis Cote


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to