Beispiel #1
0
        /*
        ** read_mutex_counters
        */
        static int test_read_mutex_counters(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            Tcl_Obj pRet;
            int     ii;

            string[] aName = new string[] {
                "fast", "recursive", "static_master", "static_mem",
                "static_open", "static_prng", "static_lru", "static_pmem"
            };

            if (objc != 1)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
                return(TCL.TCL_ERROR);
            }

            pRet = TCL.Tcl_NewObj();
            TCL.Tcl_IncrRefCount(pRet);
            for (ii = 0; ii < 8; ii++)
            {
                TCL.Tcl_ListObjAppendElement(interp, pRet, TCL.Tcl_NewStringObj(aName[ii], -1));
                TCL.Tcl_ListObjAppendElement(interp, pRet, TCL.Tcl_NewIntObj(g.aCounter[ii]));
            }
            TCL.Tcl_SetObjResult(interp, pRet);
            TCL.Tcl_DecrRefCount(ref pRet);

            return(TCL.TCL_OK);
        }
Beispiel #2
0
     /*
     ** USAGE:  utf8_to_utf8  HEX
     **
     ** The argument is a UTF8 string represented _in hexadecimal.
     ** The UTF8 might not be well-formed.  Run this string through
     ** sqlite3Utf8to8() convert it back to hex and return the result.
     */
     static int utf8_to_utf8(
         object clientdata,
         Tcl_Interp interp,
         int objc,
         Tcl_Obj[] objv
         )
     {
 #if SQLITE_DEBUG
         int    n = 0;
         int    nOut;
         string zOrig;
         byte[] z;
         if (objc != 2)
         {
             TCL.Tcl_WrongNumArgs(interp, 1, objv, "HEX");
             return(TCL.TCL_ERROR);
         }
         zOrig = TCL.Tcl_GetStringFromObj(objv[1], out n);
         z     = new byte[2 * n + 1];//sqlite3Malloc( n + 3 );
         nOut  = sqlite3TestHexToBin(zOrig, n, z);
         //z[n] = 0;
         nOut = sqlite3Utf8To8(z);
         sqlite3TestBinToHex(z, zOrig.Length);
         TCL.Tcl_AppendResult(interp, Encoding.ASCII.GetString(z, 0, n));
         //sqlite3_free( z );
         return(TCL.TCL_OK);
 #else
         Tcl_AppendResult(interp,
                          "[utf8_to_utf8] unavailable - SQLITE_DEBUG not defined", 0
                          );
         return(TCL.TCL_ERROR);
 #endif
     }
Beispiel #3
0
        /*
        ** USAGE:   hexio_render_int32   INTEGER
        **
        ** Render INTEGER has a 32-bit big-endian integer _in hexadecimal.
        */
        static int hexio_render_int32(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int val = 0;

            byte[] aNum = new byte[10];

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "INTEGER");
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetIntFromObj(interp, objv[1], ref val))
            {
                return(TCL.TCL_ERROR);
            }
            aNum[0] = (byte)(val >> 24);
            aNum[1] = (byte)(val >> 16);
            aNum[2] = (byte)(val >> 8);
            aNum[3] = (byte)val;
            sqlite3TestBinToHex(aNum, 4);
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewStringObj(aNum, 8));
            return(TCL.TCL_OK);
        }
Beispiel #4
0
        /*
        ** USAGE:   hexio_get_int   HEXDATA
        **
        ** Interpret the HEXDATA argument as a big-endian integer.  Return
        ** the value of that integer.  HEXDATA can contain between 2 and 8
        ** hexadecimal digits.
        */
        static int hexio_get_int(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int    val;
            int    nIn = 0, nOut;
            string zIn;

            byte[] aOut;
            byte[] aNum = new byte[4];

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "HEXDATA");
                return(TCL.TCL_ERROR);
            }
            zIn  = TCL.Tcl_GetStringFromObj(objv[1], ref nIn);
            aOut = new byte[nIn / 2];// sqlite3Malloc( nIn / 2 );
            if (aOut == null)
            {
                return(TCL.TCL_ERROR);
            }
            nOut = sqlite3TestHexToBin(zIn, nIn, aOut);
            if (nOut >= 4)
            {
                aNum[0] = aOut[0]; // memcpy( aNum, aOut, 4 );
                aNum[1] = aOut[1];
                aNum[2] = aOut[2];
                aNum[3] = aOut[3];
            }
            else
            {
                //memset(aNum, 0, sizeof(aNum));
                //memcpy(&aNum[4-nOut], aOut, nOut);
                aNum[4 - nOut] = aOut[0];
                if (nOut > 1)
                {
                    aNum[4 - nOut + 1] = aOut[1];
                }
                if (nOut > 2)
                {
                    aNum[4 - nOut + 2] = aOut[2];
                }
                if (nOut > 3)
                {
                    aNum[4 - nOut + 3] = aOut[3];
                }
            }
            aOut = null;// sqlite3DbFree( db, ref aOut );
            val  = (aNum[0] << 24) | (aNum[1] << 16) | (aNum[2] << 8) | aNum[3];
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(val));
            return(TCL.TCL_OK);
        }
Beispiel #5
0
        /*
        ** Usage:   hexio_read  FILENAME  OFFSET  AMT
        **
        ** Read AMT bytes from file FILENAME beginning at OFFSET from the
        ** beginning of the file.  Convert that information to hexadecimal
        ** and return the resulting HEX string.
        */
        static int hexio_read(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int    offset = 0;
            int    amt = 0, got;
            string zFile;

            byte[]     zBuf;
            FileStream _in;

            if (objc != 4)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "FILENAME OFFSET AMT");
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetIntFromObj(interp, objv[2], ref offset))
            {
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetIntFromObj(interp, objv[3], ref amt))
            {
                return(TCL.TCL_ERROR);
            }
            zFile = TCL.Tcl_GetString(objv[1]);
            zBuf  = new byte[amt * 2 + 1];// sqlite3Malloc( amt * 2 + 1 );
            if (zBuf == null)
            {
                return(TCL.TCL_ERROR);
            }
            _in = new FileStream(zFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            //if( _in==null){
            //  _in = fopen(zFile, "r");
            //}
            if (_in == null)
            {
                TCL.Tcl_AppendResult(interp, "cannot open input file ", zFile);
                return(TCL.TCL_ERROR);
            }
            _in.Seek(offset, SeekOrigin.Begin); //fseek(_in, offset, SEEK_SET);
            got = _in.Read(zBuf, 0, amt);       // got = fread( zBuf, 1, amt, _in );
            _in.Flush();
            _in.Close();                        // fclose( _in );
            if (got < 0)
            {
                got = 0;
            }
            sqlite3TestBinToHex(zBuf, got);
            TCL.Tcl_AppendResult(interp, System.Text.Encoding.UTF8.GetString(zBuf).Substring(0, got * 2));
            zBuf = null;// sqlite3DbFree( db, ref zBuf );
            return(TCL.TCL_OK);
        }
Beispiel #6
0
        /*
        ** Usage:   hexio_write  FILENAME  OFFSET  DATA
        **
        ** Write DATA into file FILENAME beginning at OFFSET from the
        ** beginning of the file.  DATA is expressed _in hexadecimal.
        */
        static int hexio_write(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int    offset = 0;
            int    nIn = 0, nOut, written;
            string zFile;
            string zIn;

            byte[]     aOut;
            FileStream _out;

            if (objc != 4)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "FILENAME OFFSET HEXDATA");
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetIntFromObj(interp, objv[2], ref offset))
            {
                return(TCL.TCL_ERROR);
            }
            zFile = TCL.Tcl_GetString(objv[1]);
            zIn   = TCL.Tcl_GetStringFromObj(objv[3], ref nIn);
            aOut  = new byte[nIn / 2 + 1];//sqlite3Malloc( nIn/2 );
            if (aOut == null)
            {
                return(TCL.TCL_ERROR);
            }
            nOut = sqlite3TestHexToBin(zIn, nIn, aOut);
            _out = new FileStream(zFile, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);// fopen( zFile, "r+b" );
            //if( _out==0 ){
            //  _out = fopen(zFile, "r+");
            //}
            if (_out == null)
            {
                TCL.Tcl_AppendResult(interp, "cannot open output file ", zFile);
                return(TCL.TCL_ERROR);
            }
            _out.Seek(offset, SeekOrigin.Begin); // fseek( _out, offset, SEEK_SET );
            written = (int)_out.Position;
            _out.Write(aOut, 0, nOut);           // written = fwrite( aOut, 1, nOut, _out );
            written = (int)_out.Position - written;
            aOut    = null;                      // sqlite3DbFree( db, ref aOut );
            _out.Flush();
            _out.Close();                        // fclose( _out );
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(written));
            return(TCL.TCL_OK);
        }
Beispiel #7
0
        /*
        ** sqlite3_initialize
        */
        static int test_initialize(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv)
        {
            int rc;

            if (objc != 1)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
                return(TCL.TCL_ERROR);
            }

            rc = sqlite3_initialize();
            TCL.Tcl_SetResult(interp, sqlite3TestErrorName(rc), TCL.TCL_VOLATILE);
            return(TCL.TCL_OK);
        }
Beispiel #8
0
        /*
        ** 2007 March 29
        **
        ** The author disclaims copyright to this source code.  In place of
        ** a legal notice, here is a blessing:
        **
        **    May you do good and not evil.
        **    May you find forgiveness for yourself and forgive others.
        **    May you share freely, never taking more than you give.
        **
        *************************************************************************
        **
        ** This file contains obscure tests of the C-interface required
        ** for completeness. Test code is written in C for these cases
        ** as there is not much point in binding to Tcl.
        *************************************************************************
        **  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
        **  C#-SQLite is an independent reimplementation of the SQLite software library
        **
        **  SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3
        **
        *************************************************************************
        */
        //#include "sqliteInt.h"
        //#include "tcl.h"
        //#include <stdlib.h>
        //#include <string.h>

        /*
        ** c_collation_test
        */
        static int c_collation_test(
            object clientdata, /* Pointer to sqlite3_enable_XXX function */
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int objc,          /* Number of arguments */
            Tcl_Obj[] objv     /* Command arguments */
            )
        {
            string  zErrFunction = "N/A";
            sqlite3 db           = null;

            int rc;

            if (objc != 1)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
                return(TCL.TCL_ERROR);
            }

            /* Open a database. */
            rc = sqlite3_open(":memory:", out db);
            if (rc != SQLITE_OK)
            {
                zErrFunction = "sqlite3_open";
                goto error_out;
            }

            rc = sqlite3_create_collation(db, "collate", 456, null, null);
            if (rc != SQLITE_MISUSE)
            {
                sqlite3_close(db);
                zErrFunction = "sqlite3_create_collation";
                goto error_out;
            }

            sqlite3_close(db);
            return(TCL.TCL_OK);

error_out:
            TCL.Tcl_ResetResult(interp);
            TCL.Tcl_AppendResult(interp, "Error testing function: ", zErrFunction, null);
            return(TCL.TCL_ERROR);
        }
Beispiel #9
0
        /*
        ** install_mutex_counters BOOLEAN
        */
        //static int test_install_mutex_counters(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  int rc = SQLITE_OK;
        //  int isInstall;

        //  sqlite3_mutex_methods counter_methods = {
        //    counterMutexInit,
        //    counterMutexEnd,
        //    counterMutexAlloc,
        //    counterMutexFree,
        //    counterMutexEnter,
        //    counterMutexTry,
        //    counterMutexLeave,
        //    counterMutexHeld,
        //    counterMutexNotheld
        //  };

        //  if( objc!=2 ){
        //    TCL.Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
        //    return TCL.TCL_ERROR;
        //  }
        //  if( TCL.TCL_OK!=Tcl_GetBooleanFromObj(interp, objv[1], isInstall) ){
        //    return TCL.TCL_ERROR;
        //  }

        //  Debug.Assert(isInstall==0 || isInstall==1);
        //  Debug.Assert(g.isInstalled==0 || g.isInstalled==1);
        //  if( isInstall==g.isInstalled ){
        //    TCL.Tcl_AppendResult(interp, "mutex counters are ");
        //    TCL.Tcl_AppendResult(interp, isInstall?"already installed":"not installed");
        //    return TCL.TCL_ERROR;
        //  }

        //  if( isInstall ){
        //    Debug.Assert( g.m.xMutexAlloc==0 );
        //    rc = sqlite3_config(SQLITE_CONFIG_GETMUTEX, g.m);
        //    if( rc==SQLITE_OK ){
        //      sqlite3_config(SQLITE_CONFIG_MUTEX, counter_methods);
        //    }
        //    g.disableTry = 0;
        //  }else{
        //    Debug.Assert( g.m.xMutexAlloc );
        //    rc = sqlite3_config(SQLITE_CONFIG_MUTEX, g.m);
        //    memset(&g.m, 0, sizeof(sqlite3_mutex_methods));
        //  }

        //  if( rc==SQLITE_OK ){
        //    g.isInstalled = isInstall;
        //  }

        //  TCL.Tcl_SetResult(interp, (char *)sqlite3TestErrorName(rc), TCL.Tcl_VOLATILE);
        //  return TCL.TCL_OK;
        //}

        /*
        ** read_mutex_counters
        */
        //static int test_read_mutex_counters(
        //     object clientdata,
        //      Tcl_Interp interp,
        //      int objc,
        //      Tcl_Obj[] objv
        //){
        //  Tcl_Obj pRet;
        //  int ii;
        //  char *aName[8] = {
        //    "fast",        "recursive",   "static_master", "static_mem",
        //    "static_open", "static_prng", "static_lru",    "static_lru2"
        //  };

        //  if( objc!=1 ){
        //    TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
        //    return TCL.TCL_ERROR;
        //  }

        //  pRet = TCL.Tcl_NewObj();
        //  TCL.Tcl_IncrRefCount(pRet);
        //  for(ii=0; ii<8; ii++){
        //    TCL.Tcl_ListObjAppendElement(interp, pRet, TCL.Tcl_NewStringObj(aName[ii], -1));
        //    TCL.Tcl_ListObjAppendElement(interp, pRet, TCL.Tcl_NewIntObj(g.aCounter[ii]));
        //  }
        //  TCL.Tcl_SetObjResult(interp, pRet);
        //  TCL.Tcl_DecrRefCount(pRet);

        //  return TCL.TCL_OK;
        //}

        /*
        ** clear_mutex_counters
        */
        static int test_clear_mutex_counters(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int ii;

            if (objc != 1)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
                return(TCL.TCL_ERROR);
            }

            for (ii = 0; ii < 8; ii++)
            {
                g.aCounter[ii] = 0;
            }
            return(TCL.TCL_OK);
        }
Beispiel #10
0
        //#include <tcl.h>

        /*
        ** Decode a pointer to an sqlite3 object.
        */
        //extern int getDbPointer(Tcl_Interp interp, string zA, sqlite3 **ppDb);

        /*
        ** Register the echo virtual table module.
        */
        static int register_wholenumber_module(
            ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
            Tcl_Interp interp,     /* The TCL interpreter that invoked this command */
            int objc,              /* Number of arguments */
            Tcl_Obj[] objv         /* Command arguments */
            )
        {
            sqlite3 db = null;

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "DB");
                return(TCL.TCL_ERROR);
            }
            if (getDbPointer(interp, TCL.Tcl_GetString(objv[1]), out db) != 0)
            {
                return(TCL.TCL_ERROR);
            }
            wholenumber_register(db);
            return(TCL.TCL_OK);
        }
Beispiel #11
0
        /*
        **    sqlite3_intarray_bind  INTARRAY  ?VALUE ...?
        **
        ** Invoke the sqlite3_intarray_bind interface on the given array of integers.
        */
        static int test_intarray_bind(
            ClientData clientData, /* Not used */
            Tcl_Interp interp,     /* The TCL interpreter that invoked this command */
            int objc,              /* Number of arguments */
            Tcl_Obj[] objv         /* Command arguments */
            )
        {
            sqlite3_intarray pArray;
            int rc = SQLITE_OK;
            int i, n;

            sqlite3_int64[] a;

            if (objc < 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "INTARRAY");
                return(TCL.TCL_ERROR);
            }
            pArray = (sqlite3_intarray)sqlite3TestTextToPtr(interp, TCL.Tcl_GetString(objv[1]));
            n      = objc - 2;
#if !SQLITE_OMIT_VIRTUALTABLE
            a = new sqlite3_int64[n];//sqlite3_malloc( sizeof(a[0])*n );
            //if( a==0 ){
            //  Tcl_AppendResult(interp, "SQLITE_NOMEM", (char*)0);
            //  return TCL_ERROR;
            //}
            for (i = 0; i < n; i++)
            {
                //a[i] = 0;
                TCL.Tcl_GetWideIntFromObj(null, objv[i + 2], out a[i]);
            }
            rc = sqlite3_intarray_bind(pArray, n, a, sqlite3_free);
            if (rc != SQLITE_OK)
            {
                TCL.Tcl_AppendResult(interp, sqlite3TestErrorName(rc), null);
                return(TCL.TCL_ERROR);
            }
#endif
            return(TCL.TCL_OK);
        }
Beispiel #12
0
        /*
        ** c_realloc_test
        */
        static int c_realloc_test(
            object clientdata, /* Pointer to sqlite3_enable_XXX function */
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int objc,          /* Number of arguments */
            Tcl_Obj[] objv     /* Command arguments */
            )
        {
            object p;
            string zErrFunction = "N/A";

            if (objc != 1)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
                return(TCL.TCL_ERROR);
            }

            p = sqlite3Malloc(5);
            if (p == null)
            {
                zErrFunction = "sqlite3Malloc";
                goto error_out;
            }

            /* Test that realloc()ing a block of memory to a negative size is
            ** the same as free()ing that memory.
            */
            //TODO -- ignore realloc
            //p = sqlite3_realloc(p, -1);
            //if( p!=null ){
            //  zErrFunction = "sqlite3_realloc";
            //  goto error_out;
            //}

            return(TCL.TCL_OK);

error_out:
            TCL.Tcl_ResetResult(interp);
            TCL.Tcl_AppendResult(interp, "Error testing function: ", zErrFunction);
            return(TCL.TCL_ERROR);
        }
Beispiel #13
0
        static int test_config(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            ConfigOption[] aOpt = new ConfigOption[] {
                new ConfigOption("singlethread", SQLITE_CONFIG_SINGLETHREAD),
                new ConfigOption("multithread", SQLITE_CONFIG_MULTITHREAD),
                new ConfigOption("serialized", SQLITE_CONFIG_SERIALIZED),
                new ConfigOption(null, 0)
            };
            int s = aOpt.Length;//sizeof(struct ConfigOption);
            int i = 0;
            int rc;

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
                return(TCL.TCL_ERROR);
            }

            if (Tcl_GetIndexFromObjStruct(interp, objv[1], aOpt, s, "flag", 0, ref i))
            {
                if (TCL.Tcl_GetIntFromObj(interp, objv[1], ref i))
                {
                    return(TCL.TCL_ERROR);
                }
            }
            else
            {
                i = aOpt[i].iValue;
            }

            rc = sqlite3_config(i);
            TCL.Tcl_SetResult(interp, sqlite3TestErrorName(rc), TCL.TCL_VOLATILE);
            return(TCL.TCL_OK);
        }
        /*
        **     sqlite3_backup CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME
        **
        */
        static int backupTestInit(
            ClientData clientData,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            sqlite3_backup pBackup;
            sqlite3        pDestDb = null;
            sqlite3        pSrcDb  = null;
            string         zDestName;
            string         zSrcName;
            string         zCmd;

            if (objc != 6)
            {
                TCL.Tcl_WrongNumArgs(
                    interp, 1, objv, "CMDNAME DESTHANDLE DESTNAME SRCHANDLE SRCNAME"
                    );
                return(TCL.TCL_ERROR);
            }

            zCmd = TCL.Tcl_GetString(objv[1]);
            getDbPointer(interp, TCL.Tcl_GetString(objv[2]), ref pDestDb);
            zDestName = TCL.Tcl_GetString(objv[3]);
            getDbPointer(interp, TCL.Tcl_GetString(objv[4]), ref pSrcDb);
            zSrcName = TCL.Tcl_GetString(objv[5]);

            pBackup = sqlite3_backup_init(pDestDb, zDestName, pSrcDb, zSrcName);
            if (null == pBackup)
            {
                TCL.Tcl_AppendResult(interp, "sqlite3_backup_init() failed");
                return(TCL.TCL_ERROR);
            }

            TCL.Tcl_CreateObjCommand(interp, zCmd, (Interp.dxObjCmdProc)backupTestCmd, pBackup, (Interp.dxCmdDeleteProc)backupTestFinish);
            TCL.Tcl_SetObjResult(interp, objv[1]);
            return(TCL.TCL_OK);
        }
Beispiel #15
0
        static int test_leave_db_mutex(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            sqlite3 db = null;

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "DB");
                return(TCL.TCL_ERROR);
            }
            getDbPointer(interp, TCL.Tcl_GetString(objv[1]), out db);
            if (null == db)
            {
                return(TCL.TCL_ERROR);
            }
            sqlite3_mutex_leave(sqlite3_db_mutex(db));
            return(TCL.TCL_OK);
        }
Beispiel #16
0
        /*
        ** Decode a pointer to an sqlite3 object.
        */
        //extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);

        /*
        ** Register the schema virtual table module.
        */
        static int register_schema_module(
            ClientData clientData, /* Not used */
            Tcl_Interp interp,     /* The TCL interpreter that invoked this command */
            int objc,              /* Number of arguments */
            Tcl_Obj[] objv         /* Command arguments */
            )
        {
            sqlite3 db = null;

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "DB");
                return(TCL.TCL_ERROR);
            }
            if (getDbPointer(interp, TCL.Tcl_GetString(objv[1]), out db) != 0)
            {
                return(TCL.TCL_ERROR);
            }
#if !SQLITE_OMIT_VIRTUALTABLE
            sqlite3_create_module(db, "schema", schemaModule, null);
#endif
            return(TCL.TCL_OK);
        }
Beispiel #17
0
    //static void init_all(Tcl_Interp );
    static int init_all_cmd(
        ClientData cd,
        Tcl_Interp interp,
        int objc,
        Tcl_Obj[] objv
        )
    {
        Tcl_Interp slave;

        if (objc != 2)
        {
            TCL.Tcl_WrongNumArgs(interp, 1, objv, "SLAVE");
            return(TCL.TCL_ERROR);
        }

        slave = TCL.Tcl_GetSlave(interp, TCL.Tcl_GetString(objv[1]));
        if (slave == null)
        {
            return(TCL.TCL_ERROR);
        }

        init_all(slave);
        return(TCL.TCL_OK);
    }
Beispiel #18
0
        /*****************************************************************************
        ** Everything below is interface for testing this module.
        */
#if SQLITE_TEST
        //#include <tcl.h>

        /*
        ** Routines to encode and decode pointers
        */
        //extern int getDbPointer(Tcl_Interp *interp, const char *zA, sqlite3 **ppDb);
        //extern void *sqlite3TestTextToPtr(const char*);
        //extern int sqlite3TestMakePointerStr(Tcl_Interp*, char *zPtr, void*);
        //extern const char *sqlite3TestErrorName(int);

        /*
        **    sqlite3_intarray_create  DB  NAME
        **
        ** Invoke the sqlite3_intarray_create interface.  A string that becomes
        ** the first parameter to sqlite3_intarray_bind.
        */
        static int test_intarray_create(
            ClientData clientData, /* Not used */
            Tcl_Interp interp,     /* The TCL interpreter that invoked this command */
            int objc,              /* Number of arguments */
            Tcl_Obj[] objv         /* Command arguments */
            )
        {
            sqlite3          db;
            string           zName;
            sqlite3_intarray pArray;
            int           rc   = SQLITE_OK;
            StringBuilder zPtr = new StringBuilder(100);

            if (objc != 3)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "DB");
                return(TCL.TCL_ERROR);
            }
            if (getDbPointer(interp, TCL.Tcl_GetString(objv[1]), out db) != 0)
            {
                return(TCL.TCL_ERROR);
            }
            zName = TCL.Tcl_GetString(objv[2]);
#if !SQLITE_OMIT_VIRTUALTABLE
            rc = sqlite3_intarray_create(db, zName, out pArray);
#endif
            if (rc != SQLITE_OK)
            {
                Debug.Assert(pArray == null);
                TCL.Tcl_AppendResult(interp, sqlite3TestErrorName(rc), null);
                return(TCL.TCL_ERROR);
            }
            sqlite3TestMakePointerStr(interp, zPtr, pArray);
            TCL.Tcl_AppendResult(interp, zPtr, null);
            return(TCL.TCL_OK);
        }
Beispiel #19
0
        /*
        ** install_mutex_counters BOOLEAN
        */
        static int test_install_mutex_counters(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int  rc        = SQLITE_OK;
            bool isInstall = false;

            sqlite3_mutex_methods counter_methods = new sqlite3_mutex_methods(
                (dxMutexInit)counterMutexInit,
                (dxMutexEnd)counterMutexEnd,
                (dxMutexAlloc)counterMutexAlloc,
                (dxMutexFree)counterMutexFree,
                (dxMutexEnter)counterMutexEnter,
                (dxMutexTry)counterMutexTry,
                (dxMutexLeave)counterMutexLeave,
                (dxMutexHeld)counterMutexHeld,
                (dxMutexNotheld)counterMutexNotheld
                );

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "BOOLEAN");
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetBoolean(interp, objv[1], out isInstall))
            {
                return(TCL.TCL_ERROR);
            }

            Debug.Assert(isInstall == false || isInstall == true);
            Debug.Assert(g.isInstalled == false || g.isInstalled == true);
            if (isInstall == g.isInstalled)
            {
                TCL.Tcl_AppendResult(interp, "mutex counters are ");
                TCL.Tcl_AppendResult(interp, isInstall ? "already installed" : "not installed");
                return(TCL.TCL_ERROR);
            }

            if (isInstall)
            {
                Debug.Assert(g.m.xMutexAlloc == null);
                rc = sqlite3_config(SQLITE_CONFIG_GETMUTEX, ref g.m);
                if (rc == SQLITE_OK)
                {
                    sqlite3_config(SQLITE_CONFIG_MUTEX, counter_methods);
                }
                g.disableTry = false;
            }
            else
            {
                Debug.Assert(g.m.xMutexAlloc != null);
                rc  = sqlite3_config(SQLITE_CONFIG_MUTEX, g.m);
                g.m = new sqlite3_mutex_methods();//        memset( &g.m, 0, sizeof( sqlite3_mutex_methods ) );
            }

            if (rc == SQLITE_OK)
            {
                g.isInstalled = isInstall;
            }

            TCL.Tcl_SetResult(interp, sqlite3TestErrorName(rc), TCL.TCL_VOLATILE);
            return(TCL.TCL_OK);
        }
        static int backupTestCmd(
            ClientData clientData,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            BackupSubCommand[] aSub = new BackupSubCommand[] {
                new BackupSubCommand("step", BackupSubCommandEnum.BACKUP_STEP, 1, "npage"),
                new BackupSubCommand("finish", BackupSubCommandEnum.BACKUP_FINISH, 0, ""),
                new BackupSubCommand("remaining", BackupSubCommandEnum.BACKUP_REMAINING, 0, ""),
                new BackupSubCommand("pagecount", BackupSubCommandEnum.BACKUP_PAGECOUNT, 0, ""),
                new BackupSubCommand(null, 0, 0, null)
            };

            sqlite3_backup p    = (sqlite3_backup)clientData;
            int            iCmd = 0;
            int            rc;

            rc = Tcl_GetIndexFromObjStruct(
                interp, objv[1], aSub, aSub.Length, "option", 0, ref iCmd
                );
            if (rc != TCL.TCL_OK)
            {
                return(rc);
            }
            if (objc != (2 + aSub[iCmd].nArg))
            {
                TCL.Tcl_WrongNumArgs(interp, 2, objv, aSub[iCmd].zArg);
                return(TCL.TCL_ERROR);
            }

            switch (aSub[iCmd].eCmd)
            {
            case BackupSubCommandEnum.BACKUP_FINISH:
            {
                string         zCmdName;
                WrappedCommand cmdInfo = null;
                zCmdName = TCL.Tcl_GetString(objv[0]);
                TCL.Tcl_GetCommandInfo(interp, zCmdName, ref cmdInfo);
                cmdInfo.deleteProc = null;
                TCL.Tcl_SetCommandInfo(interp, zCmdName, cmdInfo);
                TCL.Tcl_DeleteCommand(interp, zCmdName);

                rc = sqlite3_backup_finish(p);
                TCL.Tcl_SetResult(interp, sqlite3TestErrorName(rc), TCL.TCL_STATIC);
                break;
            }

            case BackupSubCommandEnum.BACKUP_STEP:
            {
                int nPage = 0;
                if (TCL.Tcl_GetIntFromObj(interp, objv[2], ref nPage))
                {
                    return(TCL.TCL_ERROR);
                }
                rc = sqlite3_backup_step(p, nPage);
                TCL.Tcl_SetResult(interp, sqlite3TestErrorName(rc), TCL.TCL_STATIC);
                break;
            }

            case BackupSubCommandEnum.BACKUP_REMAINING:
                TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(sqlite3_backup_remaining(p)));
                break;

            case BackupSubCommandEnum.BACKUP_PAGECOUNT:
                TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(sqlite3_backup_pagecount(p)));
                break;
            }

            return(TCL.TCL_OK);
        }
Beispiel #21
0
        /*
        ** c_misuse_test
        */
        static int c_misuse_test(
            object clientdata, /* Pointer to sqlite3_enable_XXX function */
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int objc,          /* Number of arguments */
            Tcl_Obj[] objv     /* Command arguments */
            )
        {
            string       zErrFunction = "N/A";
            sqlite3      db           = null;
            sqlite3_stmt pStmt;
            int          rc;

            if (objc != 1)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
                return(TCL.TCL_ERROR);
            }

            /* Open a database. Then close it again. We need to do this so that
            ** we have a "closed database handle" to pass to various API functions.
            */
            rc = sqlite3_open(":memory:", out db);
            if (rc != SQLITE_OK)
            {
                zErrFunction = "sqlite3_open";
                goto error_out;
            }
            sqlite3_close(db);


            rc = sqlite3_errcode(db);
            if (rc != SQLITE_MISUSE)
            {
                zErrFunction = "sqlite3_errcode";
                goto error_out;
            }

            pStmt    = new sqlite3_stmt();
            pStmt.pc = 1234;
            rc       = sqlite3_prepare(db, (StringBuilder)null, 0, ref pStmt, 0);
            if (rc != SQLITE_MISUSE)
            {
                zErrFunction = "sqlite3_prepare";
                goto error_out;
            }
            Debug.Assert(pStmt == null); /* Verify that pStmt is zeroed even on a MISUSE error */


            pStmt    = new sqlite3_stmt();
            pStmt.pc = 1234;
            rc       = sqlite3_prepare_v2(db, null, 0, ref pStmt, 0);
            if (rc != SQLITE_MISUSE)
            {
                zErrFunction = "sqlite3_prepare_v2";
                goto error_out;
            }
            Debug.Assert(pStmt == null);

#if !SQLITE_OMIT_UTF16
            pStmt = (sqlite3_stmt)1234;
            rc    = sqlite3_prepare16(db, null, 0, ref pStmt, 0);
            if (rc != SQLITE_MISUSE)
            {
                zErrFunction = "sqlite3_prepare16";
                goto error_out;
            }
            Debug.Assert(pStmt == 0);
            pStmt = (sqlite3_stmt)1234;
            rc    = sqlite3_prepare16_v2(db, null, 0, ref pStmt, 0);
            if (rc != SQLITE_MISUSE)
            {
                zErrFunction = "sqlite3_prepare16_v2";
                goto error_out;
            }
            Debug.Assert(pStmt == 0);
#endif

            return(TCL.TCL_OK);

error_out:
            TCL.Tcl_ResetResult(interp);
            TCL.Tcl_AppendResult(interp, "Error testing function: ", zErrFunction);
            return(TCL.TCL_ERROR);
        }