contributions/mobl/www/js/persistence.store.sql.js
/**
   * Internal function to persist an object to the database
   * this function is invoked by persistence.flush()
   */
Internal function to persist an object to the database
this function is invoked by persistence.flush()
Internal function to persist an object to the database this function is invoked by persistence . flush ()
function save(obj, tx, callback) {
    var meta = persistence.getMeta(obj._type);
    var tm = persistence.typeMapper;
    var properties = [];
    var values = [];
    var qs = [];
    var propertyPairs = [];
    if(obj._new) { 
      for (var p in meta.fields) {
        if(meta.fields.hasOwnProperty(p)) {
          obj._dirtyProperties[p] = true;
        }
      }
    } 
    for ( var p in obj._dirtyProperties) {
      if (obj._dirtyProperties.hasOwnProperty(p)) {
        properties.push("`" + p + "`");
        var type = meta.fields[p] || tm.idType;
        values.push(tm.entityValToDbVal(obj._data[p], type));
        qs.push(tm.outVar("?", type));
        propertyPairs.push("`" + p + "` = " + tm.outVar("?", type));
      }
    }
    var additionalQueries = [];
    for(var p in meta.hasMany) {
      if(meta.hasMany.hasOwnProperty(p)) {
        additionalQueries = additionalQueries.concat(persistence.get(obj, p).persistQueries());
      }
    }
    executeQueriesSeq(tx, additionalQueries, function() {
        if (properties.length === 0) { 
          if(callback) callback();
          return;
        }
        obj._dirtyProperties = {};
        if (obj._new) {
          properties.push('id');
          values.push(tm.entityIdToDbId(obj.id));
          qs.push(tm.outIdVar('?'));
          var sql = "INSERT INTO `" + obj._type + "` (" + properties.join(", ") + ") VALUES (" + qs.join(', ') + ")";
          obj._new = false;
          tx.executeSql(sql, values, callback);
        } else {
          var sql = "UPDATE `" + obj._type + "` SET " + propertyPairs.join(',') + " WHERE id = " + tm.outId(obj.id);
          tx.executeSql(sql, values, callback);
        }
      });
  }
function save ( obj , tx , callback ) { var meta = persistence . getMeta ( obj . _type ) ; var tm = persistence . typeMapper ; var properties = [ ] ; var values = [ ] ; var qs = [ ] ; var propertyPairs = [ ] ; if ( obj . _new ) { for ( var p in meta . fields ) { if ( meta . fields . hasOwnProperty ( p ) ) { obj . _dirtyProperties [ p ] = true ; } } } for ( var p in obj . _dirtyProperties ) { if ( obj . _dirtyProperties . hasOwnProperty ( p ) ) { properties . push ( "`" + p + "`" ) ; var type = meta . fields [ p ] || tm . idType ; values . push ( tm . entityValToDbVal ( obj . _data [ p ] , type ) ) ; qs . push ( tm . outVar ( "?" , type ) ) ; propertyPairs . push ( "`" + p + "` = " + tm . outVar ( "?" , type ) ) ; } } var additionalQueries = [ ] ; for ( var p in meta . hasMany ) { if ( meta . hasMany . hasOwnProperty ( p ) ) { additionalQueries = additionalQueries . concat ( persistence . get ( obj , p ) . persistQueries ( ) ) ; } } executeQueriesSeq ( tx , additionalQueries , function ( ) { if ( properties . length === 0 ) { if ( callback ) callback ( ) ; return ; } obj . _dirtyProperties = { } ; if ( obj . _new ) { properties . push ( 'id' ) ; values . push ( tm . entityIdToDbId ( obj . id ) ) ; qs . push ( tm . outIdVar ( '?' ) ) ; var sql = "INSERT INTO `" + obj . _type + "` (" + properties . join ( ", " ) + ") VALUES (" + qs . join ( ', ' ) + ")" ; obj . _new = false ; tx . executeSql ( sql , values , callback ) ; } else { var sql = "UPDATE `" + obj . _type + "` SET " + propertyPairs . join ( ',' ) + " WHERE id = " + tm . outId ( obj . id ) ; tx . executeSql ( sql , values , callback ) ; } } ) ; }
Internal function to persist an object to the database
 this function is invoked by persistence.flush()
Internal function to persist an object to the database this function is invoked by persistence . flush ()
// Mark all properties dirty // Nothing changed