Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-8712] iOS: Database Update not occurring outside of Ti.Cloud.Query function

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionWon't Do
Resolution Date2020-01-10T18:05:30.000+0000
Affected Version/sRelease 2.0.1
Fix Version/sn/a
ComponentsiOS
Labelscore, titanbeta
ReporterRay Belisle
AssigneeUnknown
Created2012-04-04T11:01:51.000+0000
Updated2020-01-10T18:05:30.000+0000

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))) } }); };

Comments

  1. Kevin Whinnery 2012-04-04

    Can you please provide the platform and version of the OS you're running on? Android+versions tested, or iOS+versions tested? Thanks...
  2. Ray Belisle 2012-04-04

    Just FYI, this was tested on IOS 5, xCode 4.2 on the IOS Simulator. Also tested on Android Device, same behaviour. Android 2.3.4, running Android Runtime v8 (haven't tried Rhino yet), Android API 2.3.3
  3. Jeff English 2012-04-12

    Moving to TIMOB as this doesn't seem to be a module issue.
  4. Alan Hutton 2020-01-10

    This issue is out of date with our current supported SDK release (7.5.2.GA as of the date of closure), and out of date with mobile OS versions. If community members feel that the issue is still valid, please create a new ticket. Please reference this closed ticket number, include SDK used, comments, and code that demonstrates/reproduces the issue.

JSON Source