1. #11
    Sencha Premium Member
    Join Date
    May 2011
    Posts
    71
    Answers
    5
    Vote Rating
    6
    cyee is on a distinguished road

      0  

    Default


    Have you tried changing your 'id' field in the model to something else, like 'primaryID'?

    I believe there's a problem if you use a field called 'id' in your model

  2. #12
    Sencha User
    Join Date
    Jun 2012
    Posts
    136
    Answers
    8
    Vote Rating
    1
    munder is on a distinguished road

      0  

    Default


    Thanks, cyee. I'm using the SQLlite proxy by Shepsii, which requires an id named 'id'. I'm a bit further along now, actually. Initially, I had the following code to copy the downloaded data to the local store:
    Code:
               answersonline.each(function (record) {                            
                                 answersStore.add(record);
                            });
                            answersStore.sync();
    where 'answersonline' refers to the store containing the the downloaded data and 'answers' refers to the offline store using the SQLlite proxy. I found that my app would apparently continue before the sync was complete, with the result that it would try to display a user answer which was not actually in the store. I discovered that inserting "console.log('answer copied')" would apparently ensure that all answers were in the offline store (presumably by slowing things down). I asked in the forum if anybody knew how to detect when the sync was complete and Mitch kindly supplied an answer, which, unfortunately, was sheer gobbledegook to me. However, I took him to be saying that I should call the sync after each record was added:
    Code:
               answersonline.each(function (record) {                            
                                answersStore.add(record);
                               answersStore.sync();
                            });
    Whilst that did have the effect of ensuring that all the answers were in the table before moving on, it had the unfortunate side effect of creating multiple duplicates. I've now reverted to moving the sync outside the loop and find I now have just one of each record. (Curiously, if I downloaded 12 records, I got 12 copies of the first, 11 of the second, 10 of the third etc.) Anyway it's a relief that I now have no duplicates, BUT I still don't know how to detect when they have all been safely copied and synced to the offline store. The only relevant event I can see in the docs is beforeSync, which is the opposite of what I need. If anybody does know of an appropriate event to trap, please let me know - I'm afraid I struggle with the documentation.

  3. #13
    Sencha Premium Member
    Join Date
    Jul 2012
    Posts
    26
    Vote Rating
    1
    alile is on a distinguished road

      0  

    Default


    There are two parts to this post - the first is what this chain was previously about, the second regarding what munder asked above.
    --- 1---
    I tried many things on this, and what worked for me was to only sync the stores on window unload. I added the following in Main.launch:

    Code:
    window.onbeforeunload = this.handleWindowBeforeUnload;
    and for the unload,

    Code:
    Ext.getStore("LocalNotificationStore").sync();
    Currently my solution is not duplicating any entries as it seemed that the duplication only came when saving the records. And only saving it once seems to work around that. It could well be that there are other fixes in the many that I tried that linger on in my project and they are contributing, but this was the last piece that i added which stopped the problem.

    --- 2 ---
    I recommend looping through all the records and adding them to your store, and then calling sync(). As mentioned above, each modification of a local storage record seems to cause duplication. Cannot say precisely why your approach is duping, but there it is. So your original code was better (for performance reasons as well), but what you may need to do is declare the record "dirty" for the sync to properly save it.

    Code:
    answersonline.each(function (record) 
    {                                                        
          answersStore.add(record);
          record.setDirty();
    });
    
    answersStore.sync();

  4. #14
    Sencha User
    Join Date
    Jun 2012
    Posts
    136
    Answers
    8
    Vote Rating
    1
    munder is on a distinguished road

      0  

    Default


    Thank you for you suggestion, alile. I'm afraid calling setDirty() has made no difference. It seems that sync() is not instantaneous, with the result that when the app progresses after supposedly filling the db table, the data aren't all there yet, so it coughs and splutters and falls over. I must say using (attempting to use) Sencha is a humbling experience. I've rarely felt quite so thick since being introduced to quantum mechanics in school and reading the docs is like an exercise in biblical exegesis. I recently produced in WinJS a version of the app I'm now trying to create in Sencha. A walk in the park in comparison. Good luck.

  5. #15
    Sencha User
    Join Date
    Jan 2014
    Posts
    7
    Vote Rating
    0
    chrisman is on a distinguished road

      0  

    Default


    I had a similar problem using WebSQL.
    I would load a model, update some data on it, then save and a duplicate would appear in the database with the same primary key!

    The answer:
    1) Make sure the record was NOT being set to dirty - so I removed the model.setDirty()
    2) Set phantom to false to force an update

    model.phantom = false

    Then on save, the record in the database was updated!

    Hope this helps

  6. #16
    Sencha User
    Join Date
    Jun 2012
    Posts
    136
    Answers
    8
    Vote Rating
    1
    munder is on a distinguished road

      1  

    Default


    Thanks, Chrisman. I had in fact discovered that approach since posting my comment, but I'm grateful to you for suggesting a solution.
    As it happens, I may well be dumping the WebSQL approach anyway, as it's been deprecated. Trouble is I don't know what to use instead, given that Apple are in no hurry to implement IndexedDB and previously adopted an alarmingly high handed approach to local storage. In my WinJS app, I simply downloaded the SQL result from the web service and stored it in a bunch of JSON files in the user's "roaming" storage area, but I don't quite get how I might do something similar with Sencha Touch.
    Actually, I might even not use ST, since, by the time I had finished following all the advice on how to optimize my app, there wan't much of the ST magic left, and it still wasn't brilliantly responsive. I'm currently investigating Intel's XDK and waiting for the release of famo.us.

  7. #17
    Sencha User
    Join Date
    Jan 2014
    Posts
    7
    Vote Rating
    0
    chrisman is on a distinguished road

      0  

    Default


    No worries - I was only a year late with a reply!

    Cheers for the heads-up about WebSQL being deprecated, I didn't realise!

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi