自定义函数的SQLite使用Mono(custom functions SQLite with Mo

2019-07-03 17:57发布

有没有办法使用单声道添加SQLite的自定义函数? (Mono.Data.Sqlite)

我想补充一点,返回两个地理地点之间的距离距离函数

    [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) ) ) ) ); 
        }
    }

它给我一个错误:

试图JIT编译方法“(包装机设备到管理)Mono.Data.Sqlite.SqliteFunction:ScalarCallback(IntPtr的,INT,IntPtr的)”,而与--aot只运行。 见http://docs.xamarin.com/ios/about/limitations以获取更多信息。

Answer 1:

看那个错误报告页面的反向回调段:在实践中,你需要应用MonoPInvokeCallbackAttribute属性的方法(和它需要进行静态)。

这是在iOS设备上的限制,因为它们不支持的JIT编译器。



文章来源: custom functions SQLite with Mono