sql - Triggers on sqlite android does not work -
the goal of trigger insert new record in table column giorni_sett date when update or insert value greater 1 in table shifts column shift, can not run trigger, wrong not know , log have no errors, trigger not work, can me, thank you.
public class dbhelper extends sqliteopenhelper { static string database_name="turnidb.db"; public static final string turni="turni"; public static final string turni_id="idturno"; public static final string turno="turno"; public static final string giorni_sett="giorni"; public static final string giorni_id="giorni_id"; public static final string giorni="giorni"; public static final string data="data"; public dbhelper(context context) { super(context, database_name, null, 1); } @override public void oncreate(sqlitedatabase db) { string create_table="create table "+turni+" ("+turni_id+" integer primary key autoincrement,"+turno+" text)"; db.execsql(create_table); string create_table2="create table "+giorni_sett+" ("+giorni_id+" integer primary key autoincrement,"+giorni+" text,"+data+" integer)"; db.execsql(create_table2); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { db.execsql("create trigger if not exists aggiungi_data after update on turni each row when (new.turno > 0) "); db.execsql(" begin "); db.execsql("insert giorni_sett (data) values (1);"); db.execsql("end;"); db.execsql("drop trigger aggiungi_data;"); db.execsql("drop table if exists "+turni); db.execsql("drop table if exists "+giorni_sett); oncreate(db); } public static void begintransaction() { // todo auto-generated method stub } public static long insert(string string, object object, contentvalues values) { // todo auto-generated method stub return 0; }
}
your create trigger query should in oncreate
after creation of 2 tables, , should like:
db.execsql("create trigger if not exists aggiungi_data after update on " + turni + " each row when (new.turno > 0) begin insert " + giorni_sett + " (data) values (1); end");
Comments
Post a Comment