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

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

            // TODO assert(hi._h == h)
            return(hi);
        }
Example #3
0
        int ISQLite3Provider.sqlite3_exec(IntPtr db, string sql, delegate_exec func, object user_data, out string errMsg)
        {
            // TODO null string?
            GCHandle pinned = GCHandle.Alloc(util.to_utf8(sql), GCHandleType.Pinned);
            IntPtr   ptr    = pinned.AddrOfPinnedObject();

            int rc;

            byte[]   buf8        = new byte[8];
            GCHandle buf8_pinned = GCHandle.Alloc(buf8, GCHandleType.Pinned);
            IntPtr   buf8_ptr    = buf8_pinned.AddrOfPinnedObject();

            if (func != null)
            {
                exec_hook_info hi   = new exec_hook_info(func, user_data);
                callback_exec  cb   = new callback_exec(exec_hook_bridge);
                GCHandle       h_cb = GCHandle.Alloc(cb);

                rc = SQLite3RuntimeProvider.sqlite3_exec(db.ToInt64(), ptr.ToInt64(), Marshal.GetFunctionPointerForDelegate(cb).ToInt64(), hi.ptr.ToInt64(), buf8_ptr.ToInt64());
                hi.free();
                h_cb.Free();
            }
            else
            {
                rc = SQLite3RuntimeProvider.sqlite3_exec(db.ToInt64(), ptr.ToInt64(), IntPtr.Zero.ToInt64(), IntPtr.Zero.ToInt64(), buf8_ptr.ToInt64());
            }

            IntPtr errmsg_ptr = new IntPtr(Marshal.ReadInt64(buf8_ptr));

            buf8_pinned.Free();

            if (errmsg_ptr == IntPtr.Zero)
            {
                errMsg = null;
            }
            else
            {
                errMsg = util.from_utf8(errmsg_ptr);
                SQLite3RuntimeProvider.sqlite3_free(errmsg_ptr.ToInt64());
            }

            pinned.Free();

            return(rc);
        }
        int ISQLite3Provider.sqlite3_exec (IntPtr db, string sql, delegate_exec func, object user_data, out string errMsg)
        {
            IntPtr errmsg_ptr;
            int rc;

            if (func != null) {
                exec_hook_info hi = new exec_hook_info (func, user_data);
                rc = NativeMethods.sqlite3_exec (db, util.to_utf8 (sql), exec_hook_bridge, hi.ptr, out errmsg_ptr);
                hi.free ();
            } else {
                rc = NativeMethods.sqlite3_exec (db, util.to_utf8 (sql), null, IntPtr.Zero, out errmsg_ptr);
            }

            if (errmsg_ptr == IntPtr.Zero) {
                errMsg = null;
            } else {
                errMsg = util.from_utf8 (errmsg_ptr);
                NativeMethods.sqlite3_free (errmsg_ptr);
            }

            return rc;
        }
Example #5
0
        static int exec_hook_bridge(IntPtr p, int n, IntPtr values_ptr, IntPtr names_ptr)
        {
            exec_hook_info hi = exec_hook_info.from_ptr(p);

            return(hi.call(n, values_ptr, names_ptr));
        }
        int ISQLite3Provider.sqlite3_exec(IntPtr db, string sql, delegate_exec func, object user_data, out string errMsg)
        {
            // TODO null string?
            GCHandle pinned = GCHandle.Alloc(util.to_utf8(sql), GCHandleType.Pinned);
            IntPtr ptr = pinned.AddrOfPinnedObject();

            int rc;

            byte[] buf8 = new byte[8];
            GCHandle buf8_pinned = GCHandle.Alloc(buf8, GCHandleType.Pinned);
            IntPtr buf8_ptr = buf8_pinned.AddrOfPinnedObject();

            if (func != null)
            {
                exec_hook_info hi = new exec_hook_info(func, user_data);
                callback_exec cb = new callback_exec(exec_hook_bridge);
                GCHandle h_cb = GCHandle.Alloc(cb);

                rc = SQLite3RuntimeProvider.sqlite3_exec(db.ToInt64(), ptr.ToInt64(), Marshal.GetFunctionPointerForDelegate(cb).ToInt64(), hi.ptr.ToInt64(), buf8_ptr.ToInt64());
                hi.free();
                h_cb.Free();
            }
            else
            {
                rc = SQLite3RuntimeProvider.sqlite3_exec(db.ToInt64(), ptr.ToInt64(), IntPtr.Zero.ToInt64(), IntPtr.Zero.ToInt64(), buf8_ptr.ToInt64());
            }

            IntPtr errmsg_ptr = new IntPtr(Marshal.ReadInt64(buf8_ptr));
            buf8_pinned.Free();

            if (errmsg_ptr == IntPtr.Zero)
            {
                errMsg = null;
            }
            else
            {
                errMsg = util.from_utf8(errmsg_ptr);
                SQLite3RuntimeProvider.sqlite3_free(errmsg_ptr.ToInt64());
            }

            pinned.Free();

            return rc;
        }