Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2945] Android: Database - ResultSet.fieldCount property should be ResultSet.fieldCount() method

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionDuplicate
Resolution Date2012-08-29T19:49:06.000+0000
Affected Version/sRelease 1.6.0, Release 1.8.0.1, Release 3.0.0
Fix Version/sn/a
ComponentsAndroid
Labelsparity
ReporterBen
AssigneeNeeraj Gupta
Created2011-04-15T03:33:31.000+0000
Updated2017-03-22T20:38:15.000+0000

Description

The APIDOCs at [Titanium.Database.ResultSet](http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Database.ResultSet-object.html) state that [fieldCount](http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Database.ResultSet.fieldCount-method.html) is a method. While this exists on iOS, Android provides it as a property. Hence, this is a request to remove the property on Android and to replace it with a method. See the following testcase provided by Ketan:
/**
 * Initializes the test environment, creating a simple table "data" that has 150
 * rows in it and just 2 fields
 */
var testRowCount = 150;
var db = Ti.Database.open('data');
db.execute('CREATE TABLE IF NOT EXISTS data (id INTEGER PRIMARY KEY, val TEXT)');
db.execute('DELETE FROM data WHERE 1=1');
for (var i = 1; i <= testRowCount; i++) {
    db.execute('INSERT INTO data (val) VALUES(?)','our value:' + i);
}

/**
 * FIELD COUNT WORKS AS A METHOD AS EXPECTED ON IOS BUT RETURNS ERROR ON ANDROID.
 * EXPECTED RESULT: 2
 *
 * REAL BEHAVIOR IN 1.8.3: ANDROID SAYS: Uncaught TypeError: Property 'fieldCount' of object #<TiResultSet> is not a function
 */
function testFieldCountCrashesOnAndroid() {
    // now select out our data from the database
    var rows = db.execute("SELECT * FROM data");
    var fieldCount = rows.fieldCount();
    Ti.API.info('*** SHOULD WORK ON BOTH iOS & ANDROID ***');
    Ti.API.info('rows.fieldCount() = ' + fieldCount);
}

testFieldCountCrashesOnAndroid();

/**
 * FIELD COUNT WORKS AS A METHOD AS EXPECTED ON IOS BUT RETURNS ERROR ON ANDROID. You will need to comment out line 27 above to test it working on android.
 * EXPECTED RESULT: 2
 * 
 * REAL BEHAVIOR IN 1.8.0.1 RC3: iOS only sees the result set object and no longer gets the field count value, although android now returns the value 2.
 */
function testFieldCountWorksOnAndroid() {
    // now select out our data from the database
    var rows = db.execute("SELECT * FROM data");
    var fieldCount = rows.fieldCount; // Changed to a property not a method call.
    Ti.API.info('*** NOW WORKS ON ANDROID NOT iOS ***');
    Ti.API.info('rows.fieldCount = ' + fieldCount);
}

testFieldCountWorksOnAndroid();

Comments

  1. Marc Kurtz 2011-04-26

    I also have this problem in beta 1.7.0
  2. Mark Henderson 2011-05-16

    I see this using 1.6.2, in iPhone you have to use fieldCount() .fieldCount returns [DatabaseResultSet]
  3. Ketan Majmudar 2011-12-18

    I believe as its a method the correct way of calling it is with Titanium.Database.ResultSet.fieldCount(). However Android thins it is a property and throws up such an error. Treating it as a property returns the result on Android but then does not return a result on iOS. The test case below shows this behaviour and can be replicated. Testing on iOS first shows one it working with one method. Then test on Android, and you will see the error. Thirdly commenting out the first function call then testing on android shows you it working on Android. Test Environment: Host OS: Mac OS X OS Arch: x86 JRE Version: 1.6.0_29 JRE Vendor: Apple Inc. JRE Home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home Install Directory: file:/Applications/Titanium Studio/ Version: 1.0.8.201112161851 SDK 1.8.0.1 RC3 (and since 1.7.x) It is worth noting that I had noticed this problem in passing since Studio 1.6.x it's only now that i've come to a point where its critical for me to use.
       /**
        * Initializes the test environment, creating a simple table "data" that has 150
        * rows in it and just 2 fields
        */
       var testRowCount = 150;
       var db = Ti.Database.open('data');
       db.execute('CREATE TABLE IF NOT EXISTS data (id INTEGER PRIMARY KEY, val TEXT)');
       db.execute('DELETE FROM data WHERE 1=1');
       for (var i = 1; i <= testRowCount; i++) {
           db.execute('INSERT INTO data (val) VALUES(?)','our value:' + i);
       }
       
       /**
        * FIELD COUNT WORKS AS A METHOD AS EXPECTED ON IOS BUT RETURNS ERROR ON ANDROID.
        * EXPECTED RESULT: 2
        *
        * REAL BEHAVIOR IN 1.8.3: ANDROID SAYS: Uncaught TypeError: Property 'fieldCount' of object #<TiResultSet> is not a function
        */
       function testFieldCountCrashesOnAndroid() {
           // now select out our data from the database
           var rows = db.execute("SELECT * FROM data");
           var fieldCount = rows.fieldCount();
           Ti.API.info('*** SHOULD WORK ON BOTH iOS & ANDROID ***');
           Ti.API.info('rows.fieldCount() = ' + fieldCount);
       }
       
       testFieldCountCrashesOnAndroid();
       
       /**
        * FIELD COUNT WORKS AS A METHOD AS EXPECTED ON IOS BUT RETURNS ERROR ON ANDROID. You will need to comment out line 27 above to test it working on android.
        * EXPECTED RESULT: 2
        * 
        * REAL BEHAVIOR IN 1.8.0.1 RC3: iOS only sees the result set object and no longer gets the field count value, although android now returns the value 2.
        */
       function testFieldCountWorksOnAndroid() {
           // now select out our data from the database
           var rows = db.execute("SELECT * FROM data");
           var fieldCount = rows.fieldCount; // Changed to a property not a method call.
           Ti.API.info('*** NOW WORKS ON ANDROID NOT iOS ***');
           Ti.API.info('rows.fieldCount = ' + fieldCount);
       }
       
       testFieldCountWorksOnAndroid();
       
    The only way I see of working with this in production is by using something like this: cols=(Ti.Platform.osname === 'android')?rs.fieldCount:rs.fieldCount() Where rs is a resultSet Object.
  4. Ketan Majmudar 2012-03-08

    It would be very useful if this was resolved, it makes parity difficult to debug, and costs many hours in development, OR make a change to the documentation to state there is a difference between iOS & Android.
  5. summersmile 2012-03-20

    I got this bug either. It waste me weeks to locate the problem! Resovle this , please! If there is any differents between the two platforms , please let the developers know.
  6. Ivan Skugor 2012-04-20

    IMHO, "fieldCount" - a property "getFieldCount" - a method Btw, as a workaround, "fieldCount" can be checked if its a method:
       var fieldCount;
       if (typeof rows.fieldCount == 'function') {
           fieldCount = rows.fieldCount();
       }
       else {
           fieldCount = rows.fieldCount;
       }
       
  7. Junaid Younus 2012-08-29

    Ticket is a duplicate of TIMOB-2328.
  8. Lee Morris 2017-03-22

    Closing ticket as duplicate of the ticket that is mentioned above and has since been closed.

JSON Source