Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-8712

iOS: Database Update not occurring outside of Ti.Cloud.Query function

    Details

    • Type: Bug
    • Status: Closed
    • Priority: High
    • Resolution: Won't Do
    • Affects Version/s: Release 2.0.1
    • Fix Version/s: None
    • Component/s: iOS
    • Labels:
    • Environment:

      OSX 10.7.3, Titanium Studio 2, Titanium SDK 2.0GA

      Description

      I decided to create a database update routine that would extract information from the Appcelerator Cloud and update a local sqlite database. I seemed to get the data properly from the cloud, but the sqlite database was never updated. All of my database routines are stored in a library. I was requiring the library at the top of my code, then using it inside the Ti.Cloud.Query success function. This NEVER updated the database. I changed the database variable definition to be part of the success function and now it works fine. I expect you should be able to declare outside the function and still use it...

      The successful code is shown below. If you move the line: var db = dblib.database("org.db","organization"); outside the Ti.Cloud.Query definition, the insert does not go into the database.

      exports.UpdateDB = function() {
      var Cloud = require('ti.cloud');
      var dblib = require('/lib/database');

      Cloud.Users.login(

      { login: 'raybelisle@gmail.com', password: 'pass', }

      , function (e) {
      if (e.success)

      { var user = e.users[0]; }

      else

      { alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e))) }

      ;
      })

      Cloud.Objects.query({
      classname : 'organization',
      //page : 1,
      //per_page : 10,
      where : {
      orgid :

      {'$gt' : 10}

      }
      }, function(e) {
      if(e.success) {
      var db = dblib.database("org.db","organization");
      dblib.init();

      for(var i = 0; i < e.organization.length; i++)

      { var org = e.organization[i]; var o = new Array; o[0] = org.Name; o[1] = org.Category; o[2] = JSON.stringify(org.Locations); o[3] = JSON.stringify(org.orgLink); dblib.insertRow('organization', 'Name,Category,Locations,Links',o); }

      } else

      { alert('Error:\\n' + ((e.error && e.message) || JSON.stringify(e))) }

      });
      };

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              raybelisle Ray Belisle
            • Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-13010
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Integration