Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        /*
        ** Usage:   btree_open FILENAME NCACHE FLAGS
        **
        ** Open a new database
        */
        static int btree_open(
            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 = null;
            int    rc; int nCache = 0; int flags = 0;
            string zBuf = "";

            if (argc != 4)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " FILENAME NCACHE FLAGS\"", "");
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetInt(interp, argv[2], ref nCache))
            {
                return(TCL.TCL_ERROR);
            }
            if (TCL.Tcl_GetInt(interp, argv[3], ref flags))
            {
                return(TCL.TCL_ERROR);
            }
            nRefSqlite3++;
            if (nRefSqlite3 == 1)
            {
                sDb.pVfs  = sqlite3_vfs_find(null);
                sDb.mutex = sqlite3MutexAlloc(SQLITE_MUTEX_RECURSIVE);
                sqlite3_mutex_enter(sDb.mutex);
            }
            rc = sqlite3BtreeOpen(argv[1].ToString(), sDb, ref pBt, flags,
                                  SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_MAIN_DB);
            if (rc != SQLITE_OK)
            {
                TCL.Tcl_AppendResult(interp, errorName(rc), null);
                return(TCL.TCL_ERROR);
            }
            sqlite3BtreeSetCacheSize(pBt, nCache);
            sqlite3_snprintf(100, ref zBuf, "->%p", pBt);
            if (TCL.Tcl_CreateCommandPointer(interp, zBuf, pBt))
            {
                return(TCL.TCL_ERROR);
            }
            else
            {
                TCL.Tcl_AppendResult(interp, zBuf, null);
            }
            return(TCL.TCL_OK);
        }
Ejemplo n.º 3
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);
        }