1. #1
    Sencha User murrah's Avatar
    Join Date
    Oct 2007
    Location
    Katoomba, Blue Mountains, west of Sydney, Australia
    Posts
    379
    Vote Rating
    11
    murrah will become famous soon enough

      0  

    Default [TIP] Using the SQLite store when rapidly changing the data

    [TIP] Using the SQLite store when rapidly changing the data


    Hi.

    After much hair pulling here: http://www.sencha.com/forum/showthre...519#post561519 ,
    Makana kindly pointed out the correct way to accommodate the fact that the SQLite DB in the AIR Adapter is now Asyncronous (previously syncronous). This is particularly relevant if you are making rapid changes to the store. What I found is that when I added multiple records in a loop the store stopped working and the records didnt make it to the database table.

    What Makana said was:
    ***************
    Hello Murray,

    the problem is the following:
    If you use the update save directly after the insert save, the inserts aren't done yet and so within the second save-method the insert records are to be added again (because they still have phantom==true).
    Please leave the first save method and only use the second.

    That is normal behavior you would also run into if you would try it in a browser (not Air) app since ajax requests to a server-side script are async as well.

    There are the following possibilities:
    1. Use autoSave: true and do inserts and updates in (async) sequence.

    PHP Code:
    WholeMealCafe.MemberStore.load({
        
    callback: function (recordsoptionssuccess) {
            if (
    success === true) {

                var 
    recArr = []; // array to hold the records to insert together

                
    for (var 010i++) {
                    var 
    pk Ext.uniqueId(true);
                    var 
    rec = new WholeMealCafe.memberRec({
                        
    membIdpk,
                        
    membParentIdparentId,
                        
    membCode'TEST' i,
                        
    membFirstname'',
                        
    membLastname'',
                        
    membEmail'',
                        
    isFolderfalse
                    
    }, pk); // it is better to leave pk here...
                    
    rec.phantom true// ... and not to set phantom
                    
    recArr.push(rec);
                };

                
    // set the isFolder field on the parent after the inserts are done
                
    WholeMealCafe.MemberStore.on('save', function () {
                    var 
    memberRec WholeMealCafe.MemberStore.getById(parentId);
                    
    air.trace('set isFolder for ' parentId)
                    
    memberRec.set('isFolder'true); // saves automatically
                
    }, this, {
                    
    singletrue
                
    });

                
    WholeMealCafe.MemberStore.add(recArr); // add all records at once (save automatically)
            
    }
        },
        
    scopethis
    }); 
    2. and the better way: use autoSave: false and do one save at the end.

    Code:
    PHP Code:
    WholeMealCafe.MemberStore.load({
        
    callback: function (recordsoptionssuccess) {
            if (
    success === true) {
                
    air.trace('store loaded')

                for (var 
    010i++) {
                    var 
    pk Ext.uniqueId(true);
                    var 
    rec = new WholeMealCafe.memberRec({
                        
    membIdpk,
                        
    membParentIdparentId,
                        
    membCode'TEST' i,
                        
    membFirstname'',
                        
    membLastname'',
                        
    membEmail'',
                        
    isFolderfalse
                    
    });
                    
    WholeMealCafe.MemberStore.add(rec);
                };

                
    //WholeMealCafe.MemberStore.save(); // dont do this yet

                // Now set the isFolder field on the parent
                
    var memberRec WholeMealCafe.MemberStore.getById(parentId);
                
    air.trace('set isFolder for ' parentId)
                
    memberRec.set('isFolder'true);

                
    WholeMealCafe.MemberStore.save(); // save all together
            
    }
        },
        
    scopethis
    }); 
    As I said, it's general Ext-ish behavior so I think there's no need to build a workaround for Air apps.

    Hope it helps.

    makana
    ***************

    And, if, as I did, you also have a form that updates the store, and you set autoSave:false, you need to do something like this to submit the changes to the form data:

    eg Your form submit button:
    PHP Code:
    {
        
    xtype'button',
        
    scopethis,
        
    handlerthis.saveData,
        
    text'Save'

    the saveData method. There may be a better way to do this but the main point is that you need to call the store's save() method to get the changes from the store to the database:
    PHP Code:
    saveData: function () {
        
    // This seems a bit long winded! Maybe there is a shortcut?
        
    var idFld this.getForm().findField('membId').getValue();
        var 
    rec WholeMealCafe.MemberStore.getById(idFld)
        
    this.getForm().updateRecord(rec);
        
    WholeMealCafe.MemberStore.save();

    I hope this might help others.

    Cheers,
    Murray
    Cheers,
    Murray

  2. #2
    Sencha User makana's Avatar
    Join Date
    Apr 2008
    Location
    Dresden, Germany
    Posts
    526
    Vote Rating
    17
    makana has a spectacular aura about makana has a spectacular aura about

      0  

    Default


    Please consider, that this is with the 3.3.2 version of the air-adapter.
    There are bugs in the current downloadable package regarding this issue.

    I'm just waiting for the new build to become available on the download page. Almost 3 weeks now... I cannot do anything...

    So slowly, guys But with 3.3.2 it's just like Murray said. Thanks for publishing the tip.

    Code:
    , saveData: function () {
        // This seems a bit long winded! Maybe there is a shortcut?
    //    var idFld = this.getForm().findField('membId').getValue();
        // not realy shorter but a bit faster I think. Give the field an itemId and use...
        var idFld = this.getComponent('theItemId').getValue();
        var rec = WholeMealCafe.MemberStore.getById(idFld)
        this.getForm().updateRecord(rec);
        WholeMealCafe.MemberStore.save();
    }
    ... or hold a reference to the current editing record in your form class.
    Programming today is a race between software engineers striving to build bigger and better іdiot-proof programs, and the universe striving to produce bigger and better idiots. So far, the universe is winning. (Rick Cook)

    Enhanced ExtJS adapter for Adobe AIR

Similar Threads

  1. Tip: ExtJS, Adobe AIR and SQLite
    By BenJaminPrater in forum Ext.air for Adobe AIR
    Replies: 10
    Last Post: 16 May 2012, 11:36 AM
  2. Tip: when changing a component to floating, be sure to hide it first
    By jep in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 18 Jan 2011, 4:31 AM
  3. Help changing Json Store data
    By nicosk in forum Ext 3.x: Help & Discussion
    Replies: 7
    Last Post: 29 Jul 2010, 2:56 AM
  4. SQLite, how to select data?
    By mitchellsimoens in forum Ext.air for Adobe AIR
    Replies: 1
    Last Post: 31 Dec 2009, 7:03 AM
  5. Dynamically Changing url of Data Store
    By fangzhouxing in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 17 Jul 2008, 10:49 PM

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar