create语句出错 - SQLiteException near" limit"

时间:2015-03-15 21:36:12

标签: android sqlite

我正在创建一个可在我的Android应用中使用的数据库。

public class DBhelper
    extends SQLiteOpenHelper {

    public DBhelper(Context context) {
        super(context, DBNAME, null, 1);
    }

    public static String create = "Create table " + TBNAME + "(" + ID + " Integer Primary Key Autoincrement," +
        NAME + " text, " +
        TYPE + " text, " +
        LIMIT + " text, " +
        LOCK_TIME + " text);";

    public void details(String name, String limit, String lock_time) {
        SQLiteDatabase db = getWritableDatabase();
        //everythingz correct!
        db.execSQL("Update " + TBNAME + " set limit='" + limit + "', lock_time='" + lock_time + "' where appname='" + name + "';");
    }
}

但是我的一个列名称出现了语法错误。

03-15 17:09:55.636: E/AndroidRuntime(29455): Caused by: android.database.sqlite.SQLiteException: near "limit": syntax error (code 1): , while compiling: Create table tb1(_id Integer Primary Key Autoincrement,appname text, locktype text, limit text, lock_time text);
03-15 17:09:55.636: E/AndroidRuntime(29455):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
03-15 17:09:55.636: E/AndroidRuntime(29455):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
03-15 17:09:55.636: E/AndroidRuntime(29455):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
03-15 17:09:55.636: E/AndroidRuntime(29455):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
03-15 17:09:55.636: E/AndroidRuntime(29455):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
03-15 17:09:55.636: E/AndroidRuntime(29455):    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)

1 个答案:

答案 0 :(得分:3)

查看您的查询和您的Exception消息,“limit”是一个SQLite关键字,用于限制SELECT语句返回的数据量。这就是你得到一个例外的原因。它与您的列名冲突。例如,将列名更改为mylimit,它将起作用。