I'm creating a database using SQLiteHelper and I keep receiving exceptions when the app tries to run.
This is the error message that I receive : Caused by: android.database.sqlite.SQLiteException: near "Trip": syntax error (code 1): , while compiling: create table Business Trip Expenditure( desc text primary key , Meals integer NOT NULL , Drinks integer NOT NULL , Travel integer NOT NULL , Accommodation integer NOT NULL , Other integer NOT NULL , Receipt_Retained? real NOT NULL , Created_at text NOT NULL );
public class MySQLiteHelper extends SQLiteOpenHelper {
public static final String TABLE_NAME = "Business Trip Expenditure";
//Column Names
public static final String COLUMN_NAME = "desc";
public static final String MEAL_COST ="Meals";
public static final String DRINK_COST = "Drinks";
public static final String TRAVEL_COST = "Travel";
public static final String ACCO_COST = "Accommodation";
public static final String OTHER_COST = "Other";
public static final String HAS_RECEIPT = "Receipt_Retained?";
public static final String CREATED_AT = "Created_at";
private static final String DATABASE_NAME = "task.db";
private static final int DATABASE_VERSION = 1;
// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
+ TABLE_NAME + "( " + COLUMN_NAME + " text primary key , " + MEAL_COST + " integer NOT NULL , " + DRINK_COST + " integer NOT NULL , " + TRAVEL_COST + " integer NOT NULL , " + ACCO_COST + " integer NOT NULL , " + OTHER_COST + " integer NOT NULL , " + HAS_RECEIPT + " real NOT NULL , " + CREATED_AT + " text NOT NULL );";
public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(MySQLiteHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
If anyone could help me with the syntax of the creation of the table it would be much appreciated, I know that this form of code is picky in terms of syntax.
Aucun commentaire:
Enregistrer un commentaire