[TIMOB-3050] iOS: bug in typecasting of big integers from the database
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-12-08T22:37:53.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | Release 4.0.0 |
Components | iOS |
Labels | core, qe-testadded |
Reporter | Mick Staugaard |
Assignee | Ingo Muschenetz |
Created | 2011-04-15T03:35:32.000+0000 |
Updated | 2015-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.
A user in the Q&A has suggested [this](http://developer.appcelerator.com/question/120826/sqlite-integer-storage-issue-on-iphone) workaround.
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.
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!
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:
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
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
Use 3.5.X...that's the new name for the same thing (we switched versions).
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).
Resolving based on customer feedback.
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.