{ "id": "62779", "key": "TIMOB-2147", "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": "11225", "name": "Release 1.5.0", "archived": true, "released": true, "releaseDate": "2010-12-14" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2011-04-17T01:58:14.000+0000", "created": "2011-04-15T03:11:51.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "android", "database", "db", "defect", "patch", "pragma", "resultset", "sqlite" ], "versions": [], "issuelinks": [], "assignee": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2011-04-17T01:58:14.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": "{html}

I'm attempting to upgrade a database table from a prior revision\nof my app by checking if fields are present on a table. To do this,\nI'm using SQLite's PRAGMA statement:

\n
\n  PRAGMA table_info(account)\n
\n

On iOS w/ current git-master code this works fine, as well as\ndirectly hitting databases with 'sqlite3'. However on Android,\nDB.execute() returns null instead of a ResultSet object, so I\ncannot access any of the returned data.

\n

This appears to be because the Android TiDatabaseProxy.java\nassumes that only SELECT statements can ever return data:

\n
\nif(sql.trim().toLowerCase().startsWith(\"select\")) {\n    c = db.rawQuery(sql, newArgs);\n    if (c != null) {\n        rs = new TiResultSetProxy(getTiContext(), c);\n        if (rs.isValidRow()) {\n            rs.next(); // Position on first row if we have data.\n        }\n    } else {\n        rs = new TiResultSetProxy(getTiContext(), null); // because iPhone does it this way.\n    }\n} else {\n    if (args != null) {\n        db.execSQL(sql, args);\n    } else {\n        db.execSQL(sql);\n    }\n}\n
\n

The iPhone implementation on the other hand doesn't make any\nsuch assumption, and ships every query through the same code paths.\nIf the result info from the DB has no columns, then it returns null\ninstead of a ResultSet.

{html}", "attachment": [], "flagged": false, "summary": "Android: PRAGMA and non-SELECT statements return null from Ti.Database.DB.execute() instead of ResultSet", "creator": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "127624", "author": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Quick fix which seems to work for me so far, but I'm not 100%\nsure on it:

\n

http://github.com/brion/titanium_mobile/commits/2147
\n\nhttp://github.com/brion/titanium_mobile/commit/8d3251fca69e10df6a96...

{html}", "updateAuthor": { "name": "brionvibber", "key": "brionvibber", "displayName": "Brion Vibber", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:11:51.000+0000", "updated": "2011-04-15T03:11:51.000+0000" }, { "id": "127625", "author": { "name": "skypanther1", "key": "skypanther1", "displayName": "skypanther", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

I've encountered the same issue. I'm afraid I don't know how to\ntry out your proposed fix, so I'll have to wait till it's\nreleased.

{html}", "updateAuthor": { "name": "skypanther1", "key": "skypanther1", "displayName": "skypanther", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:11:52.000+0000", "updated": "2011-04-15T03:11:52.000+0000" }, { "id": "127626", "author": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

(from [17b01d60fe9c3c8a8b4055c376ba3625e8dc3d29])\n[#2147 state:fixed-in-qa] test:\ndrillbit/tests/tidb/tidb.js#test_database_lh_2147. This one took\nquite awhile because you can't just switch out execSql for rawSql.\nAfter suffering with it for a few hours I remember that raw doesn't\ndo transactions, therefore if you made sure the database was\ndeleted before starting, the database would get created, but the\nTest table would not. If you happened to have another database\naround with the same table you'd get a false positive because the\ndrop table would fail too. So the compromise is detect select and\npragma queries and use rawSql otherwise use exec. \nhttps://github.com/appcelerator/titanium_mobile/commit/17b01d60fe9c...

{html}", "updateAuthor": { "name": "dthorp", "key": "dthorp", "displayName": "Don Thorp", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:11:53.000+0000", "updated": "2011-04-15T03:11:53.000+0000" }, { "id": "127627", "author": { "name": "mschmulen", "key": "mschmulen", "displayName": "Matt Schmulen", "active": true, "timeZone": "America/Los_Angeles" }, "body": "{html}

Resolved Titanium SDK version: 1.5.0 (12/03/10 10:38 33c2058),\nAndroid 1.6/2.1 Emulators, Drillbit.

{html}", "updateAuthor": { "name": "mschmulen", "key": "mschmulen", "displayName": "Matt Schmulen", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2011-04-15T03:11:53.000+0000", "updated": "2011-04-15T03:11:53.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }