Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database multitables and ICS

I have a code that creates a database with 2 tables in it.

private static final String tablecommandes="CREATE TABLE Commandes (no INTEGER NOT NULL PRIMARY KEY,equipe TEXT NULL,nom TEXT  NULL,adresse TEXT  NULL,ville TEXT  NULL,tel TEXT  NULL,frequence INTEGER NULL,datelastserv TIMESTAMP NULL,priorite INTEGER NULL);";
private static final String tabletravaux="CREATE TABLE Travaux (notrav INTEGER  NOT NULL PRIMARY KEY AUTOINCREMENT, travid TEXT NULL, notravlogiciel INTEGER  NULL, nocom INTEGER  NULL, debut TIMESTAMP  NULL,fin TIMESTAMP  NULL,temps INTEGER  NULL);";
private static final String DATABASE_CREATE = tablecommandes+" "+tabletravaux; 

    @Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
}

When I'm trying to do a query on both tables I get "No such table Travaux"

public Cursor fc() throws SQLException {
Cursor mCursor = database.query(true, "Commandes , Travaux", new String[] {
            Fieldno,FieldNom,FieldAdresse,Fieldville,Fieldtel,Fieldfreq,Fieldlastserv,Fieldequipe},
            "Commande.NoCommande=Travaux.NoCommande",null, null, null, null,null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;

}

This works fine on my HC tablet but not on my ICS one. Any idea?

like image 283
Jim S Avatar asked Jul 02 '26 07:07

Jim S


1 Answers

From the SQLiteDatabase.execSQL() documentation:

Execute a single SQL statement...

So even though your code works on some devices, try breaking your build statements into two commands:

@Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(tablecommandes);
    database.execSQL(tabletravaux);
}
like image 188
Sam Avatar answered Jul 03 '26 19:07

Sam