【问题标题】:Sqlite - No Such Column Error while deleting table from sqlite_sequenceSqlite - 从 sqlite_sequence 删除表时没有这样的列错误
【发布时间】:2014-09-11 10:32:47
【问题描述】:

我正在尝试清除具有自动增量键的表。

我正在尝试执行以下操作,但遇到异常。

protected void clearSqliteSequenceTable(String table) {
        String query = "delete from sqlite_sequence where name = business";
        mDb.execSQL(query);
    }

表名是business。我得到以下没有此类列业务异常。

09-11 15:53:33.709: E/AndroidRuntime(20204): FATAL EXCEPTION: main
09-11 15:53:33.709: E/AndroidRuntime(20204): Process: com.xx.xxx, PID: 20204
09-11 15:53:33.709: E/AndroidRuntime(20204): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xx.xxx/com.xx.xxx.SplashActivity}: android.database.sqlite.SQLiteException: no such column: business (code 1): , while compiling: delete from sqlite_sequence where name = business
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.os.Handler.dispatchMessage(Handler.java:102)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.os.Looper.loop(Looper.java:136)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.app.ActivityThread.main(ActivityThread.java:5001)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at java.lang.reflect.Method.invokeNative(Native Method)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at java.lang.reflect.Method.invoke(Method.java:515)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at dalvik.system.NativeStart.main(Native Method)
09-11 15:53:33.709: E/AndroidRuntime(20204): Caused by: android.database.sqlite.SQLiteException: no such column: business (code 1): , while compiling: delete from sqlite_sequence where name = business
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1672)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1603)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at com.xx.xxx.database.BaseDbAdapter.clearSqliteSequenceTable(BaseDbAdapter.java:65)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at com.xx.xxx.database.adapters.BusinessDbAdapter.clearSqliteSequenceTable(BusinessDbAdapter.java:149)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at com.xx.xxx.SplashActivity.insertDummyData(SplashActivity.java:79)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at com.xx.xxx.SplashActivity.onCreate(SplashActivity.java:51)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.app.Activity.performCreate(Activity.java:5231)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-11 15:53:33.709: E/AndroidRuntime(20204):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
09-11 15:53:33.709: E/AndroidRuntime(20204):    ... 11 more

【问题讨论】:

    标签: android sqlite


    【解决方案1】:

    你的“where”语句

     name = business
    

    尝试从表sqlite_sequence 中删除name 列等于假设的business 列。如果您尝试从名称列包含“业务”的sqlite_sequence 中删除,请尝试

    String query = "DELETE FROM sqlite_sequence WHERE name = 'business'";
    

    【讨论】:

    • 双引号在哪里结束?
    【解决方案2】:

    只需修改您的查询

    来自

    String query = "delete from sqlite_sequence where name = business";
    

    String query = "delete from sqlite_sequence where name = \'business\' ";
    

    我已经尝试过它的工作正常:-)

    【讨论】:

    • 您可以通过包含引号来修改您的答案吗?我的意思是字符串查询 = "";我对如何使用商业报价感到困惑
    【解决方案3】:

    试试这个

    protected void clearSqliteSequenceTable(String table) {
        String query = "delete from " + table;
        mDb.execSQL(query);
    }
    

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 2015-09-07
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      • 2016-11-18
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多