[TIMOB-15254] Titanium does not handle 64bit integer correctly in Sqlite on iOS
| GitHub Issue | n/a |
|---|---|
| Type | Story |
| Priority | Low |
| Status | Closed |
| Resolution | Done |
| Resolution Date | 2016-06-13T06:30:43.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | iOS |
| Labels | 64bit, ios, sqlite |
| Reporter | James David Low |
| Assignee | Chee Kiat Ng |
| Created | 2013-08-26T11:02:09.000+0000 |
| Updated | 2016-06-13T06:30:43.000+0000 |
Description
If you store a 64bit integer in Sqlite it returns a truncated version when you try to read it back using resultset.field or resultset.fieldByName
This is due to two things:
1) A problem in the underlying pldatabase that the use:
http://code.google.com/p/pldatabase/issues/detail?id=25&thanks=25&ts=1377514140
2) Even if the above problem was fixed Titanium still truncates in TiDatabaseResultSetProxy.m aprox. line #90 in the function transformObject :
result = NUMINT([TiUtils intValue:obj def:NSNotFound valid:&valid]);
There is a work around that requires no modification of the pldatabase library, since if Titanium were to use PLSqliteResultSet->bigIntForColumnIndex it correctly returns a 64bit Objective long long.
Hi James David Low, You can follow [this link](http://stackoverflow.com/questions/9643626/javascript-cant-handle-64-bit-integers-can-it).i think you will know little more about this. Thanks
Hi, This is not a JavaScript precision issue. This is an issue with the ObjectiveC code rounding 64bit integers to 16bit integers. I have managed to get it to work by editing the Objective C code for Titanium to use the PLSqliteResultSet->bigIntForColumnIndex function. Thanks, James
There has been a fix put in the underlying SQL Lite library. If Titanium copy the latest code for the pldatabase it should fix things: https://github.com/plausiblelabs/pldatabase/commit/517d00f9cc34766ef8de0e43bf47ea4599a73452
I believe this is now fixed in PLSqliteResultSet.m in Titanium 5.2.0
- (id) objectForColumnIndex: (int) columnIndex { [self assertNotClosed]; int columnType = [self validateColumnIndex: columnIndex isNullable: YES]; switch (columnType) { case SQLITE_TEXT: return [self stringForColumnIndex: columnIndex]; case SQLITE_INTEGER: return [NSNumber numberWithLongLong:[self bigIntForColumnIndex: columnIndex]]; case SQLITE_FLOAT: return [NSNumber numberWithDouble: [self doubleForColumnIndex: columnIndex]]; case SQLITE_BLOB: return [self dataForColumnIndex: columnIndex]; case SQLITE_NULL: return [NSNull null]; default: [NSException raise: TI_PLDatabaseException format: @"Unhandled SQLite column type %d", columnType]; } /* Unreachable */ abort(); }[~jamesdlow] Thanks for the feedback!