Beispiel #1
0
        /*
        ** usage:   btree_from_db  DB-HANDLE
        **
        ** This command returns the btree handle for the main database associated
        ** with the database-handle passed as the argument. Example usage:
        **
        ** sqlite3 db test.db
        ** set bt [btree_from_db db]
        */
        static int btree_from_db(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            string         zBuf = "";//char zBuf[100];
            WrappedCommand info = null;
            sqlite3        db;
            Btree          pBt;
            int            iDb = 0;

            if (argc != 2 && argc != 3)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " DB-HANDLE ?N?\"");
                return(TCL.TCL_ERROR);
            }

            if (TCL.Tcl_GetCommandInfo(interp, argv[1].ToString(), ref info))
            {
                TCL.Tcl_AppendResult(interp, "No such db-handle: \"", argv[1], "\"");
                return(TCL.TCL_ERROR);
            }
            if (argc == 3)
            {
                iDb = atoi(argv[2].ToString());
            }

            db = ((SqliteDb)info.objClientData).db;
            Debug.Assert(db != null);

            pBt = db.aDb[iDb].pBt;
            sqlite3_snprintf(50, ref zBuf, "->%p", pBt);
            if (TCL.Tcl_CreateCommandPointer(interp, zBuf, pBt))
            {
                return(TCL.TCL_ERROR);
            }
            else
            {
                TCL.Tcl_SetResult(interp, zBuf, TCL.TCL_VOLATILE);
            }
            return(TCL.TCL_OK);
        }
Beispiel #2
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 #3
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);
        }
        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 #5
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);
        }