SQLite语法错误

时间:2015-04-11 11:46:24

标签: android sqlite

不断收到此错误E / SQLiteLog:(1)near" stationId":语法错误

  String createReviewTable = "CREATE TABLE " + TABLE_NAME + " (" + STATION_ID + " VARCHAR," +
            "" + STATION_NAME + " VARCHAR," + STATION_LOCATION + " VARCHAR," +
            "" + STATION_TYPE + " VARCHAR," + STATION_COUNTY + " VARCHAR," +
            "" + WIFI_REVIEW + " VARCHAR," +
            "" + TOILET_REVIEWS + " VARCHAR," + TROLLEY_REVIEW + " VARCHAR," +
            "" + LIFT_REVIEW + " VARCHAR," +
            "" + STEP_FREE_REVIEW + " VARCHAR," + TICKET_MACHINE_REVIEW + " VARCHAR" + ")";
    dbm.execSQL(createReviewTable );

    String createRatingsTable= "CREATE TABLE " + RATING_TABLE_NAME + "(" + REVIEW_ID + " " +
            "INTEGER AUTO INCREMENT PRIMARY KEY , " + STATION_ID + " VARCHAR," +
            "" + WIFI_RATING + " INTEGER, " + TOILET_RATING + " INTEGER," +
            "" + TROLLEY_RATING + " INTEGER, " + LIFT_RATING + " INTEGER, " +
            "" + STEP_FREE_RATING + " INTEGER," + TICKET_MACHINE_RATING + " INTEGER," +
            "" + "FOREIGN KEY " + STATION_ID + " REFERENCES review " + STATION_ID + ")";
    dbm.execSQL(createRatingsTable);

1 个答案:

答案 0 :(得分:1)

您错过了stationid字段周围的方括号。供参考:http://www.sqlite.org/foreignkeys.html

更改此

"" + "FOREIGN KEY " + STATION_ID + " REFERENCES review " + STATION_ID + ")";

到这个

"" + "FOREIGN KEY (" + STATION_ID + ") REFERENCES review (" + STATION_ID + "))";