开发者

Android - SQLiteDatabase Not Maintaining Insert

开发者 https://www.devze.com 2023-03-16 02:43 出处:网络
Using adb + sqlite3 (the tool), and querying the database after every action, I have an app that inserts a row into my_conference via:

Using adb + sqlite3 (the tool), and querying the database after every action, I have an app that inserts a row into my_conference via:

ContentValues values = new ContentValues();

      values.put("ITEM_ID", itemId);
      values.put("ITEM_DATE", sessionDate);

      mDb.beginTransaction();
      mDb.insert("my_conference", null, values);
      mDb.setTransactionSuccessful();
      mDb.endTransaction();

I can then query the database and make sure the row is there. Then, when I hit the back button on the device and after the activity returns to the screen before it, I requery the database and it is empty, devoid of the row inserted. I'm not doing anything funny to my DB in onDestroy(), just calling db.close();

What gives?

EDIT: In an attempt to make sure there were no errors, and combining what else I've found by googling, I came up with this, same thing though, inserts, then removes after onDestroy():

ContentValues values = new ContentValues();

      values.put("ITEM_ID", itemId);
      values.put("ITEM_DATE", sessionDate);

      try
      {
        mDb.beginTransaction();
        mDb.insertOrThrow("my_conference", null, values);
        mDb.setTransactionSuccessful();
      }
      catch( 开发者_运维技巧Exception e )
      {
        Log.e("DB", "EXCEPTION: " + e.getMessage() );
      }
      finally
      {
        mDb.endTransaction();
      }


So it turns out I had a bad database exists check, that always thought it didn't exists, so the database was being created anew on each activity load...

0

精彩评论

暂无评论...
验证码 换一张
取 消