示例#1
0
        static void scalar_function_hook_bridge(IntPtr context, int num_args, IntPtr argsptr)
        {
            IntPtr p = new IntPtr(SQLite3RuntimeProvider.sqlite3_user_data(context.ToInt64()));
            scalar_function_hook_info hi = scalar_function_hook_info.from_ptr(p);

            hi.call(context, num_args, argsptr);
        }
示例#2
0
        internal static scalar_function_hook_info from_ptr(IntPtr p)
        {
            GCHandle h = (GCHandle)p;
            scalar_function_hook_info hi = h.Target as scalar_function_hook_info;

            // TODO assert(hi._h == h)
            return(hi);
        }
示例#3
0
        int ISQLite3Provider.sqlite3_create_function(IntPtr db, string name, int nargs, object v, delegate_function_scalar func)
        {
            string key = string.Format("{0}.{1}", nargs, name);

            if (_scalar_functions.ContainsKey(key))
            {
                scalar_function_hook_info hi = _scalar_functions[key];

                // TODO maybe turn off the hook here, for now
                hi.free();

                _scalar_functions.Remove(key);
            }

            GCHandle pinned = GCHandle.Alloc(util.to_utf8(name), GCHandleType.Pinned);
            IntPtr   ptr    = pinned.AddrOfPinnedObject();

            int rc;

            // 1 is SQLITE_UTF8
            if (func != null)
            {
                scalar_function_hook_info hi = new scalar_function_hook_info(func, v);
                rc = SQLite3RuntimeProvider.sqlite3_create_function_v2(db.ToInt64(), ptr.ToInt64(), nargs, 1, hi.ptr.ToInt64(), Marshal.GetFunctionPointerForDelegate(new callback_scalar_function(scalar_function_hook_bridge)).ToInt64(), 0, 0, 0);
                if (rc == 0)
                {
                    _scalar_functions[key] = hi;
                }
            }
            else
            {
                rc = SQLite3RuntimeProvider.sqlite3_create_function_v2(db.ToInt64(), ptr.ToInt64(), nargs, 1, 0, 0, 0, 0, 0);
            }

            pinned.Free();

            return(rc);
        }
        int ISQLite3Provider.sqlite3_create_function (IntPtr db, string name, int nargs, object v, delegate_function_scalar func)
        {
            // the keys for this dictionary are nargs.name, not just the name
            string key = string.Format ("{0}.{1}", nargs, name);
            var info = hooks.getOrCreateFor (db);
            if (info.scalar.ContainsKey (key)) {
                scalar_function_hook_info hi = info.scalar [key];

                // TODO maybe turn off the hook here, for now
                hi.free ();

                info.scalar.Remove (key);
            }

            // 1 is SQLITE_UTF8
            if (func != null) {
                scalar_function_hook_info hi = new scalar_function_hook_info (func, v);
                int rc = NativeMethods.sqlite3_create_function_v2 (db, util.to_utf8 (name), nargs, 1, hi.ptr, scalar_function_hook_bridge, null, null, null);
                if (rc == 0) {
                    info.scalar [key] = hi;
                }
                return rc;
            } else {
                return NativeMethods.sqlite3_create_function_v2 (db, util.to_utf8 (name), nargs, 1, IntPtr.Zero, null, null, null, null);
            }
        }
示例#5
0
        int ISQLite3Provider.sqlite3_create_function(IntPtr db, string name, int nargs, object v, delegate_function_scalar func)
        {
            string key = string.Format("{0}.{1}", nargs, name);
            if (_scalar_functions.ContainsKey(key))
            {
                scalar_function_hook_info hi = _scalar_functions[key];

                // TODO maybe turn off the hook here, for now
                hi.free();

                _scalar_functions.Remove(key);
            }

            // 1 is SQLITE_UTF8
            if (func != null)
            {
                scalar_function_hook_info hi = new scalar_function_hook_info(func, v);
                int rc = NativeMethods.sqlite3_create_function_v2(db, util.to_utf8(name), nargs, 1, hi.ptr, scalar_function_hook_bridge, null, null, null);
                if (rc == 0)
                {
                    _scalar_functions[key] = hi;
                }
                return rc;
            }
            else
            {
                return NativeMethods.sqlite3_create_function_v2(db, util.to_utf8(name), nargs, 1, IntPtr.Zero, null, null, null, null);
            }
        }
        int ISQLite3Provider.sqlite3_create_function(IntPtr db, string name, int nargs, object v, delegate_function_scalar func)
        {
        // the keys for this dictionary are nargs.name, not just the name
            string key = string.Format("{0}.{1}", nargs, name);
		var info = hooks.getOrCreateFor(db);
            if (info.scalar.ContainsKey(key))
            {
                scalar_function_hook_info hi = info.scalar[key];

                // TODO maybe turn off the hook here, for now
                hi.free();

                info.scalar.Remove(key);
            }

            GCHandle pinned = GCHandle.Alloc(util.to_utf8(name), GCHandleType.Pinned);
            IntPtr ptr = pinned.AddrOfPinnedObject();

            int rc;

            // 1 is SQLITE_UTF8
            if (func != null)
            {
                scalar_function_hook_info hi = new scalar_function_hook_info(func, v);
                rc = SQLite3RuntimeProvider.sqlite3_create_function_v2(db.ToInt64(), ptr.ToInt64(), nargs, 1, hi.ptr.ToInt64(), Marshal.GetFunctionPointerForDelegate(scalar_function_hook_bridge).ToInt64(), 0, 0, 0);
                if (rc == 0)
                {
                    info.scalar[key] = hi;
                }
            }
            else
            {
                rc = SQLite3RuntimeProvider.sqlite3_create_function_v2(db.ToInt64(), ptr.ToInt64(), nargs, 1, 0, 0, 0, 0, 0);
            }

            pinned.Free();

            return rc;
        }