samedi 26 septembre 2015

Android SQLite - creating two tables at once

I am trying to create two SLite tables at once in onCreate(SQLiteDatabase database) function in object extending SQLiteOpenHelper but it stops during first creation of table DB object(it work fine when I comment out the second query)

This is my onCreate function:

@Override
public void onCreate(SQLiteDatabase database) {
    String query = "CREATE TABLE users ( userID INTEGER PRIMARY KEY, login TEXT, password TEXT, name TEXT, "
            + "phone TEXT, country TEXT, balance TEXT)";

    String query2 = "CREATE TABLE transactions ( transactionID INTEGER PRIMARY KEY, "
            + "from TEXT, to TEXT, amount TEXT, title TEXT)";

    database.execSQL(query);
    database.execSQL(query2);
}

I've also tried to put this in one query like this:

String query = "CREATE TABLE users ( userID INTEGER PRIMARY KEY, login TEXT, password TEXT, name TEXT, "
                + "phone TEXT, country TEXT, balance TEXT) CREATE TABLE transactions ( transactionID INTEGER PRIMARY KEY, "
                + "from TEXT, to TEXT, amount TEXT, title TEXT)";

then it works but stops my app when I want to get data from transactions table (users table works fine though)

What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire