I am getting strange wrong value from an INTEGER column in SQlite3. Here it is
From terminal I executed select satement
sqlite> select userId, email, firstName, lastName, mobilePhone, passWord, signupDate, profilePicture from SCH_USERS where email = '[email protected]';
8|[email protected]|Sujit|Dalai|**5106932562**|yas|2015-02-22 02:05:55 +0000|
The mobilePhone value is 5106932562
Now when I am executing same select statement in IOS I am getting different value
Here it is
NSString * sql = [NSString stringWithFormat:@"select userId, email, firstName, lastName, mobilePhone, passWord, signupDate, profilePicture from SCH_USERS where email = '%@';", email];
NSLog(@"sql: %@", sql);
sqlite3_stmt * selectStatement;
if (sqlite3_prepare_v2(sqlite.database, [sql UTF8String], -1, &selectStatement, NULL) == SQLITE_OK)
while (sqlite3_step(selectStatement) == SQLITE_ROW)
NSNumber *mobilePhone = [NSNumber numberWithInt:sqlite3_column_int(selectStatement, 4)];
NSLog(@"mobile phone %@", mobilePhone);
The result in log is 2015-02-21 18:05:55.171 Appointment Scheduler[40331:7035909] phone: 811965266
It's quite strange. Any help?
Not that strange at all in fact …
4,294,967,296, and that just happens to be
2^32 – so you’re simply experiencing the effects of an integer overflow here.
And that’s were your mistake lies to begin with – storing phone numbers as integers, which they are of course not.
Store phone numbers as what they are – strings.