예제 #1
0
 public static void Result_ErrorNoMem(FuncContext fctx)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     MemSetNull(fctx.S);
     fctx.IsError            = RC.NOMEM;
     fctx.S.Ctx.MallocFailed = true;
 }
예제 #2
0
        // The following routines are used by user-defined functions to specify the function result.
        //
        // The setStrOrError() funtion calls sqlite3VdbeMemSetStr() to store the result as a string or blob but if the string or blob is too large, it
        // then sets the error code to SQLITE_TOOBIG

        static void SetResultStrOrError(FuncContext fctx, string z, int o, int n, TEXTENCODE encode, Action del)
        {
            if (Vdbe.MemSetStr(fctx.S, z, o, n, encode, del) == RC.TOOBIG)
            {
                Vdbe.Result_ErrorOverflow(fctx);
            }
        }
예제 #3
0
        public static void InvalidFunction(FuncContext fctx, int notUsed1, Mem[] notUsed2)
        {
            string name = fctx.Func.Name;
            string err  = C._mprintf("unable to use function %s in the requested context", name);

            Result_Error(fctx, err, -1);
            C._free(ref err);
        }
예제 #4
0
 public static void Result_ErrorCode(FuncContext fctx, RC errCode)
 {
     fctx.IsError = errCode;
     if ((fctx.S.Flags & MEM.Null) != 0)
     {
         SetResultStrOrError(fctx, SysEx.ErrStr(errCode), -1, TEXTENCODE.UTF8, DESTRUCTOR_STATIC);
     }
 }
예제 #5
0
        public static object get_Auxdata(FuncContext fctx, int arg)
        {
            Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
            VdbeFunc vdbeFunc = fctx.VdbeFunc;

            if (vdbeFunc == null || arg >= vdbeFunc.AuxsLength || arg < 0)
            {
                return(null);
            }
            return(vdbeFunc.Auxs[arg].Aux);
        }
예제 #6
0
        public static RC MemFinalize(Mem mem, FuncDef func)
        {
            RC rc = RC.OK;

            if (C._ALWAYS(func != null && func.Finalize != null))
            {
                Debug.Assert((mem.Flags & MEM.Null) != 0 || func == mem.u.Def);
                Debug.Assert(mem.Ctx == null || MutexEx.Held(mem.Ctx.Mutex));
                //memset(&ctx, 0, sizeof(ctx));
                FuncContext ctx = new FuncContext();
                ctx.S.Flags = MEM.Null;
                ctx.S.Ctx   = mem.Ctx;
                ctx.Mem     = mem;
                ctx.Func    = func;
                func.Finalize(ctx);              // IMP: R-24505-23230
                Debug.Assert((mem.Flags & MEM.Dyn) == 0 && mem.Del == null);
                C._tagfree(mem.Ctx, ref mem.Z_); //: mem->Malloc);
                ctx.S._memcpy(ref mem);
                rc = ctx.IsError;
            }
            return(rc);
        }
예제 #7
0
        public static void set_Auxdata(FuncContext fctx, int args, object aux, Action delete)
        {
            if (args < 0)
            {
                goto failed;
            }
            Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
            VdbeFunc vdbeFunc = fctx.VdbeFunc;

            if (vdbeFunc == null || vdbeFunc.AuxsLength <= args)
            {
                int auxLength = (vdbeFunc != null ? vdbeFunc.AuxsLength : 0);
                int newSize   = args;
                vdbeFunc = new VdbeFunc();
                if (vdbeFunc == null)
                {
                    goto failed;
                }
                fctx.VdbeFunc            = vdbeFunc;
                vdbeFunc.Auxs[auxLength] = new VdbeFunc.AuxData();
                vdbeFunc.AuxsLength      = args + 1;
                vdbeFunc.Func            = fctx.Func;
            }
            VdbeFunc.AuxData auxData = vdbeFunc.Auxs[args];
            if (auxData.Aux != null && auxData.Aux is IDisposable)
            {
                (auxData.Aux as IDisposable).Dispose();
            }
            auxData.Aux = aux;
            return;

failed:
            if (aux != null && aux is IDisposable)
            {
                (aux as IDisposable).Dispose();
            }
        }
예제 #8
0
        public static Mem Aggregate_Context(FuncContext fctx, int bytes)
        {
            Debug.Assert(fctx != null && fctx.Func != null && fctx.Func.Step != null);
            Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
            Mem mem = fctx.Mem;

            C.ASSERTCOVERAGE(bytes < 0);
            if ((mem.Flags & MEM.Agg) == 0)
            {
                if (bytes <= 0)
                {
                    MemReleaseExternal(mem);
                    mem.Flags = 0;
                    mem.Z     = null;
                }
                else
                {
                    MemGrow(mem, bytes, 0);
                    mem.Flags = MEM.Agg;
                    mem.u.Def = fctx.Func;
                }
            }
            return(Mem.ToMem_(mem));
        }
예제 #9
0
 public static void Result_ZeroBlob(FuncContext fctx, int n)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     MemSetZeroBlob(fctx.S, n);
 }
예제 #10
0
 public static void Result_Double(FuncContext fctx, double val)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     MemSetDouble(fctx.S, val);
 }
예제 #11
0
 public static void Result_Error(FuncContext fctx, string z, int n)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     SetResultStrOrError(fctx, z, n, TEXTENCODE.UTF8, DESTRUCTOR_TRANSIENT);
     fctx.IsError = RC.ERROR;
 }
예제 #12
0
 public static object User_Data(FuncContext fctx)
 {
     Debug.Assert(fctx != null && fctx.Func != null);
     return(fctx.Func.UserData);
 }
예제 #13
0
 public static Context Context_Ctx(FuncContext fctx)
 {
     Debug.Assert(fctx != null && fctx.Func != null);
     return(fctx.S.Ctx);
 }
예제 #14
0
 public static void Result_ErrorOverflow(FuncContext fctx)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     fctx.IsError = RC.ERROR;
     SetResultStrOrError(fctx, "string or blob too big", -1, TEXTENCODE.UTF8, DESTRUCTOR_STATIC);
 }
예제 #15
0
 void Result_Error16(FuncContext fctx, string z, int n)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     fctx.IsError = RC.ERROR;
     MemSetStr(fctx.S, z, n, TEXTENCODE.UTF16NATIVE, DESTRUCTOR_TRANSIENT);
 }
예제 #16
0
 public static void Result_Blob(FuncContext fctx, string z, int n, Action del)
 {
     Debug.Assert(n >= 0);
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     SetResultStrOrError(fctx, z, 0, n, (TEXTENCODE)0, del);
 }
예제 #17
0
 public static void Result_Int(FuncContext fctx, int val)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     MemSetInt64(fctx.S, (long)val);
 }
예제 #18
0
 public static void Result_Value(FuncContext fctx, Mem value)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     MemCopy(fctx.S, value);
 }
예제 #19
0
 void Result_Text16le(FuncContext fctx, string z, int n, Action del)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     MemSetStr(fctx.S, z, n, TEXTENCODE.UTF16LE, del);
 }
예제 #20
0
 public static void Result_Text(FuncContext fctx, string z, int n, Action del)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     SetResultStrOrError(fctx, z, 0, n, TEXTENCODE.UTF8, del);
 }
예제 #21
0
 public static void Result_Null(FuncContext fctx)
 {
     Debug.Assert(MutexEx.Held(fctx.S.Ctx.Mutex));
     MemSetNull(fctx.S);
 }
예제 #22
0
 public static void Result_Int64(FuncContext ctx, long value)
 {
     Debug.Assert(MutexEx.Held(ctx.S.Ctx.Mutex));
     MemSetInt64(ctx.S, value);
 }