lundi 27 avril 2015

Android SQLite Table Syntax Error (Code 1) Again

I posted not too long ago looking for a solution to a syntax error I was having and some one managed to help me with that but it did not solve my problem completely as my syntax is still wrong in the creation of my table. It is strange how ever as my app is running but I still receive the compiling error.

Here is the error I receive: android.database.sqlite.SQLiteException: near "?": 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);

Here is my code:

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 = "trip.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);
    }
}

Again, if anyone could help me solve this, that would be a great help to me and much appreciated. Also sorry for spamming questions.

Aucun commentaire:

Enregistrer un commentaire