Android SQLite表创建失败

时间:2016-01-24 20:42:21

标签: android sqlite android-sqlite

我正在为我的数据库编写测试,现在下面的表没有构建,并且测试失败了,正在构建这个SQL命令:" CREATE TABLE位置(_id INTEGER PRIMARY KEY,location_setting TEXT UNIQUE NOT NULL,city_name TEXT NOT NULL,coord_lat REAL NOT NULL coord_long REAL NOT NULL); &#34 ;.我很确定有一些语法错误但我是android中的新数据库并且老老实实地需要帮助。

创建表:

@Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE " + LocationEntry.TABLE_NAME + " (" +
                LocationEntry._ID + " INTEGER PRIMARY KEY," +
                LocationEntry.COLUMN_LOCATION_SETTING + " TEXT UNIQUE NOT NULL, " +
                LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, " +
                LocationEntry.COLUMN_COORD_LAT + " REAL NOT NULL " +
                LocationEntry.COLUMN_COORD_LONG + " REAL NOT NULL " +
                " );";
    }

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

你需要在这样的每一列之后添加',',只留下最后一列。

    final String SQL_CREATE_LOCATION_TABLE = "CREATE TABLE " + LocationEntry.TABLE_NAME + " (" +
            LocationEntry._ID + " INTEGER PRIMARY KEY," +
            LocationEntry.COLUMN_LOCATION_SETTING + " TEXT UNIQUE NOT NULL, " +
            LocationEntry.COLUMN_CITY_NAME + " TEXT NOT NULL, " +
            LocationEntry.COLUMN_COORD_LAT + " REAL NOT NULL, " +
            LocationEntry.COLUMN_COORD_LONG + " REAL NOT NULL" +
            " );";

答案 1 :(得分:-1)

您可以TEXTUNIQUE一起使用。

更多信息:make text column as unique key

您可以尝试VARCHAR或考虑使用其他实施方案来实现目标。

再见