I have been working with Android and SQLite Database to develop an application. But I am having a few problems. This is my 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");
Now the problem is, that in my cursor cursorCategory
I get the data that is stored in the Category
table of my database. But I do not get any data in the cursorTransaction
, why does this happen??
Furthermore, while instantiating my SQLiteHelperMoney2
object, if I change the instantiation of my SQLiteHelperMoney2
object to this :
SQLiteHelperMoney SQLiteHelperMoney2 = new SQLiteHelperMoney(this, "TRANSACTIONS", null, 1);
then I get the data from the Transaction
table, in my cursorTransaction
.
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?
Furthermore, the documentation says that in the constructor for SQLiteOpenHelper, in the field "NAME" you can specify null
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 :
SQLiteHelperMoney SQLiteHelperMoney1 = new SQLiteHelperMoney(this, null, null, 1);
But it works here but not in the other case.
Further, what is the name of database created by default? Because I haven't specified it in my onCreate
function of the SQLiteOpenHelper. And can I change the name of my database??
Aucun commentaire:
Enregistrer un commentaire