Code to describe transaction with SQLite in titanium is mentioned below.
Let say we have a simple employe table and we will insert employee data in bulk.
//Define an array holds employee data
var empData = [];
//Data added to the array
empData.push({id:’001′, name:’emp1′});
empData.push({id:’002′, name:’emp2′});
.
.
.
empData.push({id:’00n’, name:’empn’});
//************* DB Operation ************
//Define the database
var myDb = Ti.Database.open(’employeeDb’);
//Starts the Transaction
myDb.execute(‘BEGIN’);
//Insert the data from the array
for(var count = 0; count < empData.length; count++){
//Query to insert data
myDb.execute(‘INSERT INTO employee (id, name) VALUES (empData[count].id, empData[count].name));
}
//Comit the transaction
myDb.execute(‘COMMIT’);
//Close the db connection
myDb.close();