我的sql命令中缺少什么?
public class PhoneDal extends SQLiteOpenHelper {
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = Constants.DB_NAME;
public static final String BLOCKED_PHONES_TABLE = "BLOCKED_PHONES_TABLE";
public PhoneDal(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_BLOCKED_PHONES_TABLE =
"CREATE TABLE "+ BLOCKED_PHONES_TABLE +
" ( "+ KEY_ID+" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL DEFAULT 1, "
+ KEY_PHONE+" TEXT, "
+ KEY_IS_BLOCKED+" BIT," +
" UNIQUE "+ KEY_PHONE+" )";
db.execSQL(CREATE_BLOCKED_PHONES_TABLE);
}
,错误是
android.database.sqlite.SQLiteException: near "KEY_PHONE": syntax error (code 1): , while compiling: CREATE TABLE BLOCKED_PHONES_TABLE ( id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL DEFAULT 1, KEY_PHONE TEXT, KEY_IS_BLOCKED BIT, UNIQUE KEY_PHONE )
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
答案 0 :(得分:3)
UNIQUE
列。变化
" UNIQUE "+ KEY_PHONE+" )";
到
" UNIQUE ("+ KEY_PHONE+") )";
答案 1 :(得分:1)
您在定义唯一字段时遇到语法错误
请改用此KEY_PHONE + " TEXT UNIQUE"
sqlite中的列定义: