我正在嘗試創建在其數據庫上使用觸發器的應用程序。每當我嘗試在Android Studio上運行它時,應用程序運行良好,代碼中沒有錯誤。但是當我嘗試在MEmu或Lollipop手機上運行它時,會顯示一些錯誤消息。我試圖修復它,但現在有一條消息,當我試圖在修復後啓動它時。SQLite觸發啓動android應用程序時出錯
了java.lang.RuntimeException:無法啓動活動ComponentInfo {com.dexpensemanager/com.dexpensemanager.Home}:android.database.sqlite.SQLiteException:限定表名不允許在INSERT,UPDATE和DELETE觸發器中的語句(代碼1):,編譯時:CREATE TRIGGER(如果不存在)sumcalc_income當TRANS.type =收入時,爲每行執行TRANS TRANSFER INSERT TRANSFORMAT =收入AND strftime('%Y' - '%m','now','start ')BEGIN插入SUMTRANS.income SELECT SUM(收入)FROM TRANS.amount END; 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2460) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2522) 在android.app.ActivityThread.access $ 800(ActivityThread.java:169) 在android.app.ActivityThread上$ android.os.Looper.loop(Looper.java:194) 在android.app.ActivityThread.main(ActivityThread.java:5546) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:967) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762) 引起:android.database.sqlite.SQLiteException:不允許在觸發器中的INSERT,UPDATE和DELETE語句中使用限定的表名(代碼1 ):,編譯時:如果不存在CREATE TRIGGER sumcalc_income當TRANS.type = income AND strftime('%Y' - '%m','now','month of'')時,爲每行執行插入操作BEGIN insert到SUMTRANS.income SELECT SUM(收入)FROM TRANS.amount END; at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:898) at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:509 ) at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) at android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58) at android.database.sqlite.SQLiteStatement。(SQLiteStatement.java :31) 在android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1704) 在android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1635) 在com.example.connectionDB.DBnTrigger.onCreate (DBnTrigger.java:45) 在android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251) 在android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163) 在com.example.connectionDB.DBnTrigger.getLastIncome(DBnTrigger。的java:459) 在com.dexpensemanager.Home.onCreate(Home.java:61) 在android.app.Activity.performCreate(Activity.java:5975) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java: 1111) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2413) ...... 10多個
,這裏是我的觸發器的代碼我把它從create trigger Reflective
public String insincTrigger() {
String insinc = "CREATE TRIGGER if not exists sumcalc_income "
+ " AFTER INSERT "
+ " ON "+TRANSACTION_TABLE
+ " FOR EACH ROW "
+ " WHEN "
+ " TRANS.type= income "
+ " AND strftime ('%Y'-'%m','now','start of month') "
+ " BEGIN "
+ " insert into SUMTRANS.income "
+ " SELECT SUM(income) FROM TRANS.amount "
+ " END; ";
return insinc;
}
public String insexpTrigger(){
String insexp = "CREATE TRIGGER if not exists sumcalc_expense "
+ " AFTER INSERT "
+ " ON "+TRANSACTION_TABLE
+ " FOR EACH ROW "
+ " WHEN "
+ " TRANS.type= expense "
+ " WHERE strftime ('%Y'-'%m','now','start of month') "
+ " BEGIN "
+ " insert into SUMTRANS.expense "
+ " SELECT SUM(expense) FROM TRANS.amount "
+ " END; ";
return insexp;
}
public String upincTrigger(){
String upinc = "CREATE TRIGGER if not exists usumcalc_income "
+ " AFTER UPDATE "
+ " OF [amount] "
+ " ON "+TRANSACTION_TABLE
+ " FOR EACH ROW "
+ " WHEN "
+ " TRANS.type= income "
+ " WHERE strftime ('%Y'-'%m','now','start of month') "
+ " BEGIN "
+ " UPDATE OR REPLACE "+TRANSACTION_SUM
+ " SET [income] = SELECT SUM(income) from TRANS.amount "
+ " END; ";
return upinc;
}
public String upexpTrigger() {
String upexp = "CREATE TRIGGER if not exists usumcalc_expense "
+ " AFTER UPDATE "
+ " OF [amount] "
+ " ON "+TRANSACTION_TABLE
+ " FOR EACH ROW "
+ " WHEN "
+ " TRANS.type= expense "
+ " WHERE strftime ('%Y'-'%m','now','start of month') "
+ " BEGIN "
+ " UPDATE OR REPLACE "+TRANSACTION_SUM
+ " SET [expense] = SELECT SUM(expense) from TRANS.amount "
+ " END; ";
return upexp;
}
public String delTrigger(){
String del = "CREATE TRIGGER if not exists sumcalc_delete "
+ " AFTER DELETE "
+ " ON "+TRANSACTION_TABLE
+ " FOR EACH ROW "
+ " WHEN "
+ " TRANS.type = income AND expense "
+ " WHERE strftime ('%Y'-'%m','now','start of month') "
+ " BEGIN "
+ " DELETE FROM "+TRANSACTION_SUM
+ " WHERE = SELECT SUM(income AND expense) from TRANS.amount "
+ " END; ";
return del;
}
public String instimeTrigger(){
String instime = "CREATE TRIGGER if not exists sumcalc_instime "
+ " AFTER INSERT "
+ " ON "+TRANSACTION_SUM
+ " FOR EACH ROW "
+ " BEGIN "
+ " insert into SUMTRANS.month "
+ " VALUES ('%Y'-'%m','now','start of month') "
+ " END;";
return instime;
}
public String deltimeTrigger(){
String deltime = "CREATE TRIGGER if not exists sumcalc_instime "
+ " AFTER DELETE "
+ " ON "+TRANSACTION_SUM
+ " FOR EACH ROW "
+ " BEGIN "
+ " DELETE FROM SUMTRANS.month "
+ " END; ";
return deltime;
}
有人能告訴我該怎麼辦?
謝謝。
在這個數據庫中有2個表Transaction_table和sumtrans –