August 12, 2008

Executing Multiple Statements in a SQLlite transaction

Posted in iPhone development tagged , , , , , , , at 4:00 pm by tetontech

Here is a quick example of how to execute multiple statements serially within a SQLite transaction.  This example comes from the next beta of QuickConnectiPhone.  I’m releasing it early here.


This code clears the values out of a table by dropping the table and then re-creating it all within one transaction and one asynchronous call.

function clearValues(){

    var dropSQL = 'DROP TABLE session';

    var createSQL = "CREATE TABLE IF NOT EXISTS session (key TEXT UNIQUE, information TEXT)";


    this.db.transaction(function(tx) {

            tx.executeSql(dropSQL);//end of main executeSql call


        });//end of transaction callback function



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: