Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom functions SQLite with Mono

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

and it gives me an error:

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.

like image 803
DeadlyMind Avatar asked Nov 10 '12 22:11

DeadlyMind


1 Answers

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).

This is a limitation on iOS devices, because they don't support JIT compilers.

like image 150
lupus Avatar answered Sep 29 '22 12:09

lupus