コード例 #1
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_OK != TCL.Tcl_GetIntFromObj(interp, objv[2], out offset))
            {
                return(TCL.TCL_ERROR);
            }
            if (TCL.TCL_OK != TCL.Tcl_GetIntFromObj(interp, objv[3], out 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, 0, zBuf.Length).Substring(0, got * 2));
            zBuf = null;// sqlite3DbFree( db, ref zBuf );
            return(TCL.TCL_OK);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: test_wholenumber_c.cs プロジェクト: ekicyou/pasta
        //#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);
        }
コード例 #4
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);
        }
コード例 #5
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);
        }
コード例 #6
0
ファイル: test_mutex_c.cs プロジェクト: ekicyou/pasta
        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);
        }
コード例 #7
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);
        }
コード例 #8
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);
    }
コード例 #9
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);
        }
コード例 #10
0
ファイル: test_tclvar_c.cs プロジェクト: ekicyou/pasta
        static int tclvarColumn(sqlite3_vtab_cursor cur, sqlite3_context ctx, int i)
        {
            Tcl_Obj       p1 = null;
            Tcl_Obj       p2 = null;
            string        z1;
            string        z2     = "";
            tclvar_cursor pCur   = (tclvar_cursor)cur;
            Tcl_Interp    interp = ((tclvar_vtab )cur.pVtab).interp;

            TCL.Tcl_ListObjIndex(interp, pCur.pList1, pCur.i1, out p1);
            TCL.Tcl_ListObjIndex(interp, pCur.pList2, pCur.i2, out p2);
            z1 = TCL.Tcl_GetString(p1);
            if (p2 != null)
            {
                z2 = TCL.Tcl_GetString(p2);
            }
            switch (i)
            {
            case 0: {
                sqlite3_result_text(ctx, z1, -1, SQLITE_TRANSIENT);
                break;
            }

            case 1: {
                sqlite3_result_text(ctx, z2, -1, SQLITE_TRANSIENT);
                break;
            }

            case 2: {
                Tcl_Obj pVal = TCL.Tcl_GetVar2Ex(interp, z1, z2 == "" ? null : z2, (TCL.VarFlag)TCL.TCL_GLOBAL_ONLY);
                sqlite3_result_text(ctx, TCL.Tcl_GetString(pVal), -1, SQLITE_TRANSIENT);
                break;
            }
            }
            return(SQLITE_OK);
        }
コード例 #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);
        }
コード例 #12
0
        /*
        ** tclcmd:  abuse_create_function
        **
        ** Make various calls to sqlite3_create_function that do not have valid
        ** parameters.  Verify that the error condition is detected and reported.
        */
        static int abuse_create_function(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            //extern int getDbPointer(Tcl_Interp*, const char*, sqlite3**);
            sqlite3 db = null;
            int     rc;
            int     mxArg;

            if (getDbPointer(interp, TCL.Tcl_GetString(objv[1]), ref db) != 0)
            {
                return(TCL.TCL_ERROR);
            }

            rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, tStep, tStep, tFinal);
            if (rc != SQLITE_MISUSE)
            {
                goto abuse_err;
            }

            rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, tStep, tStep, null);
            if (rc != SQLITE_MISUSE)
            {
                goto abuse_err;
            }

            rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, tStep, null, tFinal);
            if (rc != SQLITE_MISUSE)
            {
                goto abuse_err;
            }

            rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, null, null, tFinal);
            if (rc != SQLITE_MISUSE)
            {
                goto abuse_err;
            }

            rc = sqlite3_create_function(db, "tx", 1, SQLITE_UTF8, 0, null, tStep, null);
            if (rc != SQLITE_MISUSE)
            {
                goto abuse_err;
            }

            rc = sqlite3_create_function(db, "tx", -2, SQLITE_UTF8, 0, tStep, null, null);
            if (rc != SQLITE_MISUSE)
            {
                goto abuse_err;
            }

            rc = sqlite3_create_function(db, "tx", 128, SQLITE_UTF8, 0, tStep, null, null);
            if (rc != SQLITE_MISUSE)
            {
                goto abuse_err;
            }

            rc = sqlite3_create_function(db, "funcxx" +
                                         "_123456789_123456789_123456789_123456789_123456789" +
                                         "_123456789_123456789_123456789_123456789_123456789" +
                                         "_123456789_123456789_123456789_123456789_123456789" +
                                         "_123456789_123456789_123456789_123456789_123456789" +
                                         "_123456789_123456789_123456789_123456789_123456789",
                                         1, SQLITE_UTF8, 0, tStep, null, null);
            if (rc != SQLITE_MISUSE)
            {
                goto abuse_err;
            }

            /* This last function registration should actually work.  Generate
            ** a no-op function (that always returns NULL) and which has the
            ** maximum-length function name and the maximum number of parameters.
            */
            sqlite3_limit(db, SQLITE_LIMIT_FUNCTION_ARG, 10000);
            mxArg = sqlite3_limit(db, SQLITE_LIMIT_FUNCTION_ARG, -1);
            rc    = sqlite3_create_function(db, "nullx" +
                                            "_123456789_123456789_123456789_123456789_123456789" +
                                            "_123456789_123456789_123456789_123456789_123456789" +
                                            "_123456789_123456789_123456789_123456789_123456789" +
                                            "_123456789_123456789_123456789_123456789_123456789" +
                                            "_123456789_123456789_123456789_123456789_123456789",
                                            mxArg, SQLITE_UTF8, 0, tStep, null, null);
            if (rc != SQLITE_OK)
            {
                goto abuse_err;
            }

            return(TCL.TCL_OK);

abuse_err:
            TCL.Tcl_AppendResult(interp, "sqlite3_create_function abused test failed"
                                 );
            return(TCL.TCL_ERROR);
        }