Exemplo n.º 1
0
        internal scalar_function_hook_info(delegate_function_scalar func, object v)
        {
            _func      = func;
            _user_data = v;

            _h = GCHandle.Alloc(this);
        }
Exemplo n.º 2
0
 public function_hook_info(
     delegate_function_scalar func_scalar,
     object user_data
     )
 {
     _func_scalar = func_scalar;
     _user_data   = user_data;
 }
Exemplo n.º 3
0
        public void test_result_errors()
        {
            int code = 10;
            delegate_function_scalar errorcode_func =
                (ctx, user_data, args) => raw.sqlite3_result_error_code(ctx, code);

            delegate_function_scalar toobig_func =
                (ctx, user_data, args) => raw.sqlite3_result_error_toobig(ctx);

            delegate_function_scalar nomem_func =
                (ctx, user_data, args) => raw.sqlite3_result_error_nomem(ctx);

            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.create_function("errorcode", 0, null, errorcode_func);
                db.create_function("toobig", 0, null, toobig_func);
                db.create_function("nomem", 0, null, nomem_func);

                try
                {
                    db.exec("select errorcode();");
                    Assert.Fail("expected exception");
                }
                catch (ugly.sqlite3_exception e)
                {
                    Assert.AreEqual(e.errcode, code);
                }

                try
                {
                    db.exec("select toobig();");
                    Assert.Fail("expected exception");
                }
                catch (ugly.sqlite3_exception e)
                {
                    Assert.AreEqual(e.errcode, raw.SQLITE_TOOBIG);
                }

                try
                {
                    db.exec("select nomem();");
                    Assert.Fail("expected exception");
                }
                catch (ugly.sqlite3_exception e)
                {
                    Assert.AreEqual(e.errcode, raw.SQLITE_NOMEM);
                }
            }
        }
Exemplo n.º 4
0
        public void test_result_zeroblob()
        {
            delegate_function_scalar zeroblob_func =
                (ctx, user_data, args) =>
            {
                int size = raw.sqlite3_value_int(args[0]);
                raw.sqlite3_result_zeroblob(ctx, size);
            };

            using (sqlite3 db = ugly.open(":memory:"))
            {
                db.exec("CREATE TABLE foo (x blob);");
                db.create_function("createblob", 1, null, zeroblob_func);
                db.exec("INSERT INTO foo (x) VALUES(createblob(10));");

                var    rowid = db.last_insert_rowid();
                byte[] blob  = db.query_scalar <byte[]>("SELECT x FROM foo WHERE rowid=" + rowid);
                Assert.AreEqual(blob.Length, 10);
                foreach (var b in blob)
                {
                    Assert.AreEqual(b, 0);
                }
            }
        }
Exemplo n.º 5
0
 int ISQLite3Provider.sqlite3_create_function(IntPtr db, string name, int nargs, object v, delegate_function_scalar func)
 {
     throw new Exception(GRIPE);
 }
Exemplo n.º 6
0
 static public int sqlite3_create_function(sqlite3 db, string name, int nArg, object v, delegate_function_scalar func)
 {
     return(_imp.sqlite3_create_function(db.ptr, name, nArg, v, func));
 }
        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);
            }
        }
Exemplo n.º 8
0
 static public int sqlite3_create_function(sqlite3 db, string name, int nArg, object v, delegate_function_scalar func)
 {
     return _imp.sqlite3_create_function(db.ptr, name, nArg, v, func);
 }
Exemplo n.º 9
0
        public static void create_function(this sqlite3 db, string name, int nargs, object v, delegate_function_scalar f)
        {
            int rc = raw.sqlite3_create_function(db, name, nargs, v, f);

            check_ok(rc);
        }
Exemplo n.º 10
0
        internal scalar_function_hook_info(delegate_function_scalar func, object v)
        {
            _func = func;
            _user_data = v;

            _h = GCHandle.Alloc(this);
        }
Exemplo n.º 11
0
 public int sqlite3_create_function(IntPtr db, string name, int nArg, int flags, object v, delegate_function_scalar func) => throw new NotImplementedException();
Exemplo n.º 12
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);
            }
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
        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;
        }
Exemplo n.º 15
0
        int ISQLite3Provider.sqlite3_create_function(IntPtr db, string name, int nargs, object v, delegate_function_scalar func)
        {
	    throw new Exception(GRIPE);
        }
Exemplo n.º 16
0
 internal void free()
 {
     _func      = null;
     _user_data = null;
     _h.Free();
 }
Exemplo n.º 17
0
 internal void free()
 {
     _func = null;
     _user_data = null;
     _h.Free();
 }