Question

I'm trying to add a second table to my application but I'm not having any luck. The two tables are their own classes and are singletons. I pass in a reference of the database in the onUpgrade method and again as an instance variable.

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    transTable = TransactionTable.getInstance(db);
    sysTable = SystemTable.getInstance(db);

    onCreate( db );

    transTable.updateTable();
    sysTable.updateTable();
}

The onCreate method just calls the create methods in all the tables.

@Override
public void onCreate(SQLiteDatabase db) {
    transTable.createTable();
    sysTable.createTable();
}

The second table, sysTable, doesn't throw and exception while executing the following create statement.

public void createTable() {
    db.rawQuery("CREATE TABLE IF NOT EXISTS " + tableName + " ("
            + "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + lastUsed
            + " INTEGER, " + balance + " INTEGER, " + accountName
            + " TEXT, UNIQUE ( " + accountName + " ) )", null);
}

But, when I run a simple query such as the following:

 db.rawQuery("select * from " + tableName, null);

I get an error stating

 android.database.sqlite.SQLiteException: no such table: system_t: , 
 while compiling: select * from system_t

There is no issue with the first table being dropped or created. Any ideas?

Was it helpful?

Solution

change createTable method the code:

 db.rawQuery

to

db.execSQL()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top