尝试刷新目录项表..只是一个基本的数据库操作我遇到了一个奇怪的行为
String purgeItems ="DELETE FROM CatalogItems";
String count = "SELECT * FROM CatalogItems";
SQLiteDatabase db = mDb.getWritableDatabase(); // mDb extends SQLiteOpenHelper
db.beginTransaction();
db.rawQuery(purgeItems,null);
db.setTransactionSuccessful();
db.endTransaction();
Cursor c = db.rawQuery(count, null);
Log.e(TAG, "CatalogItems after purge " + String.valueOf(c.getCount()));
返回642:原始表行计数
......!也许我累了^^。它可以与其他表格一起使用..
SQLiteOpenHelper(mDb)创建表代码
private void createTables(SQLiteDatabase db) {
// --- CATALOG ITEMS ---
String catalogItemsTable = "CREATE TABLE CatalogItems (" +
"idCatalogItem INT(11) PRIMARY KEY, " +
"idCatalog INT(11), " +
"idProduct INT(11), " +
"image BLOB, " +
"price FLOAT, " +
"quantity INT(11), " +
"unit VARCHAR(5), " +
"status INT(11), " +
"extras VARCHAR(512) " +
");" ;
db.execSQL(catalogItemsTable);
Log.i(TAG, "table CatalogItems created");
答案 0 :(得分:1)
rawQuery
适用于返回行的查询。而是使用:
db.execSQL(purgeItems);