Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes it take time before SQLite db updates?
    primarykey
    data
    text
    <p>I have a problem with my SQLite db. I store a new entry to the db with:</p> <pre><code>public Long createTest(String name, String lang) { ContentValues initialValues = new ContentValues(); initialValues.put(KEY_TEST_NAME, name); initialValues.put(KEY_TEST_LANGUAGE, lang); initialValues.put(KEY_TEST_TRIED, 0); initialValues.put(KEY_TEST_CORRECT, 0); return mDb.insert(DB_TABLE_TEST, null, initialValues); } </code></pre> <p>But when I try to get the new "test" from the db, I don't get anything..</p> <p>My debug code:</p> <pre><code>long id = mDbHelper.createTest(name, lang); if(id &gt; 0) mId = id; //A new id is returned!! Cursor testInfo = mDbHelper.getTestInfo(mId); startManagingCursor(testInfo); String lang_output = testInfo.getString(testInfo.getColumnIndexOrThrow(DbAdapter.KEY_TEST_LANGUAGE)); Log.i("AddTestDebug", "lang_output = " + lang_output); //lang_output is null </code></pre> <p><code>createTest()</code> returns a new id. But <code>lang_output</code> is <code>null</code>.</p> <p>The strange thing is that in my next activity, I call the exact same method (<code>getTestInfo(mId)</code>) and I get the <code>lang_output</code> to the correct value. I also get the correct value if I hardcode an earlier saved id. (<code>getTestInfo(26)</code>). The previous id is always working..</p> <p>My <code>getTestInfo</code> is</p> <pre><code>public Cursor getTestInfo(long id) throws SQLException { Cursor mCursor = mDb.rawQuery("SELECT test.name, test.lang, COUNT(words._id) AS num " + "FROM words, test " + "WHERE test._id = " + id + " " + "AND test._id = words.test_id", null); if(mCursor != null) { mCursor.moveToFirst(); } return mCursor; } </code></pre> <p>Why isn't the entry correctly returned the first time??</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload