Exemple #1
0
        internal override void CreateFunction(string strFunction, int nArgs, bool needCollSeq, SQLiteCallback func, SQLiteCallback funcstep, SQLiteFinalCallback funcfinal)
        {
            int n;

#if MONOTOUCH
            var data = new FunctionData();
            data.Func      = func;
            data.FuncStep  = funcstep;
            data.FuncFinal = funcfinal;
            SQLiteCallback      func_callback      = func == null ? null : new SQLiteCallback(scalar_callback);
            SQLiteCallback      funcstep_callback  = funcstep == null ? null : new SQLiteCallback(step_callback);
            SQLiteFinalCallback funcfinal_callback = funcfinal == null ? null : new SQLiteFinalCallback(final_callback);

            IntPtr user_data;
            user_data = GCHandle.ToIntPtr(GCHandle.Alloc(data));
            n         = UnsafeNativeMethods.sqlite3_create_function_v2(_sql, ToUTF8(strFunction), nArgs, 4, user_data, func_callback, funcstep_callback, funcfinal_callback, destroy_callback);

            if (n == 0)
            {
                // sqlite3_create_function_v2 will call 'destroy_callback' if it fails, so we need to recreate the gchandle here.
                user_data = GCHandle.ToIntPtr(GCHandle.Alloc(data));
                n         = UnsafeNativeMethods.sqlite3_create_function_v2(_sql, ToUTF8(strFunction), nArgs, 1, user_data, func_callback, funcstep_callback, funcfinal_callback, destroy_callback);
            }
#elif !SQLITE_STANDARD
            n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0);
            if (n == 0)
            {
                n = UnsafeNativeMethods.sqlite3_create_function_interop(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal, (needCollSeq == true) ? 1 : 0);
            }
#else
            n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 4, IntPtr.Zero, func, funcstep, funcfinal);
            if (n == 0)
            {
                n = UnsafeNativeMethods.sqlite3_create_function(_sql, ToUTF8(strFunction), nArgs, 1, IntPtr.Zero, func, funcstep, funcfinal);
            }
#endif
            if (n > 0)
            {
                throw new SqliteException(n, SQLiteLastError());
            }
        }