Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /*
        ** Usage:   btree_ismemdb ID
        **
        ** Return true if the B-Tree is in-memory.
        */
        static int btree_ismemdb(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            Btree pBt;
            int   res;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
                                     " ID\"");
                return(TCL.TCL_ERROR);
            }
            pBt = (Btree)sqlite3TestTextToPtr(interp, argv[1].ToString());
            sqlite3_mutex_enter(pBt.db.mutex);
            sqlite3BtreeEnter(pBt);
            res = sqlite3PagerIsMemdb(sqlite3BtreePager(pBt)) ? 1 : 0;
            sqlite3BtreeLeave(pBt);
            sqlite3_mutex_leave(pBt.db.mutex);
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewBooleanObj(res));
            return(TCL.TCL_OK);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 5
0
        /*
        ** tclcmd:   sqlite3_auto_extension_broken
        **
        ** Register the broken extension to be loaded automatically.
        */
        static int autoExtBrokenObjCmd(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int rc = sqlite3_auto_extension((dxInit)broken_init);

            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(SQLITE_OK);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
        /*
        ** sqlite3BitvecBuiltinTest SIZE PROGRAM
        **
        ** Invoke the SQLITE_TESTCTRL_BITVEC_TEST operator on test_control.
        ** See comments on sqlite3BitvecBuiltinTest() for additional information.
        */
        static int testBitvecBuiltinTest(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            int sz = 0, rc;
            int nProg = 0;

            int[]  aProg = new int[100];
            string z;

            if (argc != 3)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
                                     " SIZE PROGRAM\"");
            }
            if (TCL.Tcl_GetInt(interp, argv[1], out sz))
            {
                return(TCL.TCL_ERROR);
            }
            z = argv[2].ToString() + '\0';
            int iz = 0;

            while (nProg < 99 && z[iz] != 0)
            {
                while (z[iz] != 0 && !sqlite3Isdigit(z[iz]))
                {
                    iz++;
                }
                if (z[iz] == 0)
                {
                    break;
                }
                while (sqlite3Isdigit(z[iz]))
                {
                    aProg[nProg] = aProg[nProg] * 10 + (z[iz] - 48);
                    iz++;
                }
                nProg++;
            }
            aProg[nProg] = 0;
            rc           = sqlite3_test_control(SQLITE_TESTCTRL_BITVEC_TEST, sz, aProg);
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(TCL.TCL_OK);
        }
Ejemplo n.º 8
0
        /*
        ** TCLCMD:  autoinstall_test_functions
        **
        ** Invoke this TCL command to use sqlite3_auto_extension() to cause
        ** the standard set of test functions to be loaded into each new
        ** database connection.
        */
        static int autoinstall_test_funcs(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            //extern int Md5_Register(sqlite3*);
            int rc = sqlite3_auto_extension((dxInit)registerTestFunctions);

            if (rc == SQLITE_OK)
            {
                rc = sqlite3_auto_extension((dxInit)Md5_Register);
            }
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(TCL.TCL_OK);
        }
Ejemplo n.º 9
0
        /*
        **     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);
        }
Ejemplo n.º 10
0
        /*
        ** Usage:   pager_open FILENAME N-PAGE
        **
        ** Open a new pager
        */
        //static int pager_open(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  u16 pageSize;
        //  Pager *pPager;
        //  Pgno nPage;
        //  int rc;
        //  char zBuf[100];
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " FILENAME N-PAGE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  if( Tcl_GetInt(interp, argv[2], nPage) ) return TCL.TCL_ERROR;
        //  rc = sqlite3PagerOpen(sqlite3_vfs_find(0), pPager, argv[1], 0, 0,
        //      SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB,
        // pager_test_reiniter);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  sqlite3PagerSetCachesize(pPager, nPage);
        //  pageSize = test_pagesize;
        //  sqlite3PagerSetPagesize(pPager, pageSize,-1);
        //  sqlite3_snprintf(100, ref zBuf,"%p",pPager);
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_close ID
        **
        ** Close the given pager.
        */
        //static int pager_close(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerClose(pPager);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_rollback ID
        **
        ** Rollback changes
        */
        //static int pager_rollback(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerRollback(pPager);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_commit ID
        **
        ** Commit all changes
        */
        //static int pager_commit(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerCommitPhaseOne(pPager,  0, 0);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  rc = sqlite3PagerCommitPhaseTwo(pPager);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_stmt_begin ID
        **
        ** Start a new checkpoint.
        */
        //static int pager_stmt_begin(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerOpenSavepoint(pPager, 1);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_stmt_rollback ID
        **
        ** Rollback changes to a checkpoint
        */
        //static int pager_stmt_rollback(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_ROLLBACK, 0);
        //sqlite3PagerSavepoint(pPager, SAVEPOINT_RELEASE, 0);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_stmt_commit ID
        **
        ** Commit changes to a checkpoint
        */
        //static int pager_stmt_commit(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int rc;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerSavepoint(pPager, SAVEPOINT_RELEASE, 0);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_stats ID
        **
        ** Return pager statistics.
        */
        //static int pager_stats(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int i, *a;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  a = sqlite3PagerStats(pPager);
        //  for(i=0; i<9; i++){
        //    static char *zName[] = {
        //      "ref", "page", "max", "size", "state", "err",
        //      "hit", "miss", "ovfl",
        //    };
        //    char zBuf[100];
        //    Tcl_AppendElement(interp, zName[i]);
        //    sqlite3_snprintf(100, ref zBuf,"%d",a[i]);
        //    Tcl_AppendElement(interp, zBuf);
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_pagecount ID
        **
        ** Return the size of the database file.
        */
        //static int pager_pagecount(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  char zBuf[100];
        //  Pgno nPage;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  sqlite3PagerPagecount(pPager, nPage);
        //  sqlite3_snprintf(100, ref zBuf, "%d", nPage);
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_get ID PGNO
        **
        ** Return a pointer to a page from the database.
        */
        //static int page_get(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  char zBuf[100];
        //  DbPage *pPage;
        //  int pgno;
        //  int rc;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID PGNO\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  if( Tcl_GetInt(interp, argv[2], pgno) ) return TCL.TCL_ERROR;
        //rc = sqlite3PagerSharedLock(pPager);
        //if( rc==SQLITE_OK ){
        //  rc = sqlite3PagerGet(pPager, pgno, &pPage);
        //}
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  sqlite3_snprintf(100, ref zBuf,"%p",pPage);
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_lookup ID PGNO
        **
        ** Return a pointer to a page if the page is already in cache.
        ** If not in cache, return an empty string.
        */
        //static int page_lookup(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  char zBuf[100];
        //  DbPage *pPage;
        //  int pgno;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID PGNO\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  if( Tcl_GetInt(interp, argv[2], pgno) ) return TCL.TCL_ERROR;
        //  pPage = sqlite3PagerLookup(pPager, pgno);
        //  if( pPage ){
        //    sqlite3_snprintf(100, ref zBuf,"%p",pPage);
        //    Tcl_AppendResult(interp, zBuf);
        //  }
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   pager_truncate ID PGNO
        */
        //static int pager_truncate(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  Pager *pPager;
        //  int pgno;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " ID PGNO\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPager = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  if( Tcl_GetInt(interp, argv[2], pgno) ) return TCL.TCL_ERROR;
        //  sqlite3PagerTruncateImage(pPager, pgno);
        //  return TCL.TCL_OK;
        //}


        /*
        ** Usage:   page_unref PAGE
        **
        ** Drop a pointer to a page.
        */
        //static int page_unref(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  DbPage *pPage;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " PAGE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPage = (DbPage *)sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  sqlite3PagerUnref(pPage);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_read PAGE
        **
        ** Return the content of a page
        */
        //static int page_read(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  char zBuf[100];
        //  DbPage *pPage;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " PAGE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPage = sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  memcpy(zBuf, sqlite3PagerGetData(pPage), sizeof(zBuf));
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_number PAGE
        **
        ** Return the page number for a page.
        */
        //static int page_number(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  char zBuf[100];
        //  DbPage *pPage;
        //  if( argc!=2 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " PAGE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPage = (DbPage *)sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  sqlite3_snprintf(100, ref zBuf, "%d", sqlite3PagerPagenumber(pPage));
        //  Tcl_AppendResult(interp, zBuf);
        //  return TCL.TCL_OK;
        //}

        /*
        ** Usage:   page_write PAGE DATA
        **
        ** Write something into a page.
        */
        //static int page_write(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  DbPage *pPage;
        //  char *pData;
        //  int rc;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " PAGE DATA\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pPage = (DbPage *)sqlite3TestTextToPtr(interp,argv[1].ToString());
        //  rc = sqlite3PagerWrite(pPage);
        //  if( rc!=SQLITE_OK ){
        //    Tcl_AppendResult(interp, errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  pData = sqlite3PagerGetData(pPage);
        //  strncpy(pData, argv[2], test_pagesize-1);
        //  pData[test_pagesize-1] = 0;
        //  return TCL.TCL_OK;
        //}

#if !SQLITE_OMIT_DISKIO
        /*
        ** Usage:   fake_big_file  N  FILENAME
        **
        ** Write a few bytes at the N megabyte point of FILENAME.  This will
        ** create a large file.  If the file was a valid SQLite database, then
        ** the next time the database is opened, SQLite will begin allocating
        ** new pages after N.  If N is 2096 or bigger, this will test the
        ** ability of SQLite to write to large files.
        */
        //static int fake_big_file(
        //  object NotUsed,
        //  Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
        //  int argc,              /* Number of arguments */
        //  TclObject[] argv      /* Text of each argument */
        //){
        //  sqlite3_vfs *pVfs;
        //  sqlite3_file *fd = 0;
        //  int rc;
        //  int n;
        //  i64 offset;
        //  if( argc!=3 ){
        //    Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
        //       " N-MEGABYTES FILE\"", 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  if( Tcl_GetInt(interp, argv[1], n) ) return TCL.TCL_ERROR;

        //  pVfs = sqlite3_vfs_find(0);
        //  rc = sqlite3OsOpenMalloc(pVfs, argv[2], fd,
        //      (SQLITE_OPEN_CREATE|SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB), 0
        //  );
        //  if( rc !=0){
        //    Tcl_AppendResult(interp, "open failed: ", errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  offset = n;
        //  offset *= 1024*1024;
        //  rc = sqlite3OsWrite(fd, "Hello, World!", 14, offset);
        //  sqlite3OsCloseFree(fd);
        //  if( rc !=0){
        //    Tcl_AppendResult(interp, "write failed: ", errorName(rc), 0);
        //    return TCL.TCL_ERROR;
        //  }
        //  return TCL.TCL_OK;
        //}
#endif


        /*
        ** test_control_pending_byte  PENDING_BYTE
        **
        ** Set the PENDING_BYTE using the sqlite3_test_control() interface.
        */
        static int testPendingByte(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            int pbyte = 0;
            int rc;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
                                     " PENDING-BYTE\"");
            }
            if (TCL.Tcl_GetInt(interp, argv[1], ref pbyte))
            {
                return(TCL.TCL_ERROR);
            }
            rc = sqlite3_test_control(SQLITE_TESTCTRL_PENDING_BYTE, pbyte);
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(TCL.TCL_OK);
        }
Ejemplo n.º 11
0
        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);
        }