[TIMOB-2945] Android: Database - ResultSet.fieldCount property should be ResultSet.fieldCount() method
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2012-08-29T19:49:06.000+0000 |
Affected Version/s | Release 1.6.0, Release 1.8.0.1, Release 3.0.0 |
Fix Version/s | n/a |
Components | Android |
Labels | parity |
Reporter | Ben |
Assignee | Neeraj Gupta |
Created | 2011-04-15T03:33:31.000+0000 |
Updated | 2017-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();
I also have this problem in beta 1.7.0
I see this using 1.6.2, in iPhone you have to use fieldCount() .fieldCount returns [DatabaseResultSet]
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.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.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.
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.
IMHO, "fieldCount" - a property "getFieldCount" - a method Btw, as a workaround, "fieldCount" can be checked if its a method:
Ticket is a duplicate of TIMOB-2328.
Closing ticket as duplicate of the ticket that is mentioned above and has since been closed.