SHARE
TWEET

WebDB Create Tables Stratagem

jameslafferty May 27th, 2012 27 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * _dbqueries is an object for storing the queries my app is using. _dbqueries.createTables
  3.  * is an array of the sql statements for creating the tables the app is going to need.
  4.  *
  5.  * _mySELFDb is a WebDB object in the same closure as this snippet. The closure contains all
  6.  * the functions for managing the database, so it's self-contained.
  7.  */
  8.  
  9.  
  10.         _createTables = function () {
  11.                 var _increment, _queries, _tableMaker;
  12.                
  13.                 _queries = _dbqueries.createTables;
  14.                 _increment = 0;
  15.                
  16.                 _tableMaker = function (tx, i) {
  17.                         i += 1;
  18.                         if (_queries[i - 1]) {
  19.                                 console.log('Installing... executing :' + _queries[i - 1]);
  20.                                 tx.executeSql(_queries[i - 1], [], function (tx, result) {
  21.                                         _tableMaker(tx, i);
  22.                                 });
  23.                         } else {
  24.                                 console.log('Finished');
  25.                         }
  26.                 };
  27.                 if ('function' === typeof _mySELFDb.transaction) {
  28.                         _mySELFDb.transaction(function (tx) {
  29.                                 _tableMaker(tx, _increment);
  30.                         });
  31.                 }
  32.         };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top