{ "id": "89471", "key": "TIMOB-8712", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "10100", "description": "This issue won't be actioned.", "name": "Won't Do" }, "resolutiondate": "2020-01-10T18:05:30.000+0000", "created": "2012-04-04T11:01:51.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "core", "titanbeta" ], "versions": [ { "id": "13272", "description": "Release 2.0.1", "name": "Release 2.0.1", "archived": true, "released": true, "releaseDate": "2012-04-16" } ], "issuelinks": [], "assignee": null, "updated": "2020-01-10T18:05:30.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "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...\r\n\r\nThe 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.\r\n\r\nexports.UpdateDB = function() {\r\nvar Cloud = require('ti.cloud');\r\nvar dblib = require('/lib/database');\r\n\r\nCloud.Users.login({\r\n login: 'raybelisle@gmail.com',\r\n password: 'pass',\r\n}, function (e) {\r\n if (e.success) {\r\n var user = e.users[0];\r\n\r\n } else {\r\n alert('Error:\\\\n' +\r\n ((e.error && e.message) || JSON.stringify(e)))\r\n };\r\n})\r\n\r\n\tCloud.Objects.query({\r\n\t\tclassname : 'organization',\r\n\t\t//page : 1,\r\n\t\t//per_page : 10,\r\n\t\twhere : {\r\n\t\t\torgid : {'$gt' : 10}\r\n\t\t}\r\n\t}, function(e) {\r\n\t\tif(e.success) {\r\n\t\t\tvar db = dblib.database(\"org.db\",\"organization\");\r\n\t\t\tdblib.init();\r\n\r\n\t\t\tfor(var i = 0; i < e.organization.length; i++) {\r\n\t\t\t\tvar org = e.organization[i];\r\n\t\t\t\tvar o = new Array;\r\n\t\t\t\to[0] = org.Name;\r\n\t\t\t\to[1] = org.Category;\r\n\t\t\t\to[2] = JSON.stringify(org.Locations);\r\n\t\t\t\to[3] = JSON.stringify(org.orgLink);\r\n\t\t\t\tdblib.insertRow('organization', 'Name,Category,Locations,Links',o);\r\n\t\t\t}\r\n\t\t} else {\r\n\t\t\talert('Error:\\\\n' + ((e.error && e.message) || JSON.stringify(e)))\r\n\t\t}\r\n\t}); \r\n};", "attachment": [], "flagged": false, "summary": "iOS: Database Update not occurring outside of Ti.Cloud.Query function", "creator": { "name": "raybelisle", "key": "raybelisle", "displayName": "Ray Belisle", "active": true, "timeZone": "America/Edmonton" }, "subtasks": [], "reporter": { "name": "raybelisle", "key": "raybelisle", "displayName": "Ray Belisle", "active": true, "timeZone": "America/Edmonton" }, "environment": "OSX 10.7.3, Titanium Studio 2, Titanium SDK 2.0GA", "comment": { "comments": [ { "id": "189878", "author": { "name": "kwhinnery", "key": "kwhinnery", "displayName": "Kevin Whinnery", "active": true, "timeZone": "America/Chicago" }, "body": "Can you please provide the platform and version of the OS you're running on? Android+versions tested, or iOS+versions tested?\r\n\r\nThanks...", "updateAuthor": { "name": "kwhinnery", "key": "kwhinnery", "displayName": "Kevin Whinnery", "active": true, "timeZone": "America/Chicago" }, "created": "2012-04-04T14:38:33.000+0000", "updated": "2012-04-04T14:38:33.000+0000" }, { "id": "189906", "author": { "name": "raybelisle", "key": "raybelisle", "displayName": "Ray Belisle", "active": true, "timeZone": "America/Edmonton" }, "body": "Just FYI, this was tested on IOS 5, xCode 4.2 on the IOS Simulator.\r\n\r\nAlso tested on Android Device, same behaviour. Android 2.3.4, running Android Runtime v8 (haven't tried Rhino yet), Android API 2.3.3", "updateAuthor": { "name": "raybelisle", "key": "raybelisle", "displayName": "Ray Belisle", "active": true, "timeZone": "America/Edmonton" }, "created": "2012-04-04T18:55:51.000+0000", "updated": "2012-04-04T18:55:51.000+0000" }, { "id": "190832", "author": { "name": "jenglish", "key": "jenglish", "displayName": "Jeff English", "active": true, "timeZone": "America/Chicago" }, "body": "Moving to TIMOB as this doesn't seem to be a module issue.", "updateAuthor": { "name": "jenglish", "key": "jenglish", "displayName": "Jeff English", "active": true, "timeZone": "America/Chicago" }, "created": "2012-04-12T19:35:20.000+0000", "updated": "2012-04-12T19:35:20.000+0000" }, { "id": "453649", "author": { "name": "ahutton", "key": "ahutton", "displayName": "Alan Hutton", "active": true, "timeZone": "America/Los_Angeles" }, "body": "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. \r\n\r\nIf 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.", "updateAuthor": { "name": "ahutton", "key": "ahutton", "displayName": "Alan Hutton", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2020-01-10T18:05:30.000+0000", "updated": "2020-01-10T18:05:30.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }