Hybrid View

  1. #1
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default SqliteProxy for ST2

    SqliteProxy for ST2


    Hi,

    I have ported sqliteproxy to work with ST2.

    You can find previous thread
    http://www.sencha.com/forum/showthre...Proxy&p=661960

    Updated Code can be found under .
    https://github.com/tomalex0/SenchaTouch-v2-SqliteProxy
    Sencha Touch Demos

    IosToggleField Forum - Github
    Form Validation
    Forum - Github
    Iphone Settings Menu
    Forum
    Sqlite Storage & Login Manifest
    Forum
    KitchenSink MVC
    Forum - Github
    SqliteProxy-v1 Forum - Github
    SqliteProxy-v2
    Forum - Github
    Arshaw Fullcalendar Forum - Github






  2. #2
    Sencha User
    Join Date
    Nov 2011
    Location
    León, Spain
    Posts
    77
    Vote Rating
    3
    diesalher is on a distinguished road

      0  

    Default


    Hi.

    I'm a bit new in sencha and javascript so maybe this makes no sense...

    i've modified your proxy to be able to use params in the query..

    Code:
    read: function(operation, callback, scope) {
            var me = this;
    
    
            var sql = me.dbConfig.dbQuery || 'SELECT * FROM ' + me.dbConfig.tablename + '';
            var params, onSucess, onError;
    
    
            params = me.dbConfig.params ? me.dbConfig.params : [];
    
    
            onSucess = function(tx, results) {
                me.applyDataToModel(tx, results, operation, callback, scope);
            };
    
    
            onError = function(tx, err) {
                me.throwDbError(tx, err);
            };
    
    
            me.queryDB(me.dbConfig.dbConn, sql, onSucess, onError, params);
        }

    then, in order to load the store i do somethig like...

    Code:
     var qry = 'SELECT * FROM Test where field 1 = ? and field2 = ?';
     var params = [ 'P1','P2'];
     
    store.getProxy().dbConfig.dbQuery = qry;
    store.getProxy().dbConfig.params = params;
    store.load();
    Maybe what i say makes no sense for some reason i dont know...but it seems to work.

  3. #3
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default


    @diesalher

    Yea its fine, there are couple of other ways also, so i haven't rounded upon one .

    Code:
    read: function(operation, callback, scope) {
            
    	var param_arr = [];
    	Ext.iterate(operation.params,function(a,i){
    	    param_arr.push(i);
    	});
    	
            var thisProxy = this;
            var sql = operation.query || thisProxy.dbConfig.dbQuery || 'SELECT * FROM '+thisProxy.dbConfig.tablename+'';
            
            var params, onSucess, onError;
            
            onSucess = function(tx, results) {
                thisProxy.applyDataToModel(tx, results, operation, callback, scope);
            };
    
    
            onError = function(tx, err) {
                thisProxy.throwDbError(tx, err);
            };
    
    
            
            thisProxy.queryDB(thisProxy.dbConfig.dbConn, sql, onSucess, onError,param_arr);
        }
    Example

    Code:
    contactStore.load({params :{ name: '435'},query : 'select * from contacts_tables WHERE firstName = ?'});
    Sencha Touch Demos

    IosToggleField Forum - Github
    Form Validation
    Forum - Github
    Iphone Settings Menu
    Forum
    Sqlite Storage & Login Manifest
    Forum
    KitchenSink MVC
    Forum - Github
    SqliteProxy-v1 Forum - Github
    SqliteProxy-v2
    Forum - Github
    Arshaw Fullcalendar Forum - Github






  4. #4
    Sencha User
    Join Date
    Mar 2011
    Posts
    81
    Vote Rating
    0
    sarah_77 is on a distinguished road

      0  

    Default


    Great!! But this is a solution for manage SQLLite on PhoneGap with Sencha Touch 2.0?

    Thanks

  5. #5
    Sencha User
    Join Date
    Nov 2011
    Location
    León, Spain
    Posts
    77
    Vote Rating
    3
    diesalher is on a distinguished road

      0  

    Default


    I've been using sqliteproxy with good results in sencha 2.0

    i have a question

    I'm doing a function who loads data in several tables . Is there a way to do this inserts in a batch to load the stores when in finish the complete batch?

    now, to insert a record im doing something like..

    Code:
    Ext.create(model, {field1: data1,field2: data2}).save();
    but it seems to be asynchronous so if i insert 1000 records, i don't know if there is a way to wait till inserted to do a store.load() again.

    Maybe i'm facing this in the wrong way, i'm still learning javascript and sencha,

    Thanks

  6. #6
    Sencha User
    Join Date
    Mar 2011
    Posts
    81
    Vote Rating
    0
    sarah_77 is on a distinguished road

      0  

    Default


    I don't know this point: this is a solution for manage SQLLite on PhoneGap with Sencha Touch 2.0?

    Thanks

  7. #7
    Sencha User tomalex0's Avatar
    Join Date
    Apr 2009
    Location
    San Jose, CA
    Posts
    589
    Vote Rating
    16
    tomalex0 will become famous soon enough

      0  

    Default


    Sqlite query operation in browsers are asynchronous in nature, So i'm not sure how to handle callback of batch insertion. But you can implement callback in save function

    Go through http://docs.sencha.com/touch/2-0/#!/api/Ext.data.Model which does have usage of success callback in save function

    Code:
    user.save({success: function() {console.log('The User was updated');}});

    Quote Originally Posted by diesalher View Post
    I've been using sqliteproxy with good results in sencha 2.0

    i have a question

    I'm doing a function who loads data in several tables . Is there a way to do this inserts in a batch to load the stores when in finish the complete batch?

    now, to insert a record im doing something like..

    Code:
    Ext.create(model, {field1: data1,field2: data2}).save();
    but it seems to be asynchronous so if i insert 1000 records, i don't know if there is a way to wait till inserted to do a store.load() again.

    Maybe i'm facing this in the wrong way, i'm still learning javascript and sencha,

    Thanks
    Sencha Touch Demos

    IosToggleField Forum - Github
    Form Validation
    Forum - Github
    Iphone Settings Menu
    Forum
    Sqlite Storage & Login Manifest
    Forum
    KitchenSink MVC
    Forum - Github
    SqliteProxy-v1 Forum - Github
    SqliteProxy-v2
    Forum - Github
    Arshaw Fullcalendar Forum - Github






  8. #8
    Sencha User
    Join Date
    Feb 2013
    Posts
    10
    Vote Rating
    1
    mobileDev1600 is on a distinguished road

      0  

    Default sqliteproxy for SQLIte database

    sqliteproxy for SQLIte database


    Hi tomalex,

    Just wondering if your proxy is good for app which is based on PhoneGap + ST2 and SQlite database (not web sql).
    I have a SQLite database with some values added and want to use it in my app which i am creating using PhoneGap 2.3 and ST2.

    Thank you

    Quote Originally Posted by tomalex0 View Post
    Hi,

    I have ported sqliteproxy to work with ST2.

    You can find previous thread
    http://www.sencha.com/forum/showthre...Proxy&p=661960

    Updated Code can be found under .
    https://github.com/tomalex0/SenchaTouch-v2-SqliteProxy

  9. #9
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Cluj, Romania
    Posts
    654
    Vote Rating
    26
    vadimv will become famous soon enough vadimv will become famous soon enough

      0  

    Default


    @mobileDev1600 , ST2 has its own proxy for SQLite databases, check the docs and here http://vadimpopa.com/sencha-touch-2-...xy-for-sqlite/