Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite triggers in Android?

Tags:

android

sqlite

I want to force a foreign key constarint on a table in an Android application.

I've searched that this can be done by using triggers:

I did it like this:

db.execSQL("CREATE TRIGGER dept_id_trigger22+" +
                " AFTER INSERT "+
                " OF EmployeeName ON Employees"+
                " BEGIN"+
                                     //Condition
                " RAISE(ABORT,'error') END;");

but no error was raised and the illegal values are inserted.

what is wrong with this ?

like image 822
Mina Wissa Avatar asked Sep 18 '10 21:09

Mina Wissa


1 Answers

Ok I got it

Android supports SQLite triggers.

The correct syntax is

db.execSQL("CREATE TRIGGER dept_id_trigger22" + 
                " AFTER INSERT "+ 
                "ON Employees"+ 
                " BEGIN"+ 
                                     //Condition 
                " SELECT RAISE(ABORT,'error'); END;"); 

I forgot to add semicolon after the raise statement.

This does not execute the statement but it does not throw an exception. still will search for how to throw exceptions

thanks

like image 170
Mina Wissa Avatar answered Sep 18 '22 13:09

Mina Wissa