I created sqlite database and i use ContentValues to insert records into it from a file, the file contains 689 lines which means i will insert 689 records into the databse i created.
the problem i am facing is, despite i initially delete all the records from the databse, each time i call the "populate()" method posted belwo i receive "total rows: 0" as shown in the output below, but the inserted rowid never starts from 0 as shown below in the output.
in other words, assume i insert 10 records to a databse table, initially it will contain 10 records and the first and last rowid will be 1 and 10 respectively. and when i delete all the rows from the databse and insert another 10 records, the rowid of the first and last row will be 11 and 19 respectively and i think, the rowid of the first and last row should be 1 and 9 respectively
please let me know why that is happening and how to solve it
code:
public void populate(Context context, File file, SQLiteHelper sqliteHelper) {
this.mCtx = context;
this.mSQLiteHelper = sqliteHelper;
this.mSQLiteHelper.deleteALLRows();
Log.i(TAG, "total rows: " + this.mSQLiteHelper.getTotalRowsInDB());//return 0 rows..which is understandable
..
..
..
..
..
try {
while ( (line = this.mBR.readLine()) != null ) {
Log.v(TAG, "line: " + line);
params = line.split(",");
cv.put(this.mCtx.getResources().getString(R.string.cv_col1), params[0]);
cv.put(this.mCtx.getResources().getString(R.string.cv_col2), params[1]);
cv.put(this.mCtx.getResources().getString(R.string.cv_col3), params[2]);
cv.put(this.mCtx.getResources().getString(R.string.cv_col4), params[3]);
if (!wdb.isOpen()) {
Log.w(TAG, "wdb will be opened");
wdb = this.mSQLiteHelper.getWritableDatabase();
}
rowId = wdb.insert(this.mCtx.getResources().getString(R.string.str_sqlite_table_name), null, cv);
if (rowId != -1) {
Log.v(TAG, "row inserted correctly. rowid: " + rowId);
} else {
Log.v(TAG, "row insertion error");
}
Log.d(TAG, "params[0]: " + params[0]);
Log.d(TAG, "params[1]: " + params[1]);
Log.d(TAG, "params[2]: " + params[2]);
Log.d(TAG, "params[3]: " + params[3]);
}
} catch (IOException e) {
e.printStackTrace();
}
output:
02-04 15:07:24.182 27741-27741/com.example.com.myapplication I/Populator: total rows: 0
02-04 15:07:24.182 27741-27741/com.example.com.myapplication V/Populator: line: 163816,49.3478675,8.4643171,120
02-04 15:07:24.212 27741-27741/com.example.com.myapplication V/Populator: row inserted correctly. rowid: 1
02-04 15:07:24.212 27741-27741/com.example.com.myapplication D/Populator: params[0]: 163816
02-04 15:07:24.212 27741-27741/com.example.com.myapplication D/Populator: params[1]: 49.3478675
02-04 15:07:24.212 27741-27741/com.example.com.myapplication D/Populator: params[2]: 8.4643171
02-04 15:07:24.212 27741-27741/com.example.com.myapplication D/Populator: params[3]: 120
02-04 15:07:24.212 27741-27741/com.example.com.myapplication V/Populator: line: 163817,49.3455829,8.467746,120
02-04 15:07:24.212 27741-27741/com.example.com.myapplication V/Populator: row inserted correctly. rowid: 689
02-04 15:07:24.222 27741-27741/com.example.com.myapplication D/Populator: params[0]: 163817
02-04 15:07:24.222 27741-27741/com.example.com.myapplication D/Populator: params[1]: 49.3455829
02-04 15:07:24.222 27741-27741/com.example.com.myapplication D/Populator: params[2]: 8.467746
02-04 15:07:24.222 27741-27741/com.example.com.myapplication D/Populator: params[3]: 120
....
....
....
02-04 15:07:29.972 27741-27741/com.example.com.myapplication V/Populator: line: 456947,49.0559242,8.4985024,120
02-04 15:07:29.982 27741-27741/com.example.com.myapplication V/Populator: row inserted correctly. rowid: 690
02-04 15:07:29.982 27741-27741/com.example.com.myapplication D/Populator: params[0]: 456947
02-04 15:07:29.982 27741-27741/com.example.com.myapplication D/Populator: params[1]: 49.0559242
02-04 15:07:29.982 27741-27741/com.example.com.myapplication D/Populator: params[2]: 8.4985024
02-04 15:07:29.982 27741-27741/com.example.com.myapplication D/Populator: params[3]: 120
Aucun commentaire:
Enregistrer un commentaire