SQLite的Andr​​oid中触发?SQLite、Andr、oid

2023-09-07 11:58:22 作者:仰起头不流泪

我要强制对表的外键constarint在Android应用程序。

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:

我这样做是这样的:

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.

什么是错的呢?

推荐答案

好吧,我知道了。

Android支持SQLite的触发器。

Android supports SQLite triggers.

正确的语法是

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

感谢

 
精彩推荐
图片推荐