带有 Mono 的自定义函数 SQLite [英] custom functions SQLite with Mono
问题描述
有没有办法使用 Mono 添加 SQLite 自定义函数?(Mono.Data.Sqlite)
is there a way to add SQLite custom function using Mono? (Mono.Data.Sqlite)
我尝试添加返回两个地理位置之间距离的距离函数
I tried to add distance function that returns the distance between two geo locations
[SqliteFunctionAttribute(Name = "distance", Arguments = 4, FuncType = FunctionType.Scalar)]
class SqliteDistance : SqliteFunction
{
public override object Invoke(object[] args)
{
double radius = 6367;
double lat1 = System.Convert.ToDouble(args[0]);
double lng1 = System.Convert.ToDouble(args[1]);
double lat2 = System.Convert.ToDouble(args[2]);
double lng2 = System.Convert.ToDouble(args[3]);
return radius * 2 * Math.Asin( Math.Min(1, Math.Sqrt( ( Math.Pow(Math.Sin((lat2* (Math.PI / 180) - lat1 * (Math.PI / 180) ) / 2.0), 2.0) + Math.Cos(lat1* (Math.PI / 180)) * Math.Cos(lat2* (Math.PI / 180)) * Math.Pow(Math.Sin(( lng2* (Math.PI / 180)-lng1* (Math.PI / 180)) / 2.0), 2.0) ) ) ) );
}
}
它给了我一个错误:
在使用 --aot-only 运行时尝试 JIT 编译方法 '(wrapper native-to-managed) Mono.Data.Sqlite.SqliteFunction:ScalarCallback (intptr,int,intptr)'.有关详细信息,请参阅 http://docs.xamarin.com/ios/about/limitations.
Attempting to JIT compile method '(wrapper native-to-managed) Mono.Data.Sqlite.SqliteFunction:ScalarCallback (intptr,int,intptr)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.
推荐答案
查看报错页面的Reverse Callbacks段:实际中需要对方法应用MonoPInvokeCallbackAttribute属性(并且需要将其设为静态).
Look at the Reverse Callbacks paragraph of the page that the error reports: in practice you need to apply the MonoPInvokeCallbackAttribute attribute to the method (and it needs to be made static).
这是对 iOS 设备的限制,因为它们不支持 JIT 编译器.
This is a limitation on iOS devices, because they don't support JIT compilers.
这篇关于带有 Mono 的自定义函数 SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!