Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15254] Titanium does not handle 64bit integer correctly in Sqlite on iOS

GitHub Issuen/a
TypeStory
PriorityLow
StatusClosed
ResolutionDone
Resolution Date2016-06-13T06:30:43.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labels64bit, ios, sqlite
ReporterJames David Low
AssigneeChee Kiat Ng
Created2013-08-26T11:02:09.000+0000
Updated2016-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.

Comments

  1. Motiur Rahman 2013-09-17

    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
  2. James David Low 2013-09-17

    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
  3. James David Low 2014-01-02

    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
  4. James David Low 2016-06-13

    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();
       }
       
  5. Chee Kiat Ng 2016-06-13

    [~jamesdlow] Thanks for the feedback!

JSON Source