Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

work sqlite titanium

$
0
0

hello

I'm trying to optimize the database in my app and work to better feeding tables, leaving my code so they can see if it is a good way to work feeding the database and where I can include this file must start at entry to the app.

module.exports = function(obj) {
    var db = Ti.Database.open('elite'),
        _ = require("/lib/underscore");
 
 
    db.execute('CREATE TABLE IF NOT EXISTS USUARIOS (id INTEGER PRIMARY KEY, user TEXT, pass TEXT)');
    db.close();
    /*FUNCION PARA INSERTAR REGISTROS EN LA BASE DE DATOS*/
    var insertData = function(args) {
 
        var client = Ti.Network.createHTTPClient({
             onload : function(e) {
                 var db = Ti.Database.open('elite');
                 db.execute('BEGIN IMMEDIATE TRANSACTION');
                 db.execute('DELETE FROM '+args.table);
                 var data = JSON.parse(this.responseText);
 
                 _.each(data, function(value) {
                    //Ti.API.info(JSON.stringify(value));
                    //var datos = JSON.stringify(value);
                    //db.execute(args.sql(datos));
                    Ti.API.info(args.sql(value));
                 });
                 db.execute('COMMIT TRANSACTION');
                 db.close();
 
             },
 
             onerror : function(e) {
                 Ti.API.error(e.error); 
             },
 
             timeout : 5000  
         });
 
         client.open("GET", args.url);
         client.send();
 
    };
    /***FINALIZAMOS FUNCION**/
    new insertData({
        url:'http://agrosuper.checkrocket.com/include/api/json/user.php',
        table:'USUARIOS',
        //sql:'INSERT INTO USUARIOS VALUES ('+this+',"'+this.name+'","'+this.password+'")',
        sql: function(e) {
            var datos = JSON.stringify(e);
            var consulta = datos['name'];
            return consulta;
        }
    });
 
 
 
};

Viewing all articles
Browse latest Browse all 8068

Trending Articles