2014-09-11 60 views
0

我想清除一個具有自動增量鍵的表。Sqlite - 從sqlite_sequence刪除表時沒有這樣的列錯誤

我想通過我得到一個異常來做到以下幾點。

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

表名是商業。我得到以下沒有這樣的列業務例外。

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 

回答

3

你 「哪裏」 的

name = business 

嘗試語句從表sqlite_sequence其中name列等於一個假設business列刪除。如果您正試圖從sqlite_sequence刪除其中名稱列包含 「生意」,嘗試

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

我在哪裏結束雙引號? – 2014-09-11 10:42:49

+0

對不起,忘了。請看我編輯的答案 – 2014-09-11 10:46:49

1

只需修改您的查詢

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

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

我試過它的工作正常:-)

+0

你可以通過加引號來修改答案嗎?我的意思是字符串查詢=「」;我很困惑如何使用商業報價 – 2014-09-11 10:41:44

0

試試這個

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