Beispiel #1
0
        public static collation_hook_info from_ptr(IntPtr p)
        {
            GCHandle            h  = (GCHandle)p;
            collation_hook_info hi = h.Target as collation_hook_info;

            return(hi);
        }
Beispiel #2
0
        internal static collation_hook_info from_ptr(IntPtr p)
        {
            GCHandle            h  = (GCHandle)p;
            collation_hook_info hi = h.Target as collation_hook_info;

            // TODO assert(hi._h == h)
            return(hi);
        }
Beispiel #3
0
        int ISQLite3Provider.sqlite3_create_collation(IntPtr db, string name, object v, delegate_collation func)
        {
            if (_collation_hooks.ContainsKey(name))
            {
                collation_hook_info hi = _collation_hooks[name];

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

                _collation_hooks.Remove(name);
            }

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

            int rc;

            // 1 is SQLITE_UTF8
            if (func != null)
            {
                collation_hook_info hi = new collation_hook_info(func, v);
                rc = SQLite3RuntimeProvider.sqlite3_create_collation(db.ToInt64(), ptr.ToInt64(), 1, hi.ptr.ToInt64(), Marshal.GetFunctionPointerForDelegate(new callback_collation(collation_hook_bridge)).ToInt64());
                if (rc == 0)
                {
                    _collation_hooks[name] = hi;
                }
            }
            else
            {
                rc = SQLite3RuntimeProvider.sqlite3_create_collation(db.ToInt64(), ptr.ToInt64(), 1, IntPtr.Zero.ToInt64(), IntPtr.Zero.ToInt64());
            }

            pinned.Free();

            return(rc);
        }
        int ISQLite3Provider.sqlite3_create_collation (IntPtr db, string name, object v, delegate_collation func)
        {
            var info = hooks.getOrCreateFor (db);
            if (info.collation.ContainsKey (name)) {
                collation_hook_info hi = info.collation [name];

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

                info.collation.Remove (name);
            }

            // 1 is SQLITE_UTF8
            if (func != null) {
                collation_hook_info hi = new collation_hook_info (func, v);
                int rc = NativeMethods.sqlite3_create_collation (db, util.to_utf8 (name), 1, hi.ptr, collation_hook_bridge);
                if (rc == 0) {
                    info.collation [name] = hi;
                }
                return rc;
            } else {
                return NativeMethods.sqlite3_create_collation (db, util.to_utf8 (name), 1, IntPtr.Zero, null);
            }
        }
Beispiel #5
0
        static int collation_hook_bridge(IntPtr p, int len1, IntPtr pv1, int len2, IntPtr pv2)
        {
            collation_hook_info hi = collation_hook_info.from_ptr(p);

            return(hi.call(util.from_utf8(pv1, len1), util.from_utf8(pv2, len2)));
        }
        int ISQLite3Provider.sqlite3_create_collation(IntPtr db, string name, object v, delegate_collation func)
        {
		var info = hooks.getOrCreateFor(db);
            if (info.collation.ContainsKey(name))
            {
                collation_hook_info hi = info.collation[name];

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

                info.collation.Remove(name);
            }

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

            int rc;

            // 1 is SQLITE_UTF8
            if (func != null)
            {
                collation_hook_info hi = new collation_hook_info(func, v);
                rc = SQLite3RuntimeProvider.sqlite3_create_collation(db.ToInt64(), ptr.ToInt64(), 1, hi.ptr.ToInt64(), Marshal.GetFunctionPointerForDelegate(collation_hook_bridge).ToInt64());
                if (rc == 0)
                {
                    info.collation[name] = hi;
                }
            }
            else
            {
                rc = SQLite3RuntimeProvider.sqlite3_create_collation(db.ToInt64(), ptr.ToInt64(), 1, IntPtr.Zero.ToInt64(), IntPtr.Zero.ToInt64());
            }

            pinned.Free();

            return rc;
        }