I'm creating an app which includes data stored in an SQLitedatabase. I use a long as primary key (generated buy the significant bits of an java.util.UUID). I handle the database connection with an extended SQLiteOpenHelper. The query:
INSERT INTO Categorys VALUES('-7311183930966261019', 'Mat', 'Matkonto', '#FFFFFF', '#F23341', '0', '231451', '0', '0', '');
goes through without problem, but when i retrieve the value a lot of the precision in the first value -7311183930966261019, have been lost. The query
SELECT * FROM Categorys WHERE _id='-7311183930966261019';
returns null;
I have tried the same querys in sqlite3 and the command line and not gotten the same problem so i've concluded that the problem is either related to android or my handling along the way.
Update: After correcting the querys i now have:
INSERT INTO Categorys VALUES(-6645129292311215613, 'Sparande', 'Pengar som sparas inför framtiden', '#FFFFFF', '#F23341', '0', '231451', '0', 0, '');
And from the database i get (toString() from my class):
Category: name: Sparande; description: Pengar som sparas inför framtiden; colorLight: #FFFFFF; colorDark: #F23341 _id: -6645129292311215104
The code retrieving data:
public static List<Category> readCategorys(Context context){
TransactionSQLOH helper = new TransactionSQLOH(context, DATABASE_NAME);
SQLiteDatabase db = helper.getReadableDatabase();
Cursor cursor = db.query(CategorySQLOH.TABLE_NAME, CategorySQLOH.COLUMNS, null, null, null, null, null);
List<Category> result = CategorySQLOH.cursorToCategory(cursor);
helper.close();
return result;
}
public static List<Category> cursorToCategory(Cursor cursor){
List<Category> result = new Vector<Category>();
if (cursor == null || cursor.getCount() == 0){
return result;
}
cursor.moveToFirst();
Category c;
do{
long _id = cursor.getLong(cursor.getColumnIndex(CategorySQLOH.COLUMNS[0]));
String name = cursor.getString(cursor.getColumnIndex(CategorySQLOH.COLUMNS[1]));
String description= cursor.getString(cursor.getColumnIndex(CategorySQLOH.COLUMNS[2]));
String colorLight = cursor.getString(cursor.getColumnIndex(CategorySQLOH.COLUMNS[3]));
String colorDark = cursor.getString(cursor.getColumnIndex(CategorySQLOH.COLUMNS[4]));
int destribution = cursor.getInt(cursor.getColumnIndex(CategorySQLOH.COLUMNS[5]));
long categoryGroup = cursor.getLong(cursor.getColumnIndex(CategorySQLOH.COLUMNS[6]));
int intData = cursor.getInt(cursor.getColumnIndex(CategorySQLOH.COLUMNS[7]));
long longData = cursor.getLong(cursor.getColumnIndex(CategorySQLOH.COLUMNS[8]));
String strData = cursor.getString(cursor.getColumnIndex(CategorySQLOH.COLUMNS[9]));
c = new Category(_id, name, description, colorLight, colorDark, destribution, categoryGroup, intData, longData, strData);
result.add(c);
}while(cursor.moveToNext());
return result;
}
Update:
Result of SELECT * FROM Categorys; on the pulled database:
sqlite> SELECT * FROM Categorys;
-6.64512929231122e+18|Sparande|Pengar som sparas inf├Âr framtiden|#FFFFFF|#F2334
1|0|231451.0|0|0.0|
Update:
result of .schema on pulled database.
CREATE TABLE Categorys ( _id REAL PRIMARY KEY, name TEXT NOT NULL, description T
EXT , colorLight TEXT , colorDark TEXT , destribution INTEGER , categoryGroup RE
AL , intData INTEGER , longData REAL , strData TEXT );
CREATE TABLE android_metadata (locale TEXT);