title: SQLiteOpenHelper problems
body: <p>I have been working with Android and SQLite Database to develop an application.
  But I am having a few problems.
  This is my code: </p>
  
  <pre><code>        SQLiteHelperMoney SQLiteHelperMoney1 = new SQLiteHelperMoney(this, null, null, 1);
          SQLiteDatabase database = SQLiteHelperMoney1.getReadableDatabase();
          Cursor cursorCategory = database.query(false, "CATEGORY", null, null, null, null, null, null, null);
  
          SQLiteHelperMoney SQLiteHelperMoney2 = new SQLiteHelperMoney(this, null, null, 1);
          SQLiteDatabase database2 = SQLiteHelperMoney2.getReadableDatabase();
          Cursor cursorTransaction = database2.query(false, "TRANSACTIONS", null, null, null, null, null, null, "10");
  </code></pre>
  
  <p>Now the problem is, that in my cursor <code>cursorCategory</code> I get the data that is stored in the <code>Category</code> table of my database. But I do not get any data in the <code>cursorTransaction</code>, why does this happen??</p>
  
  <p>Furthermore, while instantiating my <code>SQLiteHelperMoney2</code> object, if I change the instantiation of my <code>SQLiteHelperMoney2</code> object to this : </p>
  
  <p><code>SQLiteHelperMoney SQLiteHelperMoney2 = new SQLiteHelperMoney(this, "TRANSACTIONS", null, 1);</code></p>
  
  <p>then I get the data from the <code>Transaction</code> table, in my <code>cursorTransaction</code>.</p>
  
  <p>But why does this happen?? According to the documentation, in the constructor of the SQLiteOpenHelper, the second parameter, is the name of the database, not the name of the table. 
  Then why does giving the name of the TABLE, in the field NAME OF DATABASE, gives the correct answer?</p>
  
  <p>Furthermore, the documentation says that in the constructor for SQLiteOpenHelper, in the field "NAME" you can specify <code>null</code> if the database is already in the memory. I was assuming that the database had been created in the app itself, so it will be in memory only, that is why I specify the second parameter as null here :</p>
  
  <p><code>SQLiteHelperMoney SQLiteHelperMoney1 = new SQLiteHelperMoney(this, null, null, 1);</code></p>
  
  <p>But it works here but not in the other case.</p>
  
  <p>Further, what is the name of database created by default? Because I haven't specified it in my <code>onCreate</code> function of the SQLiteOpenHelper. And can I change the name of my database??</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p><code>onCreate</code> method:</p>
  
  <pre><code>@Override
  public void onCreate(SQLiteDatabase db) {
      db.execSQL("CREATE TABLE CATEGORY (_ID INTEGER PRIMARY KEY, NAME TEXT)");
      db.execSQL("CREATE TABLE TRANSACTIONS (_ID INTEGER PRIMARY KEY, AMOUNT INTEGER, CATEGORY TEXT, NOTE TEXT, TIME TEXT, EXPENSE INTEGER)");
      db.execSQL("CREATE TABLE BUDGET (_ID INTEGER PRIMARY KEY, AMOUNT INTEGER, TIME TEXT)");
  
      ContentValues cv = new ContentValues();
      cv.put("NAME", "FOOD");
      db.insert("CATEGORY", null, cv);
      cv.put("NAME", "TRAVEL");
      db.insert("CATEGORY", null, cv);
      cv.put("NAME", "INCOME");/*INCOME*/
      db.insert("CATEGORY", null, cv);
      cv.put("NAME", "TRANSPORTATION");
      db.insert("CATEGORY", null, cv);
      cv.put("NAME", "MOVIE");
      db.insert("CATEGORY", null, cv);
  }
  </code></pre>
  
  <p>@laalto: I read your answer here : <a href="https://stackoverflow.com/questions/21881992/when-is-sqliteopenhelper-oncreate-onupgrade-run">When is SQLiteOpenHelper onCreate() / onUpgrade() run?</a></p>
  
  <p>And I'm a bit confused about the on-disk and in-memory database. In my <code>onCreate</code> method, I add rows in my <code>Category</code> table, because I believed that the onCreate method is only called once in the lifetime of the application, i.e., when it is run the first time, for creating the databases.
  That is why in my <code>onCreate</code> method I add data into my <code>CATEGORY</code> table, because I wanted it to have some initial data.</p>
  
  <p>And I believed when we make substituent calls to <code>getReadableDatabase()</code> and <code>getWritableDatabase()</code> it returns us a copy of the earlier created database for us to work with, or probably a handle to the original database and on completion saves those changes. But, after reading your answer it seems that the <code>onCreate</code> methods are run every time. If they are run everytime where does the data get stored, since we will loose the database when we close it??</p>