Following the examples in StackOverflow Create User Defined Functions and sqlite net sqlitefunction not working, I defined a UDF for testing purposes:
[SQLiteFunction(Name = "REGEXP", Arguments = 2, FuncType = FunctionType.Scalar)]
public class FirstUdf : SQLiteFunction
{
public override object Invoke(object[] args)
{
Messages.Notify($"{this.GetType().Name}:Invoke");
return true;
}
}
I try to execute a DataReader with the following function:
private void PerformUdfTest(string funcName)
{
var commandText = $"select Node.* from Node where Node.Labels {funcName} 'testvalue'";
Messages.Notify($"SQL command: '{commandText}'");
using (var command = _connection.CreateCommand())
{
command.CommandText = commandText;
using (var reader = command.ExecuteReader())
{
while (reader.Read())
;
}
}
}
where funcName is the registration name given in the SQLiteFunctionAttribute above.
If the UDF is registered as "REGEXP", everything works and the callback is executed.
But, if I change the registration name to anything else, e.g.
[SQLiteFunction(Name = "MyUdf", Arguments = 2, FuncType = FunctionType.Scalar)]
I get an Exception:
System.Data.SQLite.SQLiteException (0x800007BF): SQL logic error
near "MyUdf": syntax error
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at SQLiteUdf.QueryTest.PerformUdfTest(String funcName)
at SQLiteUdf.QueryTest.PerformQueries()
System.Data.SQLite Version is 1.0.116.0, .NET Version 4.8.
What am I missing here?