2012-07-30 61 views
3

我有一個database與兩個表。最近,我插入一個新行(key_today),我得到以下sqliteexceptioncreate table sentense中的sqlite異常

android.database.sqlite.SQLiteException: near "text": syntax error: create table tasks (_id integer primary key autoincrement, title text not null,location text not null, body text not null , goaldate text not null , absolutedate text not null , currentdate text not null , prio text not null, done text not null, category text not null, timespent text not null, pososto text not null, father text not null, check text not null); 

我已經改變了方法,以包括新行,但我真的不能找到什麼即時通訊做錯了。

這裏是我的代碼,謝謝你提前

public static final String KEY_TITLE = "title"; 
public static final String KEY_BODY = "body"; 
public static final String KEY_ROWID = "_id"; 
public static final String KEY_FATHER="father";//father's id 
public static final String KEY_location = "location"; 
public static final String KEY_GOAL_DATE = "goaldate"; 
public static final String KEY_ABSOLUTE_DATE = "absolutedate"; 
public static final String KEY_DATE_CURRENT = "currentdate"; 
public static final String KEY_PRIO= "prio"; 
public static final String KEY_DONE = "done"; 
public static final String KEY_CATEGORY = "category"; 
public static final String KEY_TIME_SPEND = "timespent"; 
public static final String KEY_POSOSTO = "pososto"; 
public static final String KEY_TODAY= "check"; 

public static final String KEY_STITLE = "atitle"; 
public static final String KEY_ROID = "_id"; 
public static final String KEY_SCOLOR = "color"; 


private static final String TAG = "ListDatabase"; 
/** 
* @uml.property name="mDbHelper" 
* @uml.associationEnd 
*/ 
private DatabaseHelper mDbHelper; 
private SQLiteDatabase mDb; 

/** 
* Creating database tables 
*/ 
private static final String DATABASE_CREATE = 
    "create table tasks (_id integer primary key autoincrement, " 

    + "title text not null," 
    +"location text not null, " 
    + "body text not null , " 
    +" goaldate text not null , " 
    +" absolutedate text not null , " 
    +" currentdate text not null , " 
    +" prio text not null, " 
    +" done text not null, " 
    +" category text not null, " 
    +" timespent text not null, " 
    +" pososto text not null, " 
    +" father text not null, " 
    +" check text not null);"; 

回答

3

這裏是什麼導致了問題:

... check text not null) 
    ^^^^^ 

check是SQLite中的關鍵詞(和SQL一般)。

把它放在這樣的雙引號,以避免這樣的問題:

... "check" text not null) 
+0

非常感謝你!那有用。我永遠也找不到它 – user1347280 2012-07-30 17:22:40