示例#1
0
        /*
        ** Usage:   btree_cursor ID TABLENUM WRITEABLE
        **
        ** Create a new cursor.  Return the ID for the cursor.
        */
        static int btree_cursor(
            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           iTable = 0;
            BtCursor      pCur;
            int           rc     = SQLITE_OK;
            int           wrFlag = 0;
            StringBuilder zBuf   = new StringBuilder(30);

            if (argc != 4)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " ID TABLENUM WRITEABLE\"");
                return(TCL.TCL_ERROR);
            }
            pBt = (Btree)sqlite3TestTextToPtr(interp, argv[1].ToString());
            if (TCL.Tcl_GetInt(interp, argv[2], out iTable))
            {
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetBoolean(interp, argv[3], out wrFlag))
            {
                return(TCL.TCL_ERROR);
            }
            //pCur = (BtCursor )ckalloc(sqlite3BtreeCursorSize());
            pCur = new BtCursor();// memset( pCur, 0, sqlite3BtreeCursorSize() );
            sqlite3BtreeEnter(pBt);
#if !SQLITE_OMIT_SHARED_CACHE
            rc = sqlite3BtreeLockTable(pBt, iTable, wrFlag);
#endif
            if (rc == SQLITE_OK)
            {
                rc = sqlite3BtreeCursor(pBt, iTable, wrFlag, null, pCur);
            }
            sqlite3BtreeLeave(pBt);
            if (rc != 0)
            {
                pCur = null;// ckfree( pCur );
                TCL.Tcl_AppendResult(interp, errorName(rc), null);
                ;
                return(TCL.TCL_ERROR);
            }
            sqlite3_snprintf(30, zBuf, "->%p", pCur);
            if (TCL.Tcl_CreateCommandPointer(interp, zBuf, pCur))
            {
                return(TCL.TCL_ERROR);
            }
            else
            {
                TCL.Tcl_AppendResult(interp, zBuf);
            }
            return(SQLITE_OK);
        }
示例#2
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);
        }