Ejemplo n.º 1
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.º 2
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);
        }
Ejemplo n.º 3
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.º 4
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);
        }
Ejemplo n.º 5
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);
        }