Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3050] iOS: bug in typecasting of big integers from the database

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-12-08T22:37:53.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sRelease 4.0.0
ComponentsiOS
Labelscore, qe-testadded
ReporterMick Staugaard
AssigneeIngo Muschenetz
Created2011-04-15T03:35:32.000+0000
Updated2015-01-20T21:16:03.000+0000

Description

I just discovered a bug in the database code, in that it does not properly typecast big integers coming from the database. Running this code:
var db = Titanium.Database.open('bigint_test');
db.execute("DROP TABLE test")
db.execute("CREATE TABLE test (val1 BIGINT, val2 BIGINT)");
db.execute("DELETE FROM test");
db.execute("INSERT INTO test (val1, val2) VALUES (1, 1296802544867)");
 
Titanium.API.info(1296802544867);
Titanium.API.info(db.execute("SELECT * FROM test").field(0));
Titanium.API.info(db.execute("SELECT * FROM test").field(1));

var table_info = db.execute("PRAGMA table_info(test)")
for (var i=0; i < table_info.fieldCount(); i++) {
  Titanium.API.info(table_info.fieldName(i) + ": " + table_info.field(i));
};
produces this log:
[INFO] 1296802544867
[INFO] 1
[INFO] -277578525
[INFO] cid: 0
[INFO] name: val1
[INFO] type: BIGINT
[INFO] notnull: 0
[INFO] dflt_value: null
[INFO] pk: 0
So you can see that the last log line is wrong it should be 1296802544867. Looking at the .sql file from the iPhone Simulator, I can tell you that the right value is stored in the db, and that other sqlite clients give the right value back.

Comments

  1. Paul Dowsett 2011-06-10

    A user in the Q&A has suggested [this](http://developer.appcelerator.com/question/120826/sqlite-integer-storage-issue-on-iphone) workaround.
  2. Stephen Tramer 2012-07-26

    Tested SDK 2.2.0.014b86f, valid Core issue because resolution will likely involve changing the way we represent ints and floats being transferred between the interpreter and the internals.
  3. Lucas 2014-10-09

    Its still happening in release 3.4.0, its a critical bug, because my app running perfect on Android and now when us merge with IOS build, thats crash because this. Please Fix IT!
  4. Rudolf Cardinal 2014-10-18

    This is not "medium", this is critical; Titanium is corrupting user data. (In my case it prevents the storage of 10-digit patient identifiers.) Similar code to generate:
       var DBNAME = "junk.db",
           TESTVAL = 9876543210, // big enough to cause the bug
           db = Titanium.Database.open(DBNAME),
           cursor,
           x;
       
       db.execute("DROP TABLE IF EXISTS t"); // so we can run this more than once
       db.execute("CREATE TABLE t (bignum INTEGER)");
       db.execute("INSERT INTO t (bignum) VALUES (?)", TESTVAL);
       // Check the database using the SQLite command line. Confirms: 9876543210.
       cursor = db.execute("SELECT bignum FROM t");
       x = cursor.field(0);
       if (x === TESTVAL) {
           Titanium.API.debug("happy");
       } else {
           Titanium.API.debug("oh dear; Titanium bug; x is now " + x);
       }
       // Check the database using the SQLite command line. Confirms: 9876543210.
       
  5. Jon Alter 2014-11-10

    We believe this is fixed in recent CI builds of the Titanium SDK. Please test on iOS against versions 3.4.2 and 3.5.0
  6. Rudolf Cardinal 2014-11-27

    Thanks - sorry, what's the URL for the 3.4.2 SDK package for Studio installation? I can't find it in the list at http://builds.appcelerator.com.s3.amazonaws.com/index.html
  7. Ingo Muschenetz 2014-11-27

    Use 3.5.X...that's the new name for the same thing (we switched versions).
  8. Rudolf Cardinal 2014-11-27

    Thanks! The bug looks like it's fixed in Titanium SDK 3.5.0 alpha (installed today, running under iOS 8.1 simulator under OS/X).
  9. Ingo Muschenetz 2014-12-08

    Resolving based on customer feedback.
  10. Ewan Harris 2015-01-20

    Verified fix on: Mac OSX 10.10.1 Appcelerator Studio, build: 3.4.1.201410281743 Titanium SDK build: 3.6.0.v20150120113941 Titanium CLI, build: 3.4.1 Alloy: 1.5.1 Xcode 6.1.1 iPhone 6 (8.2b4), iPad Mini 3 (8.1) Using the code provided, big integers are typecast properly and the value is returned as expected. Closing ticket.

JSON Source