My table was created with
db.execSQL(
"CREATE TABLE periods (" +
" vehicle_id INTEGER KEY," +
" line_id INTEGER KEY," +
" period_id INTEGER PRIMARY KEY AUTOINCREMENT," +
" line_code STRING," +
" sup_code STRING," +
" start_date INTEGER," +
" end_date INTEGER" +
")"
);
And data was inserted with
ContentValues values = new ContentValues();
values.put("vehicle_id", 1);
values.put("line_id", 2);
values.put("line_code", "0406");
values.put("sup_code", " ");
values.put("start_date", 1);
values.put("end_date", 24);
db.insert("periods", null, values);
But when when I retrieve data with
Cursor cPeriods = db.rawQuery("SELECT * FROM periods WHERE vehicle_id=" + vehicleId, null);
System.err.printf("SQLite: ### Get line_code = \"%s\"\n", cPeriods.getString(3));
The result always be "406"
How to fix this problem? I don't want to do an ugly fix such as put some symbol in front of "0406" before insert and removed it out after retrieved.
STRING
is not a valid SQLite type, so line_code
is using the default type, INTEGER
- try changing your CREATE TABLE
statement to use the TEXT
type in place of STRING
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With