{ "id": "82913", "key": "TIMOB-6239", "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": [ { "id": "14162", "description": "Release 3.1.0", "name": "Release 3.1.0", "archived": true, "released": true, "releaseDate": "2013-04-16" }, { "id": "15274", "description": "2013 Sprint 06 API", "name": "2013 Sprint 06 API", "archived": true, "released": true, "releaseDate": "2013-03-25" }, { "id": "14816", "description": "2013 Sprint 06", "name": "2013 Sprint 06", "archived": true, "released": true, "releaseDate": "2013-03-25" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-06-21T07:02:10.000+0000", "created": "2011-11-18T17:35:05.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "core", "exalture", "module_database", "qe-testadded" ], "versions": [ { "id": "12570", "name": "Release 1.7.5", "archived": true, "released": true, "releaseDate": "2011-11-02" }, { "id": "11331", "description": "", "name": "Release 1.8.0", "archived": true, "released": true, "releaseDate": "2011-10-31" } ], "issuelinks": [], "assignee": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "updated": "2013-06-21T07:02:10.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": "10202", "name": "Android", "description": "Android Platform" } ], "description": "The Docs says that Database.ResultSet.next() returns false if no more results are available.\r\nhttp://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Database.ResultSet.next-method.html\r\n\r\nIt is always undefined for android.\r\nOn iOS it returns true and false.\r\n\r\nStep 1: run the code below\r\nStep 2: click the blue window\r\nStep 3: notice the return value output in the console is always undefined.\r\n\r\n{code}\r\nvar win = Ti.UI.createWindow({\r\n\tbackgroundColor:'blue'\r\n});\r\n\r\nwin.addEventListener('open',function(e){\r\n\tTi.API.info('WIN OPENED');\r\n\tvar db = Ti.Database.open('mydb');\r\n\tdb.execute('DROP TABLE IF EXISTS welcome');\r\n\tdb.execute(\"CREATE TABLE IF NOT EXISTS welcome (title TEXT)\");\r\n\tdb.execute(\"INSERT INTO welcome (title) VALUES (?)\",'one');\r\n\tdb.execute(\"INSERT INTO welcome (title) VALUES (?)\",'two');\r\n\tdb.close();\r\n});\r\n\r\nwin.addEventListener('click',function(e){\r\n\tTi.API.info('CLICKED');\r\n\tvar db = Ti.Database.open('mydb');\r\n\tvar rows = db.execute(\"SELECT title FROM welcome\");\r\n\tif(rows.getRowCount()){\r\n\t\tdo{\r\n\t\t\tTi.API.info(\"##### TITLE: \"+rows.fieldByName('title'));\r\n\t\t\tvar next = rows.next();\r\n\t\t\tTi.API.info('## Next: '+next);\r\n\t\t}while( next );\r\n\t}\r\n\t\r\n\t// Workaround\r\n\t// while( rows.isValidRow() ){\r\n\t\t// Ti.API.info(\"##### TITLE: \"+rows.fieldByName('title'));\r\n\t\t// rows.next();\r\n\t// }\r\n\t\r\n\trows.close();\r\n\tdb.close();\r\n});\r\n\r\nwin.open();\r\n{code}\r\n\r\nh4. Workaround\r\nUse while( rows.isValidRow() ){rows.next()}", "attachment": [], "flagged": false, "summary": "Android: Database.ResultSet.next() returns undefined", "creator": { "name": "jalter", "key": "jalter", "displayName": "Jon Alter", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "jalter", "key": "jalter", "displayName": "Jon Alter", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "TiSDK 1.7.5, 1.8.0.v20111114103905\r\nAndroid LG VS910 4G 2.2.2\r\niOS simulator 4.3", "comment": { "comments": [ { "id": "203025", "author": { "name": "abates_ca", "key": "abates_ca", "displayName": "Andrew Bates", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I ran into this same issue in a situation where I didn't want to loop through everything in the resultset so a while loop wasnt' appropriate. The easiest pattern is to call rows.next() and then test if it's valid with rows.isValidRow() before accessing fields. It requires two method calls to get the same effect on Android as calling if(rows.next()) on iOS but it's an easy workaround.", "updateAuthor": { "name": "abates_ca", "key": "abates_ca", "displayName": "Andrew Bates", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-07-12T14:14:44.000+0000", "updated": "2012-07-12T14:14:44.000+0000" }, { "id": "242574", "author": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "body": "Changed method signature to return boolean and made code changes\r\nhttps://github.com/appcelerator/titanium_mobile/pull/3976\r\n", "updateAuthor": { "name": "sunila", "key": "sunila", "displayName": "Sunila", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2013-03-16T12:20:16.000+0000", "updated": "2013-03-16T12:20:16.000+0000" }, { "id": "246847", "author": { "name": "pmishra", "key": "pmishra", "displayName": "Paras Mishra", "active": true, "timeZone": "Asia/Kolkata" }, "body": "Database.ResultSet.next() returns false in this case, works fine so closing it.\r\n\r\nVerified on:\r\nDevice : Google Nexus 7, Android Version: 4.1\r\nSDK: 3.1.0.v20130409124549\r\nCLI version : 3.1.0-cr\r\nOS : MAC OSX 10.7.5\r\nAppcelerator Studio, build: 3.1.0.201304052347\r\nXCode : 4.5.1\r\n", "updateAuthor": { "name": "pmishra", "key": "pmishra", "displayName": "Paras Mishra", "active": true, "timeZone": "Asia/Kolkata" }, "created": "2013-04-10T11:30:08.000+0000", "updated": "2013-04-10T11:30:08.000+0000" }, { "id": "258948", "author": { "name": "djha", "key": "djha", "displayName": "Dhirendra Jha", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Reopening to update labels\r\n", "updateAuthor": { "name": "djha", "key": "djha", "displayName": "Dhirendra Jha", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-21T07:00:28.000+0000", "updated": "2013-06-21T07:00:28.000+0000" }, { "id": "258949", "author": { "name": "djha", "key": "djha", "displayName": "Dhirendra Jha", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Tested with: \r\nSDK:3.1.2.v20130619101604\r\nAppcelerator Studio: 3.1.1.201306131423\r\nOS: OSX 10.7.5\r\nDevice:iPhone simulator(v 6.0), Google nexus(v 4.0.3)\r\nXcode: 4.6", "updateAuthor": { "name": "djha", "key": "djha", "displayName": "Dhirendra Jha", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-06-21T07:02:10.000+0000", "updated": "2013-06-21T07:02:10.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }