Beispiel #1
1
 public FuncDef(short nArg, byte iPrefEnc, FUNC iflags, object pUserData, FuncDef pNext, dxFunc xFunc, dxStep xStep, dxFinal xFinalize, string zName, FuncDef pHash, FuncDestructor pDestructor)
 {
     this.nArg = nArg;
     this.iPrefEnc = iPrefEnc;
     this.flags = iflags;
     this.pUserData = pUserData;
     this.pNext = pNext;
     this.xFunc = xFunc;
     this.xStep = xStep;
     this.xFinalize = xFinalize;
     this.zName = zName;
     this.pHash = pHash;
     this.pDestructor = pDestructor;
 }
 public _aFuncs(string zName, int nArg, u8 eTextRep, dxFunc xFunc)
 {
     this.zName    = zName;
     this.nArg     = nArg;
     this.eTextRep = eTextRep;
     this.xFunc    = xFunc;
 }
Beispiel #3
0
 public FuncDef(string zName, byte iPrefEnc, short nArg, int iArg, FUNC iflags, dxFunc xFunc)
 {
     this.nArg      = nArg;
     this.iPrefEnc  = iPrefEnc;
     this.flags     = iflags;
     this.pUserData = iArg;
     this.pNext     = null;
     this.xFunc     = xFunc;
     this.xStep     = null;
     this.xFinalize = null;
     this.zName     = zName;
 }
Beispiel #4
0
 public FuncDef(string zName, byte iPrefEnc, short nArg, object arg, dxFunc xFunc, FUNC flags)
 {
     this.nArg      = nArg;
     this.iPrefEnc  = iPrefEnc;
     this.flags     = flags;
     this.pUserData = arg;
     this.pNext     = null;
     this.xFunc     = xFunc;
     this.xStep     = null;
     this.xFinalize = null;
     this.zName     = zName;
 }
Beispiel #5
0
 public FuncDef(string zName, byte iPrefEnc, short nArg, int iArg, FUNC iflags, dxFunc xFunc)
 {
     this.nArg = nArg;
     this.iPrefEnc = iPrefEnc;
     this.flags = iflags;
     this.pUserData = iArg;
     this.pNext = null;
     this.xFunc = xFunc;
     this.xStep = null;
     this.xFinalize = null;
     this.zName = zName;
 }
Beispiel #6
0
 public FuncDef(short nArg, byte iPrefEnc, FUNC iflags, object pUserData, FuncDef pNext, dxFunc xFunc, dxStep xStep, dxFinal xFinalize, string zName, FuncDef pHash, FuncDestructor pDestructor)
 {
     this.nArg        = nArg;
     this.iPrefEnc    = iPrefEnc;
     this.flags       = iflags;
     this.pUserData   = pUserData;
     this.pNext       = pNext;
     this.xFunc       = xFunc;
     this.xStep       = xStep;
     this.xFinalize   = xFinalize;
     this.zName       = zName;
     this.pHash       = pHash;
     this.pDestructor = pDestructor;
 }
Beispiel #7
0
 /*
 ** This is the xFindFunction implementation for the echo module.
 ** SQLite calls this routine when the first argument of a function
 ** is a column of an echo virtual table.  This routine can optionally
 ** override the implementation of that function.  It will choose to
 ** do so if the function is named "glob", and a TCL command named
 ** ::echo_glob_overload exists.
 */
 static int echoFindFunction(
   sqlite3_vtab vtab,
   int nArg,
   string zFuncName,
   ref dxFunc pxFunc, //void (**pxFunc)(sqlite3_context*,int,sqlite3_value),
   ref object ppArg
 )
 {
   echo_vtab pVtab = (echo_vtab)vtab;
   Tcl_Interp interp = pVtab.interp;
   Tcl_CmdInfo info;
   if ( !zFuncName.StartsWith( "glob", StringComparison.InvariantCultureIgnoreCase ) )
   {
     return 0;
   }
   TCL.Tcl_GetCommandInfo( interp, "::echo_glob_overload", out info );
   if ( info ==null) 
   {
     return 0;
   }
   pxFunc = overloadedGlobFunction;
   ppArg = interp;
   return 1;
 }
Beispiel #8
0
			public dxFunc xFunc; //(sqlite3_context*,int,sqlite3_value **);

			// Constructor
			public sFuncs(string zName, sbyte nArg, u8 argType, u8 eTextRep, u8 needCollSeq, dxFunc xFunc)
			{
				this.zName = zName;
				this.nArg = nArg;
				this.argType = argType;
				this.eTextRep = eTextRep;
				this.needCollSeq = needCollSeq;
				this.xFunc = xFunc;
			}
Beispiel #9
0
static int sqlite3_create_function16(
sqlite3 db,
string zFunctionName,
int nArg,
int eTextRep,
object p,
dxFunc xFunc,   //)(sqlite3_context*,int,sqlite3_value*),
dxStep xStep,   //)(sqlite3_context*,int,sqlite3_value*),
dxFinal xFinal  //)(sqlite3_context)
){
int rc;
string zFunc8;
sqlite3_mutex_enter(db.mutex);
Debug.Assert( 0==db.mallocFailed );
zFunc8 = sqlite3Utf16to8(db, zFunctionName, -1, SQLITE_UTF16NATIVE);
rc = sqlite3CreateFunc(db, zFunc8, nArg, eTextRep, p, xFunc, xStep, xFinal, null);
sqlite3DbFree(db,ref zFunc8);
rc = sqlite3ApiExit(db, rc);
sqlite3_mutex_leave(db.mutex);
return rc;
}
Beispiel #10
0
 static int sqlite3_create_function_v2(
 sqlite3 db,
 string zFunc,
 int nArg,
 int enc,
 object p,
 dxFunc xFunc, //)(sqlite3_context*,int,sqlite3_value *),
 dxStep xStep,//)(sqlite3_context*,int,sqlite3_value *),
 dxFinal xFinal,//)(sqlite3_context)
 dxFDestroy xDestroy//)(void )
 )
 {
   int rc = SQLITE_ERROR;
   FuncDestructor pArg = null;
   sqlite3_mutex_enter( db.mutex );
   if ( xDestroy != null )
   {
     pArg = new FuncDestructor();//(FuncDestructor )sqlite3DbMallocZero(db, sizeof(FuncDestructor));
     //if( null==pArg ){
     //  xDestroy(p);
     //  goto out;
     //}
     pArg.xDestroy = xDestroy;
     pArg.pUserData = p;
   }
   rc = sqlite3CreateFunc( db, zFunc, nArg, (byte)enc, p, xFunc, xStep, xFinal, pArg );
   if ( pArg != null && pArg.nRef == 0 )
   {
     Debug.Assert( rc != SQLITE_OK );
     //xDestroy(p);
     sqlite3DbFree( db, ref pArg );
   }
   //_out:
   rc = sqlite3ApiExit( db, rc );
   sqlite3_mutex_leave( db.mutex );
   return rc;
 }
Beispiel #11
0
 /*
 ** Create new user functions.
 */
 static public int sqlite3_create_function(
 sqlite3 db,
 string zFunc,
 int nArg,
 u8 enc,
 object p,
 dxFunc xFunc, //)(sqlite3_context*,int,sqlite3_value *),
 dxStep xStep,//)(sqlite3_context*,int,sqlite3_value *),
 dxFinal xFinal//)(sqlite3_context)
 )
 {
   return sqlite3_create_function_v2( db, zFunc, nArg, enc, p, xFunc, xStep,
                         xFinal, null );
 }
Beispiel #12
0
    /*
    ** This function is exactly the same as sqlite3_create_function(), except
    ** that it is designed to be called by internal code. The difference is
    ** that if a malloc() fails in sqlite3_create_function(), an error code
    ** is returned and the mallocFailed flag cleared.
    */
    static int sqlite3CreateFunc(
    sqlite3 db,
    string zFunctionName,
    int nArg,
    u8 enc,
    object pUserData,
    dxFunc xFunc, //)(sqlite3_context*,int,sqlite3_value *),
    dxStep xStep,//)(sqlite3_context*,int,sqlite3_value *),
    dxFinal xFinal, //)(sqlite3_context),
    FuncDestructor pDestructor
    )
    {
      FuncDef p;
      int nName;

      Debug.Assert( sqlite3_mutex_held( db.mutex ) );
      if ( zFunctionName == null ||
      ( xFunc != null && ( xFinal != null || xStep != null ) ) ||
      ( xFunc == null && ( xFinal != null && xStep == null ) ) ||
      ( xFunc == null && ( xFinal == null && xStep != null ) ) ||
      ( nArg < -1 || nArg > SQLITE_MAX_FUNCTION_ARG ) ||
      ( 255 < ( nName = sqlite3Strlen30( zFunctionName ) ) ) )
      {
        return SQLITE_MISUSE_BKPT();
      }

#if !SQLITE_OMIT_UTF16
/* If SQLITE_UTF16 is specified as the encoding type, transform this
** to one of SQLITE_UTF16LE or SQLITE_UTF16BE using the
** SQLITE_UTF16NATIVE macro. SQLITE_UTF16 is not used internally.
**
** If SQLITE_ANY is specified, add three versions of the function
** to the hash table.
*/
if( enc==SQLITE_UTF16 ){
enc = SQLITE_UTF16NATIVE;
}else if( enc==SQLITE_ANY ){
int rc;
rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF8,
pUserData, xFunc, xStep, xFinal, pDestructor);
if( rc==SQLITE_OK ){
rc = sqlite3CreateFunc(db, zFunctionName, nArg, SQLITE_UTF16LE,
pUserData, xFunc, xStep, xFinal, pDestructor);
}
if( rc!=SQLITE_OK ){
return rc;
}
enc = SQLITE_UTF16BE;
}
#else
      enc = SQLITE_UTF8;
#endif

      /* Check if an existing function is being overridden or deleted. If so,
** and there are active VMs, then return SQLITE_BUSY. If a function
** is being overridden/deleted but there are no active VMs, allow the
** operation to continue but invalidate all precompiled statements.
*/
      p = sqlite3FindFunction( db, zFunctionName, nName, nArg, enc, 0 );
      if ( p != null && p.iPrefEnc == enc && p.nArg == nArg )
      {
        if ( db.activeVdbeCnt != 0 )
        {
          sqlite3Error( db, SQLITE_BUSY,
          "unable to delete/modify user-function due to active statements" );
          //Debug.Assert( 0 == db.mallocFailed );
          return SQLITE_BUSY;
        }
        else
        {
          sqlite3ExpirePreparedStatements( db );
        }
      }

      p = sqlite3FindFunction( db, zFunctionName, nName, nArg, enc, 1 );
      Debug.Assert( p != null /*|| db.mallocFailed != 0 */ );
      //if ( p == null )
      //{
      //  return SQLITE_NOMEM;
      //}

      /* If an older version of the function with a configured destructor is
      ** being replaced invoke the destructor function here. */
      functionDestroy( db, p );

      if ( pDestructor != null )
      {
        pDestructor.nRef++;
      }
      p.pDestructor = pDestructor;
      p.flags = 0;
      p.xFunc = xFunc;
      p.xStep = xStep;
      p.xFinalize = xFinal;
      p.pUserData = pUserData;
      p.nArg = (i16)nArg;
      return SQLITE_OK;
    }
Beispiel #13
0
        /*
        ** The first parameter (pDef) is a function implementation.  The
        ** second parameter (pExpr) is the first argument to this function.
        ** If pExpr is a column in a virtual table, then let the virtual
        ** table implementation have an opportunity to overload the function.
        **
        ** This routine is used to allow virtual table implementations to
        ** overload MATCH, LIKE, GLOB, and REGEXP operators.
        **
        ** Return either the pDef argument (indicating no change) or a
        ** new FuncDef structure that is marked as ephemeral using the
        ** SQLITE_FUNC_EPHEM flag.
        */
        static FuncDef sqlite3VtabOverloadFunction(
            sqlite3 db,   /* Database connection for reporting malloc problems */
            FuncDef pDef, /* Function to possibly overload */
            int nArg,     /* Number of arguments to the function */
            Expr pExpr    /* First argument to the function */
            )
        {
            Table          pTab;
            sqlite3_vtab   pVtab;
            sqlite3_module pMod;
            dxFunc         xFunc = null;//void (*xFunc)(sqlite3_context*,int,sqlite3_value*) = 0;
            object         pArg  = null;
            FuncDef        pNew;
            int            rc = 0;
            string         zLowerName;
            string         z;

            /* Check to see the left operand is a column in a virtual table */
            if (NEVER(pExpr == null))
            {
                return(pDef);
            }
            if (pExpr.op != TK_COLUMN)
            {
                return(pDef);
            }
            pTab = pExpr.pTab;
            if (NEVER(pTab == null))
            {
                return(pDef);
            }
            if ((pTab.tabFlags & TF_Virtual) == 0)
            {
                return(pDef);
            }
            pVtab = sqlite3GetVTable(db, pTab).pVtab;
            Debug.Assert(pVtab != null);
            Debug.Assert(pVtab.pModule != null);
            pMod = (sqlite3_module)pVtab.pModule;
            if (pMod.xFindFunction == null)
            {
                return(pDef);
            }

            /* Call the xFindFunction method on the virtual table implementation
            ** to see if the implementation wants to overload this function
            */
            zLowerName = pDef.zName;//sqlite3DbStrDup(db, pDef.zName);
            if (zLowerName != null)
            {
                //for(z=(unsigned char)zLowerName; *z; z++){
                //  *z = sqlite3UpperToLower[*z];
                //}
                rc = pMod.xFindFunction(pVtab, nArg, zLowerName.ToLowerInvariant(), ref xFunc, ref pArg);
                sqlite3DbFree(db, ref zLowerName);
            }
            if (rc == 0)
            {
                return(pDef);
            }

            /* Create a new ephemeral function definition for the overloaded
            ** function */
            //sqlite3DbMallocZero(db, sizeof(*pNew)
            //      + sqlite3Strlen30(pDef.zName) + 1);
            //if ( pNew == null )
            //{
            //  return pDef;
            //}
            pNew       = pDef.Copy();
            pNew.zName = pDef.zName;
            //pNew.zName = (char )&pNew[1];
            //memcpy(pNew.zName, pDef.zName, sqlite3Strlen30(pDef.zName)+1);
            pNew.xFunc     = xFunc;
            pNew.pUserData = pArg;
            pNew.flags    |= SQLITE_FUNC_EPHEM;
            return(pNew);
        }
Beispiel #14
0
 /*
 ** Create new user functions.
 */
 static public int sqlite3_create_function(
 sqlite3 db,
 string zFunctionName,
 int nArg,
 u8 enc,
 object p,
 dxFunc xFunc, //)(sqlite3_context*,int,sqlite3_value **),
 dxStep xStep,//)(sqlite3_context*,int,sqlite3_value **),
 dxFinal xFinal//)(sqlite3_context*)
 )
 {
   int rc;
   sqlite3_mutex_enter( db.mutex );
   rc = sqlite3CreateFunc( db, zFunctionName, nArg, enc, p, xFunc, xStep, xFinal );
   rc = sqlite3ApiExit( db, rc );
   sqlite3_mutex_leave( db.mutex );
   return rc;
 }
 public _aFuncs( string zName, int nArg, u8 eTextRep, dxFunc xFunc )
 {
   this.zName = zName;
   this.nArg = nArg;
   this.eTextRep = eTextRep;
   this.xFunc = xFunc;
 }
Beispiel #16
0
 public FuncDef(string zName, byte iPrefEnc, short nArg, object arg, dxFunc xFunc, FUNC flags)
 {
     this.nArg = nArg;
     this.iPrefEnc = iPrefEnc;
     this.flags = flags;
     this.pUserData = arg;
     this.pNext = null;
     this.xFunc = xFunc;
     this.xStep = null;
     this.xFinalize = null;
     this.zName = zName;
 }