Custom SQLite Functions with Mono

Is there a way to add a custom SQLite function using Mono? (Mono.Data.Sqlite)

I tried to add a distance function that returns the distance between two geographic 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) ) ) ) ); } } 

and this gives me an error:

Attempted JIT compilation method (shell controlled in Russian) Mono.Data.Sqlite.SqliteFunction: ScalarCallback (intptr, int, intptr) 'when working with -aot-only. See http://docs.xamarin.com/ios/about/limitations for more details.

+4
source share
1 answer

Take a look at the Callbacks section of the page that reports the error: in practice, you need to apply the MonoPInvokeCallbackAttribute attribute to the method (and you need to make it static).

This is a limitation on iOS devices because they do not support JIT compilers.

+5
source

Source: https://habr.com/ru/post/1445267/


All Articles