C# 具有用户定义函数的SQLite触发器
我试图创建一个SQLite触发器来调用C#中的函数。更新表中的一列后应调用该函数 该函数定义如下:C# 具有用户定义函数的SQLite触发器,c#,sqlite,triggers,C#,Sqlite,Triggers,我试图创建一个SQLite触发器来调用C#中的函数。更新表中的一列后应调用该函数 该函数定义如下: public class TestingFunction<T1> : SQLiteScalarFunction<T1, string> { public TestingFunction() : base("testing") { } protected override string Execute(T1 arg1, SQLiteConnection
public class TestingFunction<T1> : SQLiteScalarFunction<T1, string>
{
public TestingFunction() : base("testing") { }
protected override string Execute(T1 arg1, SQLiteConnection connection)
{
//.. do some work
}
}
SQLiteConnection sqLiteConnection = new SQLiteConnection(@"Data Source=" + settings.db_source);
sqLiteConnection.Open();
TestingFunction<string> function = new TestingFunction<string>();
sqLiteConnection.RegisterFunction(function);
create trigger trigger1 update of act_cost on tunnels
begin
select testing(db_source);
end;
更新表时,我得到SQLite错误:没有这样的函数:测试。
关于问题可能是什么的任何建议?您的触发器试图到达数据库中名为testing的函数,但显然它不存在。因此,您应该检查数据库的方案中是否存在该函数。尝试手动调用它。如果它不存在,就实现它。我可以用.ExecuteScalar()从代码中调用该函数作为SQLiteCommand,一切正常。但是当我试图从触发器调用它时,它不起作用。触发器和函数在同一个数据库中吗?您是从哪个连接调用触发触发器的
UPDATE
?您完全正确,我正在为更新创建一个新连接。现在它终于起作用了。谢谢你能用有效的代码更新这个吗?