Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5881] Ti API: DB result set: fieldCount is a property on Android, function on iPhone

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-05-02T20:33:12.000+0000
Affected Version/sn/a
Fix Version/s2014 Sprint 09, 2014 Sprint 09 SDK, Release 3.3.0
ComponentsTiAPI
Labelsmodule_api, parity, qe-closed-3.3.0, qe-testadded, tbs-2.1.0
ReporterShawn Lipscomb
AssigneeVishal Duggal
Created2011-09-27T16:25:12.000+0000
Updated2014-05-08T06:52:09.000+0000

Description

resultset.fieldCount on Android and resultset.fieldCount() on iPhone Can we have some parity please? At this point, you'll probably have to support fieldCount as both a function and a property on both platforms, to avoid breaking existing code.

This code will run on iOS, but fail on Android

var win = Ti.UI.createWindow();
win.open();

var db = Titanium.Database.open('mydb');

db.execute('CREATE TABLE IF NOT EXISTS DATABASETEST (ID INTEGER, NAME TEXT)');

db.execute('INSERT INTO DATABASETEST (ID, NAME ) VALUES(?,?)',1,'Name 1');
db.execute('INSERT INTO DATABASETEST (ID, NAME ) VALUES(?,?)',2,'Name 2');
db.execute('INSERT INTO DATABASETEST (ID, NAME ) VALUES(?,?)',3,'Name 3');
db.execute('INSERT INTO DATABASETEST (ID, NAME ) VALUES(?,?)',4,'Name 4');

var rows = db.execute('SELECT * FROM DATABASETEST');

Ti.API.info(rows.fieldCount());

rows.close();
db.close();

This code will run on Android, but fail on iOS

var win = Ti.UI.createWindow();
win.open();

var db = Titanium.Database.open('mydb');

db.execute('CREATE TABLE IF NOT EXISTS DATABASETEST (ID INTEGER, NAME TEXT)');

db.execute('INSERT INTO DATABASETEST (ID, NAME ) VALUES(?,?)',1,'Name 1');
db.execute('INSERT INTO DATABASETEST (ID, NAME ) VALUES(?,?)',2,'Name 2');
db.execute('INSERT INTO DATABASETEST (ID, NAME ) VALUES(?,?)',3,'Name 3');
db.execute('INSERT INTO DATABASETEST (ID, NAME ) VALUES(?,?)',4,'Name 4');

var rows = db.execute('SELECT * FROM DATABASETEST');

Ti.API.info(rows.fieldCount);

rows.close();
db.close();
This makes the code harder to write since developers but call a different code depending on the platform they are running. Also, there is a very subtle difference between the two, this makes this kind of error very easy to overlook. There should be a common way (either function or property) to access this information on all platforms.

Comments

  1. Matthew Apperson 2011-10-20

    Thank you for raising this ticket. I am afraid we need all the information listed in the [Jira Ticket Checklist](http://wiki.appcelerator.org/display/guides/Contributing+to+Titanium#ContributingtoTitanium-Summary%3AJiraTicketChecklist) in order to accept a ticket. In this instance, we need a complete code sample showing the issue. Once this ticket is complete, we can move it to the main project. Thank you
  2. Shawn Lipscomb 2011-10-26

    Thanks, Christian, for adding the sample code. Matthew, does this ticket now have what you need?
  3. Matthew Apperson 2011-10-26

    Shawn, We do request that sample code have at least one window to indicate the completeness of the code (that it can be run as a single app.js)
  4. Shawn Lipscomb 2012-02-21

    The description of this ticket is pretty straight forward, even without sample code. In order to supply a true testcase that runs on its own, I'd have to supply a database also, which I can't submit in text. Do you really need anything else to take a look at fieldCount ?
  5. Paul Hamilton 2012-08-05

    would just like to add, resultset.getFieldCount() works for both, though is documented as android only?
  6. Vishal Duggal 2014-05-02

    fieldCount will only be supported as a read only property beginning Release 3.3.0 of the SDK Pull pending https://github.com/appcelerator/titanium_mobile/pull/5657
  7. Shawn Lipscomb 2014-05-02

    Vishal, does that mean that the iOS fieldCount() function is being removed, and that the fieldCount property will exist in both Android and iOS?
  8. Vishal Duggal 2014-05-02

    @[~bitshftr] Yes fieldCount() method has been removed. fieldCount is a read only property now on all supported platforms (ios, android,blackberry). rs.fieldCount - Supported rs.getFieldCount() - Supported rs.fieldCount() - Unsupported
  9. Dhirendra Jha 2014-05-08

    Environment - Appc-Studio:3.3.0.201405011408 sdk:3.3.0.v20140507163312 acs:1.0.14 alloy:1.4.0-dev npm:1.3.2 titanium:3.3.0-dev titanium-code-processor:1.1.1 xcode:5.1.1 Device:Iphone5s(v7.1.1),Nexus7(v4.4.2) Result - fieldCount() method has been removed. fieldCount is a read only property on ios and android. Tested the code with "Ti.API.info(rows.fieldCount)" mentioned above and its working fine. Hence closing this issue.

JSON Source