示例#1
0
     /*
     ** USAGE:  utf8_to_utf8  HEX
     **
     ** The argument is a UTF8 string represented _in hexadecimal.
     ** The UTF8 might not be well-formed.  Run this string through
     ** sqlite3Utf8to8() convert it back to hex and return the result.
     */
     static int utf8_to_utf8(
         object clientdata,
         Tcl_Interp interp,
         int objc,
         Tcl_Obj[] objv
         )
     {
 #if SQLITE_DEBUG
         int    n = 0;
         int    nOut;
         string zOrig;
         byte[] z;
         if (objc != 2)
         {
             TCL.Tcl_WrongNumArgs(interp, 1, objv, "HEX");
             return(TCL.TCL_ERROR);
         }
         zOrig = TCL.Tcl_GetStringFromObj(objv[1], out n);
         z     = new byte[2 * n + 1];//sqlite3Malloc( n + 3 );
         nOut  = sqlite3TestHexToBin(zOrig, n, z);
         //z[n] = 0;
         nOut = sqlite3Utf8To8(z);
         sqlite3TestBinToHex(z, zOrig.Length);
         TCL.Tcl_AppendResult(interp, Encoding.ASCII.GetString(z, 0, n));
         //sqlite3_free( z );
         return(TCL.TCL_OK);
 #else
         Tcl_AppendResult(interp,
                          "[utf8_to_utf8] unavailable - SQLITE_DEBUG not defined", 0
                          );
         return(TCL.TCL_ERROR);
 #endif
     }
示例#2
0
/*
** Returns 1 if data is ready, or 0 if not.
*/
        static int next2(Tcl_Interp interp, tclvar_cursor pCur, Tcl_Obj pObj)
        {
            Tcl_Obj p;

            if (pObj != null)
            {
                if (null == pCur.pList2)
                {
                    p = TCL.Tcl_NewStringObj("array names", -1);
                    TCL.Tcl_IncrRefCount(p);
                    TCL.Tcl_ListObjAppendElement(null, p, pObj);
                    TCL.Tcl_EvalObjEx(interp, p, TCL.TCL_EVAL_GLOBAL);
                    TCL.Tcl_DecrRefCount(ref p);
                    pCur.pList2 = TCL.Tcl_GetObjResult(interp);
                    TCL.Tcl_IncrRefCount(pCur.pList2);
                    Debug.Assert(pCur.i2 == 0);
                }
                else
                {
                    int n = 0;
                    pCur.i2++;
                    TCL.Tcl_ListObjLength(null, pCur.pList2, out n);
                    if (pCur.i2 >= n)
                    {
                        TCL.Tcl_DecrRefCount(ref pCur.pList2);
                        pCur.pList2 = null;
                        pCur.i2     = 0;
                        return(0);
                    }
                }
            }

            return(1);
        }
示例#3
0
        /*
        ** Usage:   btree_begin_transaction ID
        **
        ** Start a new transaction
        */
        static int btree_begin_transaction(
            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   rc;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " ID\"", null);
                return(TCL.TCL_ERROR);
            }
            pBt = (Btree)sqlite3TestTextToPtr(interp, argv[1].ToString());
            sqlite3BtreeEnter(pBt);
            rc = sqlite3BtreeBeginTrans(pBt, 1);
            sqlite3BtreeLeave(pBt);
            if (rc != SQLITE_OK)
            {
                TCL.Tcl_AppendResult(interp, errorName(rc), null);;
                return(TCL.TCL_ERROR);
            }
            return(TCL.TCL_OK);
        }
示例#4
0
        /*
        ** Usage:   btree_first ID
        **
        ** Move the cursor to the first entry in the table.  Return 0 if the
        ** cursor was left point to something and 1 if the table is empty.
        */
        static int btree_first(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            BtCursor pCur;
            int      rc;
            int      res  = 0;
            string   zBuf = "";//[100];

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " ID\"");
                return(TCL.TCL_ERROR);
            }
            pCur = (BtCursor)sqlite3TestTextToPtr(interp, argv[1].ToString());
#if SQLITE_TEST
            sqlite3BtreeEnter(pCur.pBtree);
#endif
            rc = sqlite3BtreeFirst(pCur, ref res);
#if SQLITE_TEST
            sqlite3BtreeLeave(pCur.pBtree);
#endif
            if (rc != 0)
            {
                TCL.Tcl_AppendResult(interp, errorName(rc), null);;
                return(TCL.TCL_ERROR);
            }
            sqlite3_snprintf(100, ref zBuf, "%d", res);
            TCL.Tcl_AppendResult(interp, zBuf);
            return(SQLITE_OK);
        }
示例#5
0
        /*
        ** Usage:   btree_close_cursor ID
        **
        ** Close a cursor opened using btree_cursor.
        */
        static int btree_close_cursor(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            BtCursor pCur;
            Btree    pBt;
            int      rc;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " ID\"");
                return(TCL.TCL_ERROR);
            }
            pCur = (BtCursor)sqlite3TestTextToPtr(interp, argv[1].ToString());
            pBt  = pCur.pBtree;
            sqlite3BtreeEnter(pBt);
            rc = sqlite3BtreeCloseCursor(pCur);
            sqlite3BtreeLeave(pBt);
            pCur = null;//ckfree( (char*)pCur );
            if (rc != 0)
            {
                TCL.Tcl_AppendResult(interp, errorName(rc), null);;
                return(TCL.TCL_ERROR);
            }
            return(SQLITE_OK);
        }
示例#6
0
        /*
        ** Usage:   btree_ismemdb ID
        **
        ** Return true if the B-Tree is in-memory.
        */
        static int btree_ismemdb(
            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   res;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
                                     " ID\"");
                return(TCL.TCL_ERROR);
            }
            pBt = (Btree)sqlite3TestTextToPtr(interp, argv[1].ToString());
            sqlite3_mutex_enter(pBt.db.mutex);
            sqlite3BtreeEnter(pBt);
            res = sqlite3PagerIsMemdb(sqlite3BtreePager(pBt)) ? 1 : 0;
            sqlite3BtreeLeave(pBt);
            sqlite3_mutex_leave(pBt.db.mutex);
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewBooleanObj(res));
            return(TCL.TCL_OK);
        }
示例#7
0
        public static int Sqlitetest3_Init(Tcl_Interp interp)
        {
            _aCmd[] aCmd = new _aCmd[] {
                new _aCmd("btree_open", (Tcl_CmdProc)btree_open),
                new _aCmd("btree_close", (Tcl_CmdProc)btree_close),
                new _aCmd("btree_begin_transaction", (Tcl_CmdProc)btree_begin_transaction),
                new _aCmd("btree_pager_stats", (Tcl_CmdProc)btree_pager_stats),
                new _aCmd("btree_cursor", (Tcl_CmdProc)btree_cursor),
                new _aCmd("btree_close_cursor", (Tcl_CmdProc)btree_close_cursor),
                new _aCmd("btree_next", (Tcl_CmdProc)btree_next),
//new _aCmd( "btree_eof",                (Tcl_CmdProc)btree_eof                ),
                new _aCmd("btree_payload_size", (Tcl_CmdProc)btree_payload_size),
                new _aCmd("btree_first", (Tcl_CmdProc)btree_first),
                new _aCmd("btree_varint_test", (Tcl_CmdProc)btree_varint_test),
                new _aCmd("btree_from_db", (Tcl_CmdProc)btree_from_db),
                new _aCmd("btree_ismemdb", (Tcl_CmdProc)btree_ismemdb),
//new _aCmd( "btree_set_cache_size",     (Tcl_CmdProc)btree_set_cache_size     ),
            };
            int i;

            for (i = 0; i < aCmd.Length; i++)
            { //sizeof(aCmd)/sizeof(aCmd[0]); i++){
                TCL.Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, null, null);
            }

            return(TCL.TCL_OK);
        }
示例#8
0
        /*
        ** 2007 May 05
        **
        ** The author disclaims copyright to this source code.  In place of
        ** a legal notice, here is a blessing:
        **
        **    May you do good and not evil.
        **    May you find forgiveness for yourself and forgive others.
        **    May you share freely, never taking more than you give.
        **
        *************************************************************************
        ** Code for testing the btree.c module in SQLite.  This code
        ** is not included in the SQLite library.  It is used for automated
        ** testing of the SQLite library.
        *************************************************************************
        **  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
        **  C#-SQLite is an independent reimplementation of the SQLite software library
        **
        **  SQLITE_SOURCE_ID: 2009-12-07 16:39:13 1ed88e9d01e9eda5cbc622e7614277f29bcc551c
        **
        **  $Header$
        *************************************************************************
        */
        //#include "btreeInt.h"
        //#include <tcl.h>

        /*
        ** Usage: sqlite3_shared_cache_report
        **
        ** Return a list of file that are shared and the number of
        ** references to each file.
        */
        static int sqlite3BtreeSharedCacheReport(
            object clientData,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
示例#9
0
 static object sqlite3TestTextToPtr( Tcl_Interp interp, string z )
 {
   //object p ;
   //u64[] v = new u64[1];
   //u32 v2;
   //int zIndex = 0;
   //if ( z[0] == '0' && z[1] == 'x' )
   //{
   //  zIndex += 2;
   //}
   //v[0] = 0;
   //while ( zIndex < z.Length )* z )
   //{
   //  v[0] = ( v[0] << 4 ) + (ulong)testHexToInt( z[zIndex] );
   //  zIndex++;
   //}
   //if ( sizeof( object ) == sizeof( u64 ) )
   //{
   //  Marshal.Copy( v, 0, (IntPtr)p, 1 );// memcpy( &p, v, sizeof( p ) );
   //}
   //else
   //{
   //  Debug.Assert( sizeof( p ) == sizeof( v2 ) );
   //  v2 = (u32)v;
   //  memcpy( &p, v2, sizeof( p ) );
   //}
   WrappedCommand cmdInfo = new WrappedCommand();
   if ( TCL.Tcl_GetCommandInfo( interp, z, ref cmdInfo ) || cmdInfo == null )
   { return null; }
   else
   {
     return cmdInfo.objClientData;
   }
 }
示例#10
0
        /*
        ** A TCL command to take the md5 hash of a file.  The argument is the
        ** name of the file.
        */
        static int md5file_cmd(object cd, Tcl_Interp interp, int argc, Tcl_Obj[] argv)
        {
            StreamReader _in = null;

            byte[]        digest = new byte[16];
            StringBuilder zBuf   = new StringBuilder(10240);

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
                                     " FILENAME\"", 0);
                return(TCL.TCL_ERROR);
            }
            Debugger.Break(); // TODO --   _in = fopen( argv[1], "rb" );
            if (_in == null)
            {
                TCL.Tcl_AppendResult(interp, "unable to open file \"", argv[1],
                                     "\" for reading", 0);
                return(TCL.TCL_ERROR);
            }
            Debugger.Break(); // TODO
            //MD5Init( ctx );
            //for(;;){
            //  int n;
            //  n = fread(zBuf, 1, zBuf.Capacity, _in);
            //  if( n<=0 ) break;
            //  MD5Update(ctx, zBuf.ToString(), (unsigned)n);
            //}
            //fclose(_in);
            //MD5Final(digest, ctx);
            //  DigestToBase16(digest, zBuf);
            //Tcl_AppendResult( interp, zBuf );
            return(TCL.TCL_OK);
        }
示例#11
0
        //static sqlite3 *getDbPointer(Tcl_Interp *pInterp, Tcl_Obj *pObj){
        //sqlite3 *db;
        //Tcl_CmdInfo info;
        //char *zCmd = TCL.Tcl_GetString(pObj);
        //if( TCL.Tcl_GetCommandInfo(pInterp, zCmd, &info) ){
        //  db = *((sqlite3 **)info.objClientData);
        //}else{
        //  db = (sqlite3*)sqlite3TestTextToPtr(zCmd);
        //}
        //assert( db );
        //return db;

        //static int test_enter_db_mutex(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  sqlite3 *db;
        //  if( objc!=2 ){
        //    TCL.Tcl_WrongNumArgs(interp, 1, objv, "DB");
        //    return TCL.TCL_ERROR;
        //  }
        //  db = getDbPointer(interp, objv[1]);
        //  if( !db ){
        //    return TCL.TCL_ERROR;
        //  }
        //  sqlite3_mutex_enter(sqlite3_db_mutex(db));
        //  return TCL.TCL_OK;
        //}

        //static int test_leave_db_mutex(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  sqlite3 *db;
        //  if( objc!=2 ){
        //    TCL.Tcl_WrongNumArgs(interp, 1, objv, "DB");
        //    return TCL.TCL_ERROR;
        //  }
        //  db = getDbPointer(interp, objv[1]);
        //  if( !db ){
        //    return TCL.TCL_ERROR;
        //  }
        //  sqlite3_mutex_leave(sqlite3_db_mutex(db));
        //  return TCL.TCL_OK;
        //}

        static public int Sqlitetest_mutex_Init(Tcl_Interp interp)
        {
            //static struct {
            //  char *zName;
            //  Tcl_ObjCmdProc *xProc;
            //}
            _aObjCmd[] aCmd = new _aObjCmd[] {
                new _aObjCmd("sqlite3_shutdown", test_shutdown),
                new _aObjCmd("sqlite3_initialize", test_initialize),
                new _aObjCmd("sqlite3_config", test_config),

//new _aCmd("enter_db_mutex",          (Tcl_ObjCmdProc*)test_enter_db_mutex },
//new _aCmd( "leave_db_mutex",          (Tcl_ObjCmdProc*)test_leave_db_mutex },

//new _aCmd( "alloc_dealloc_mutex",     (Tcl_ObjCmdProc)test_alloc_mutex ),
//new _aCmd( "install_mutex_counters",  (Tcl_ObjCmdProc)test_install_mutex_counters ),
//new _aCmd( "read_mutex_counters",     (Tcl_ObjCmdProc)test_read_mutex_counters ),
//new _aCmd( "clear_mutex_counters",    (Tcl_ObjCmdProc)test_clear_mutex_counters ),
            };
            int i;

            for (i = 0; i < aCmd.Length; i++)
            {//sizeof(aCmd)/sizeof(aCmd[0]); i++){
                TCL.Tcl_CreateObjCommand(interp, aCmd[i].zName, aCmd[i].xProc, null, null);
            }

            //Tcl_LinkVar(interp, "disable_mutex_init",
            //             g.disableInit, VarFlag.SQLITE3_LINK_INT  );
            //Tcl_LinkVar(interp, "disable_mutex_try",
            //            g.disableTry, VarFlag.SQLITE3_LINK_INT  );
            return(SQLITE_OK);
        }
示例#12
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);
        }
示例#13
0
        /*
        ** Usage:   btree_close ID
        **
        ** Close the given database.
        */
        static int btree_close(
            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   rc;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " ID\"", null);
                return(TCL.TCL_ERROR);
            }
            pBt = (Btree)sqlite3TestTextToPtr(interp, argv[1].ToString());
            rc  = sqlite3BtreeClose(ref pBt);
            if (rc != SQLITE_OK)
            {
                TCL.Tcl_AppendResult(interp, errorName(rc), null);
                return(TCL.TCL_ERROR);
            }
            nRefSqlite3--;
            if (nRefSqlite3 == 0)
            {
                sqlite3_mutex_leave(sDb.mutex);
                sqlite3_mutex_free(ref sDb.mutex);
                sDb.mutex = null;
                sDb.pVfs  = null;
            }
            return(TCL.TCL_OK);
        }
示例#14
0
        /*
        ** read_mutex_counters
        */
        static int test_read_mutex_counters(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            Tcl_Obj pRet;
            int     ii;

            string[] aName = new string[] {
                "fast", "recursive", "static_master", "static_mem",
                "static_open", "static_prng", "static_lru", "static_pmem"
            };

            if (objc != 1)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "");
                return(TCL.TCL_ERROR);
            }

            pRet = TCL.Tcl_NewObj();
            TCL.Tcl_IncrRefCount(pRet);
            for (ii = 0; ii < 8; ii++)
            {
                TCL.Tcl_ListObjAppendElement(interp, pRet, TCL.Tcl_NewStringObj(aName[ii], -1));
                TCL.Tcl_ListObjAppendElement(interp, pRet, TCL.Tcl_NewIntObj(g.aCounter[ii]));
            }
            TCL.Tcl_SetObjResult(interp, pRet);
            TCL.Tcl_DecrRefCount(ref pRet);

            return(TCL.TCL_OK);
        }
示例#15
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);
        }
示例#16
0
        public static int Sqlitetest2_Init(Tcl_Interp interp)
        {
            //extern int sqlite3_io_error_persist;
            //extern int sqlite3_io_error_pending;
            //extern int sqlite3_io_error_hit;
            //extern int sqlite3_io_error_hardhit;
            //extern int sqlite3_diskfull_pending;
            //extern int sqlite3_diskfull;
            //extern int sqlite3_pager_n_sort_bucket;
            //static struct {
            //  char *zName;
            //  Tcl_CmdProc *xProc;
            //} aCmd[] = {
            _aCmd[] aCmd = new _aCmd[] {
//new _aCmd( "pager_open",              (Tcl_CmdProc)pager_open          ),
//new _aCmd( "pager_close",             (Tcl_CmdProc)pager_close         ),
//    { "pager_commit",            (Tcl_CmdProc*)pager_commit        },
//    { "pager_rollback",          (Tcl_CmdProc*)pager_rollback      },
//    { "pager_stmt_begin",        (Tcl_CmdProc*)pager_stmt_begin    },
//    { "pager_stmt_commit",       (Tcl_CmdProc*)pager_stmt_commit   },
//    { "pager_stmt_rollback",     (Tcl_CmdProc*)pager_stmt_rollback },
//    { "pager_stats",             (Tcl_CmdProc*)pager_stats         },
//    { "pager_pagecount",         (Tcl_CmdProc*)pager_pagecount     },
//    { "page_get",                (Tcl_CmdProc*)page_get            },
//    { "page_lookup",             (Tcl_CmdProc*)page_lookup         },
//    { "page_unref",              (Tcl_CmdProc*)page_unref          },
//    { "page_read",               (Tcl_CmdProc*)page_read           },
//    { "page_write",              (Tcl_CmdProc*)page_write          },
//    { "page_number",             (Tcl_CmdProc*)page_number         },
//    { "pager_truncate",          (Tcl_CmdProc*)pager_truncate      },
#if !SQLITE_OMIT_DISKIO
//    { "fake_big_file",           (Tcl_CmdProc*)fake_big_file       },
#endif
                new _aCmd("sqlite3BitvecBuiltinTest", (Tcl_CmdProc)testBitvecBuiltinTest),
                new _aCmd("sqlite3_test_control_pending_byte", (Tcl_CmdProc)testPendingByte),
            };
            int i;
            for (i = 0; i < aCmd.Length; i++)
            {//sizeof(aCmd)/sizeof(aCmd[0]); i++){
                TCL.Tcl_CreateCommand(interp, aCmd[i].zName, aCmd[i].xProc, null, null);
            }
            TCL.Tcl_LinkVar(interp, "sqlite_io_error_pending",
                            sqlite3_io_error_pending, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_io_error_persist",
                            sqlite3_io_error_persist, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_io_error_hit",
                            sqlite3_io_error_hit, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_io_error_hardhit",
                            sqlite3_io_error_hardhit, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_diskfull_pending",
                            sqlite3_diskfull_pending, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_diskfull",
                            sqlite3_diskfull, VarFlags.SQLITE3_LINK_INT);
            TCL.Tcl_LinkVar(interp, "sqlite_pending_byte",
                            TCLsqlite3PendingByte, VarFlags.SQLITE3_LINK_INT);
            TCLsqlite3PendingByte.iValue = sqlite3PendingByte;
            return(TCL.TCL_OK);
        }
示例#17
0
        /*
        ** USAGE:   hexio_get_int   HEXDATA
        **
        ** Interpret the HEXDATA argument as a big-endian integer.  Return
        ** the value of that integer.  HEXDATA can contain between 2 and 8
        ** hexadecimal digits.
        */
        static int hexio_get_int(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int    val;
            int    nIn = 0, nOut;
            string zIn;

            byte[] aOut;
            byte[] aNum = new byte[4];

            if (objc != 2)
            {
                TCL.Tcl_WrongNumArgs(interp, 1, objv, "HEXDATA");
                return(TCL.TCL_ERROR);
            }
            zIn  = TCL.Tcl_GetStringFromObj(objv[1], ref nIn);
            aOut = new byte[nIn / 2];// sqlite3Malloc( nIn / 2 );
            if (aOut == null)
            {
                return(TCL.TCL_ERROR);
            }
            nOut = sqlite3TestHexToBin(zIn, nIn, aOut);
            if (nOut >= 4)
            {
                aNum[0] = aOut[0]; // memcpy( aNum, aOut, 4 );
                aNum[1] = aOut[1];
                aNum[2] = aOut[2];
                aNum[3] = aOut[3];
            }
            else
            {
                //memset(aNum, 0, sizeof(aNum));
                //memcpy(&aNum[4-nOut], aOut, nOut);
                aNum[4 - nOut] = aOut[0];
                if (nOut > 1)
                {
                    aNum[4 - nOut + 1] = aOut[1];
                }
                if (nOut > 2)
                {
                    aNum[4 - nOut + 2] = aOut[2];
                }
                if (nOut > 3)
                {
                    aNum[4 - nOut + 3] = aOut[3];
                }
            }
            aOut = null;// sqlite3DbFree( db, ref aOut );
            val  = (aNum[0] << 24) | (aNum[1] << 16) | (aNum[2] << 8) | aNum[3];
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(val));
            return(TCL.TCL_OK);
        }
示例#18
0
// static void sqlite3_reset_auto_extension() { }
#endif //* SQLITE_OMIT_LOAD_EXTENSION */


        /*
        ** tclcmd:   sqlite3_reset_auto_extension
        **
        ** Reset all auto-extensions
        */
        static int resetAutoExtObjCmd(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            sqlite3_reset_auto_extension();
            return(SQLITE_OK);
        }
示例#19
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);
        }
示例#20
0
        //static void *crash_malloc(int nByte){
        //  return (void *)Tcl_Alloc((size_t)nByte);
        //}
        //static void crash_free(void *p){
        //  Tcl_Free(p);
        //}
        //static void *crash_realloc(void *p, int n){
        //  return (void *)Tcl_Realloc(p, (size_t)n);
        //}

        /*
        ** Wrapper around the sqlite3OsWrite() function that avoids writing to the
        ** 512 byte block begining at offset PENDING_BYTE.
        */
        //static int writeDbFile(CrashFile *p, u8 *z, i64 iAmt, i64 iOff){
        //  int rc;
        //  int iSkip = 0;
        //  if( iOff==PENDING_BYTE && (p.flags&SQLITE_OPEN_MAIN_DB) ){
        //    iSkip = 512;
        //  }
        //  if( (iAmt-iSkip)>0 ){
        //    rc = sqlite3OsWrite(p.pRealFile, &z[iSkip], iAmt-iSkip, iOff+iSkip);
        //  }
        //  return rc;
        //}

        /*
        ** Flush the write-list as if xSync() had been called on file handle
        ** pFile. If isCrash is true, simulate a crash.
        */
        //static int writeListSync(CrashFile *pFile, int isCrash){
        //  int rc = SQLITE_OK;
        //  int iDc = g.iDeviceCharacteristics;

        //  WriteBuffer *pWrite;
        //  WriteBuffer **ppPtr;

        //  /* If this is not a crash simulation, set pFinal to point to the
        //  ** last element of the write-list that is associated with file handle
        //  ** pFile.
        //  **
        //  ** If this is a crash simulation, set pFinal to an arbitrarily selected
        //  ** element of the write-list.
        //  */
        //  WriteBuffer *pFinal = 0;
        //  if( !isCrash ){
        //    for(pWrite=g.pWriteList; pWrite; pWrite=pWrite.pNext){
        //      if( pWrite.pFile==pFile ){
        //        pFinal = pWrite;
        //      }
        //    }
        //  }else if( iDc&(SQLITE_IOCAP_SEQUENTIAL|SQLITE_IOCAP_SAFE_APPEND) ){
        //    int nWrite = 0;
        //    int iFinal;
        //    for(pWrite=g.pWriteList; pWrite; pWrite=pWrite.pNext) nWrite++;
        //    sqlite3_randomness(sizeof(int), &iFinal);
        //    iFinal = ((iFinal<0)?-1*iFinal:iFinal)%nWrite;
        //    for(pWrite=g.pWriteList; iFinal>0; pWrite=pWrite.pNext) iFinal--;
        //    pFinal = pWrite;
        //  }

#if TRACE_CRASHTEST
//  printf("Sync %s (is %s crash)\n", pFile.zName, (isCrash?"a":"not a"));
#endif

        //  ppPtr = &g.pWriteList;
        //  for(pWrite=*ppPtr; rc==SQLITE_OK && pWrite; pWrite=*ppPtr){
        //    sqlite3_file *pRealFile = pWrite.pFile.pRealFile;

        //    /* (eAction==1)      . write block out normally,
        //    ** (eAction==2)      . do nothing,
        //    ** (eAction==3)      . trash sectors.
        //    */
        //    int eAction = 0;
        //    if( !isCrash ){
        //      eAction = 2;
        //      if( (pWrite.pFile==pFile || iDc&SQLITE_IOCAP_SEQUENTIAL) ){
        //        eAction = 1;
        //      }
        //    }else{
        //      char random;
        //      sqlite3_randomness(1, &random);

        //      /* Do not select option 3 (sector trashing) if the IOCAP_ATOMIC flag
        //      ** is set or this is an OsTruncate(), not an Oswrite().
        //      */
        //      if( (iDc&SQLITE_IOCAP_ATOMIC) || (pWrite.zBuf==0) ){
        //        random &= 0x01;
        //      }

        //      /* If IOCAP_SEQUENTIAL is set and this is not the final entry
        //      ** in the truncated write-list, always select option 1 (write
        //      ** out correctly).
        //      */
        //      if( (iDc&SQLITE_IOCAP_SEQUENTIAL && pWrite!=pFinal) ){
        //        random = 0;
        //      }

        //      /* If IOCAP_SAFE_APPEND is set and this OsWrite() operation is
        //      ** an append (first byte of the written region is 1 byte past the
        //      ** current EOF), always select option 1 (write out correctly).
        //      */
        //      if( iDc&SQLITE_IOCAP_SAFE_APPEND && pWrite.zBuf ){
        //        i64 iSize;
        //        sqlite3OsFileSize(pRealFile, &iSize);
        //        if( iSize==pWrite.iOffset ){
        //          random = 0;
        //        }
        //      }

        //      if( (random&0x06)==0x06 ){
        //        eAction = 3;
        //      }else{
        //        eAction = ((random&0x01)?2:1);
        //      }
        //    }

        //    switch( eAction ){
        //      case 1: {               /* Write out correctly */
        //        if( pWrite.zBuf ){
        //          rc = writeDbFile(
        //              pWrite.pFile, pWrite.zBuf, pWrite.nBuf, pWrite.iOffset
        //          );
        //        }else{
        //          rc = sqlite3OsTruncate(pRealFile, pWrite.iOffset);
        //        }
        //        *ppPtr = pWrite.pNext;
#if TRACE_CRASHTEST
//        if( isCrash ){
//          printf("Writing %d bytes @ %d (%s)\n",
//            pWrite.nBuf, (int)pWrite.iOffset, pWrite.pFile.zName
//          );
//        }
#endif
        //        crash_free(pWrite);
        //        break;
        //      }
        //      case 2: {               /* Do nothing */
        //        ppPtr = &pWrite.pNext;
#if TRACE_CRASHTEST
//        if( isCrash ){
//          printf("Omiting %d bytes @ %d (%s)\n",
//            pWrite.nBuf, (int)pWrite.iOffset, pWrite.pFile.zName
//          );
//        }
#endif
        //        break;
        //      }
        //      case 3: {               /* Trash sectors */
        //        u8 *zGarbage;
        //        int iFirst = (pWrite.iOffset/g.iSectorSize);
        //        int iLast = (pWrite.iOffset+pWrite.nBuf-1)/g.iSectorSize;

        //        Debug.Assert(pWrite.zBuf);

#if TRACE_CRASHTEST
//        printf("Trashing %d sectors @ sector %d (%s)\n",
//            1+iLast-iFirst, iFirst, pWrite.pFile.zName
//        );
#endif

        //        zGarbage = crash_malloc(g.iSectorSize);
        //        if( zGarbage ){
        //          sqlite3_int64 i;
        //          for(i=iFirst; rc==SQLITE_OK && i<=iLast; i++){
        //            sqlite3_randomness(g.iSectorSize, zGarbage);
        //            rc = writeDbFile(
        //              pWrite.pFile, zGarbage, g.iSectorSize, i*g.iSectorSize
        //            );
        //          }
        //          crash_free(zGarbage);
        //        }else{
        //          rc = SQLITE_NOMEM;
        //        }

        //        ppPtr = &pWrite.pNext;
        //        break;
        //      }

        //      default:
        //        Debug.Assert(!"Cannot happen");
        //    }

        //    if( pWrite==pFinal ) break;
        //  }

        //  if( rc==SQLITE_OK && isCrash ){
        //    exit(-1);
        //  }

        //  for(pWrite=g.pWriteList; pWrite && pWrite.pNext; pWrite=pWrite.pNext);
        //  g.pWriteListEnd = pWrite;

        //  return rc;
        //}

        /*
        ** Add an entry to the end of the write-list.
        */
        //static int writeListAppend(
        //  sqlite3_file *pFile,
        //  sqlite3_int64 iOffset,
        //  const u8 *zBuf,
        //  int nBuf
        //){
        //  WriteBuffer *pNew;

        //  Debug.Assert((zBuf && nBuf) || (!nBuf && !zBuf));

        //  pNew = (WriteBuffer *)crash_malloc(sizeof(WriteBuffer) + nBuf);
        //  if( pNew==0 ){
        //    fprintf(stderr, "out of memory in the crash simulator\n");
        //  }
        //  memset(pNew, 0, sizeof(WriteBuffer)+nBuf);
        //  pNew.iOffset = iOffset;
        //  pNew.nBuf = nBuf;
        //  pNew.pFile = (CrashFile *)pFile;
        //  if( zBuf ){
        //    pNew.zBuf = (u8 *)&pNew[1];
        //    memcpy(pNew.zBuf, zBuf, nBuf);
        //  }

        //  if( g.pWriteList ){
        //    Debug.Assert(g.pWriteListEnd);
        //    g.pWriteListEnd.pNext = pNew;
        //  }else{
        //    g.pWriteList = pNew;
        //  }
        //  g.pWriteListEnd = pNew;

        //  return SQLITE_OK;
        //}

        /*
        ** Close a crash-file.
        */
        //static int cfClose(sqlite3_file *pFile){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  writeListSync(pCrash, 0);
        //  sqlite3OsClose(pCrash.pRealFile);
        //  return SQLITE_OK;
        //}

        ///*
        //** Read data from a crash-file.
        //*/
        //static int cfRead(
        //  sqlite3_file *pFile,
        //  void *zBuf,
        //  int iAmt,
        //  sqlite_int64 iOfst
        //){
        //  CrashFile *pCrash = (CrashFile *)pFile;

        //  /* Check the file-size to see if this is a short-read */
        //  if( pCrash.iSize<(iOfst+iAmt) ){
        //    return SQLITE_IOERR_SHORT_READ;
        //  }

        //  memcpy(zBuf, &pCrash.zData[iOfst], iAmt);
        //  return SQLITE_OK;
        //}

        ///*
        //** Write data to a crash-file.
        //*/
        //static int cfWrite(
        //  sqlite3_file *pFile,
        //  const void *zBuf,
        //  int iAmt,
        //  sqlite_int64 iOfst
        //){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  if( iAmt+iOfst>pCrash.iSize ){
        //    pCrash.iSize = iAmt+iOfst;
        //  }
        //  while( pCrash.iSize>pCrash.nData ){
        //    u8 *zNew;
        //    int nNew = (pCrash.nData*2) + 4096;
        //    zNew = crash_realloc(pCrash.zData, nNew);
        //    if( !zNew ){
        //      return SQLITE_NOMEM;
        //    }
        //    memset(&zNew[pCrash.nData], 0, nNew-pCrash.nData);
        //    pCrash.nData = nNew;
        //    pCrash.zData = zNew;
        //  }
        //  memcpy(&pCrash.zData[iOfst], zBuf, iAmt);
        //  return writeListAppend(pFile, iOfst, zBuf, iAmt);
        //}

        ///*
        //** Truncate a crash-file.
        //*/
        //static int cfTruncate(sqlite3_file *pFile, sqlite_int64 size){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  Debug.Assert(size>=0);
        //  if( pCrash.iSize>size ){
        //    pCrash.iSize = size;
        //  }
        //  return writeListAppend(pFile, size, 0, 0);
        //}

        ///*
        //** Sync a crash-file.
        //*/
        //static int cfSync(sqlite3_file *pFile, int flags){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  int isCrash = 0;

        //  const char *zName = pCrash.zName;
        //  const char *zCrashFile = g.zCrashFile;
        //  int nName = strlen(zName);
        //  int nCrashFile = strlen(zCrashFile);

        //  if( nCrashFile>0 && zCrashFile[nCrashFile-1]=='*' ){
        //    nCrashFile--;
        //    if( nName>nCrashFile ) nName = nCrashFile;
        //  }

        //  if( nName==nCrashFile && 0==memcmp(zName, zCrashFile, nName) ){
        //    if( (--g.iCrash)==0 ) isCrash = 1;
        //  }

        //  return writeListSync(pCrash, isCrash);
        //}

        ///*
        //** Return the current file-size of the crash-file.
        //*/
        //static int cfFileSize(sqlite3_file *pFile, sqlite_int64 *pSize){
        //  CrashFile *pCrash = (CrashFile *)pFile;
        //  *pSize = (i64)pCrash.iSize;
        //  return SQLITE_OK;
        //}

        ///*
        //** Calls related to file-locks are passed on to the real file handle.
        //*/
        //static int cfLock(sqlite3_file *pFile, int eLock){
        //  return sqlite3OsLock(((CrashFile *)pFile).pRealFile, eLock);
        //}
        //static int cfUnlock(sqlite3_file *pFile, int eLock){
        //  return sqlite3OsUnlock(((CrashFile *)pFile).pRealFile, eLock);
        //}
        //static int cfCheckReservedLock(sqlite3_file *pFile, int *pResOut){
        //  return sqlite3OsCheckReservedLock(((CrashFile *)pFile).pRealFile, pResOut);
        //}
        //static int cfFileControl(sqlite3_file *pFile, int op, void *pArg){
        //  return sqlite3OsFileControl(((CrashFile *)pFile).pRealFile, op, pArg);
        //}

        ///*
        //** The xSectorSize() and xDeviceCharacteristics() functions return
        //** the global values configured by the [sqlite_crashparams] tcl
        //*  interface.
        //*/
        //static int cfSectorSize(sqlite3_file *pFile){
        //  return g.iSectorSize;
        //}
        //static int cfDeviceCharacteristics(sqlite3_file *pFile){
        //  return g.iDeviceCharacteristics;
        //}

        //static const sqlite3_io_methods CrashFileVtab = {
        //  1,                            /* iVersion */
        //  cfClose,                      /* xClose */
        //  cfRead,                       /* xRead */
        //  cfWrite,                      /* xWrite */
        //  cfTruncate,                   /* xTruncate */
        //  cfSync,                       /* xSync */
        //  cfFileSize,                   /* xFileSize */
        //  cfLock,                       /* xLock */
        //  cfUnlock,                     /* xUnlock */
        //  cfCheckReservedLock,          /* xCheckReservedLock */
        //  cfFileControl,                /* xFileControl */
        //  cfSectorSize,                 /* xSectorSize */
        //  cfDeviceCharacteristics       /* xDeviceCharacteristics */
        //};

        ///*
        //** Application data for the crash VFS
        //*/
        //struct crashAppData {
        //  sqlite3_vfs *pOrig;                   /* Wrapped vfs structure */
        //};

        /*
        ** Open a crash-file file handle.
        **
        ** The caller will have allocated pVfs.szOsFile bytes of space
        ** at pFile. This file uses this space for the CrashFile structure
        ** and allocates space for the "real" file structure using
        ** sqlite3_malloc(). The assumption here is (pVfs.szOsFile) is
        ** equal or greater than sizeof(CrashFile).
        */
        //static int cfOpen(
        //  sqlite3_vfs *pCfVfs,
        //  const char *zName,
        //  sqlite3_file *pFile,
        //  int flags,
        //  int *pOutFlags
        //){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  int rc;
        //  CrashFile *pWrapper = (CrashFile *)pFile;
        //  sqlite3_file *pReal = (sqlite3_file*)&pWrapper[1];

        //  memset(pWrapper, 0, sizeof(CrashFile));
        //  rc = sqlite3OsOpen(pVfs, zName, pReal, flags, pOutFlags);

        //  if( rc==SQLITE_OK ){
        //    i64 iSize;
        //    pWrapper.pMethod = &CrashFileVtab;
        //    pWrapper.zName = (char *)zName;
        //    pWrapper.pRealFile = pReal;
        //    rc = sqlite3OsFileSize(pReal, &iSize);
        //    pWrapper.iSize = (int)iSize;
        //    pWrapper.flags = flags;
        //  }
        //  if( rc==SQLITE_OK ){
        //    pWrapper.nData = (4096 + pWrapper.iSize);
        //    pWrapper.zData = crash_malloc(pWrapper.nData);
        //    if( pWrapper.zData ){
        //      /* os_unix.c contains an Debug.Assert() that fails if the caller attempts
        //      ** to read data from the 512-byte locking region of a file opened
        //      ** with the SQLITE_OPEN_MAIN_DB flag. This region of a database file
        //      ** never contains valid data anyhow. So avoid doing such a read here.
        //      */
        //      const int isDb = (flags&SQLITE_OPEN_MAIN_DB);
        //      i64 iChunk = pWrapper.iSize;
        //      if( iChunk>PENDING_BYTE && isDb ){
        //        iChunk = PENDING_BYTE;
        //      }
        //      memset(pWrapper.zData, 0, pWrapper.nData);
        //      rc = sqlite3OsRead(pReal, pWrapper.zData, iChunk, 0);
        //      if( SQLITE_OK==rc && pWrapper.iSize>(PENDING_BYTE+512) && isDb ){
        //        i64 iOff = PENDING_BYTE+512;
        //        iChunk = pWrapper.iSize - iOff;
        //        rc = sqlite3OsRead(pReal, &pWrapper.zData[iOff], iChunk, iOff);
        //      }
        //    }else{
        //      rc = SQLITE_NOMEM;
        //    }
        //  }
        //  if( rc!=SQLITE_OK && pWrapper.pMethod ){
        //    sqlite3OsClose(pFile);
        //  }
        //  return rc;
        //}

        //static int cfDelete(sqlite3_vfs *pCfVfs, const char *zPath, int dirSync){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xDelete(pVfs, zPath, dirSync);
        //}
        //static int cfAccess(
        //  sqlite3_vfs *pCfVfs,
        //  const char *zPath,
        //  int flags,
        //  int *pResOut
        //){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xAccess(pVfs, zPath, flags, pResOut);
        //}
        //static int cfFullPathname(
        //  sqlite3_vfs *pCfVfs,
        //  const char *zPath,
        //  int nPathOut,
        //  char *zPathOut
        //){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xFullPathname(pVfs, zPath, nPathOut, zPathOut);
        //}
        //static void *cfDlOpen(sqlite3_vfs *pCfVfs, const char *zPath){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xDlOpen(pVfs, zPath);
        //}
        //static void cfDlError(sqlite3_vfs *pCfVfs, int nByte, char *zErrMsg){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  pVfs.xDlError(pVfs, nByte, zErrMsg);
        //}
        //static void (*cfDlSym(sqlite3_vfs *pCfVfs, void *pH, const char *zSym))(void){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xDlSym(pVfs, pH, zSym);
        //}
        //static void cfDlClose(sqlite3_vfs *pCfVfs, void *pHandle){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  pVfs.xDlClose(pVfs, pHandle);
        //}
        //static int cfRandomness(sqlite3_vfs *pCfVfs, int nByte, char *zBufOut){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xRandomness(pVfs, nByte, zBufOut);
        //}
        //static int cfSleep(sqlite3_vfs *pCfVfs, int nMicro){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xSleep(pVfs, nMicro);
        //}
        //static int cfCurrentTime(sqlite3_vfs *pCfVfs, double *pTimeOut){
        //  sqlite3_vfs *pVfs = (sqlite3_vfs *)pCfVfs.pAppData;
        //  return pVfs.xCurrentTime(pVfs, pTimeOut);
        //}

        //static int processDevSymArgs(
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[],
        //  int *piDeviceChar,
        //  int *piSectorSize
        //){
        //  struct DeviceFlag {
        //    char *zName;
        //    int iValue;
        //  } aFlag[] = {
        //    { "atomic",      SQLITE_IOCAP_ATOMIC      },
        //    { "atomic512",   SQLITE_IOCAP_ATOMIC512   },
        //    { "atomic1k",    SQLITE_IOCAP_ATOMIC1K    },
        //    { "atomic2k",    SQLITE_IOCAP_ATOMIC2K    },
        //    { "atomic4k",    SQLITE_IOCAP_ATOMIC4K    },
        //    { "atomic8k",    SQLITE_IOCAP_ATOMIC8K    },
        //    { "atomic16k",   SQLITE_IOCAP_ATOMIC16K   },
        //    { "atomic32k",   SQLITE_IOCAP_ATOMIC32K   },
        //    { "atomic64k",   SQLITE_IOCAP_ATOMIC64K   },
        //    { "sequential",  SQLITE_IOCAP_SEQUENTIAL  },
        //    { "safe_append", SQLITE_IOCAP_SAFE_APPEND },
        //    { 0, 0 }
        //  };

        //  int i;
        //  int iDc = 0;
        //  int iSectorSize = 0;
        //  int setSectorsize = 0;
        //  int setDeviceChar = 0;

        //  for(i=0; i<objc; i+=2){
        //    int nOpt;
        //    char *zOpt = Tcl_GetStringFromObj(objv[i], &nOpt);

        //    if( (nOpt>11 || nOpt<2 || strncmp("-sectorsize", zOpt, nOpt))
        //     && (nOpt>16 || nOpt<2 || strncmp("-characteristics", zOpt, nOpt))
        //    ){
        //      Tcl_AppendResult(interp,
        //        "Bad option: \"", zOpt,
        //        "\" - must be \"-characteristics\" or \"-sectorsize\"", 0
        //      );
        //      return TCL.TCL_ERROR;
        //    }
        //    if( i==objc-1 ){
        //      Tcl_AppendResult(interp, "Option requires an argument: \"", zOpt, "\"",0);
        //      return TCL.TCL_ERROR;
        //    }

        //    if( zOpt[1]=='s' ){
        //      if( Tcl_GetIntFromObj(interp, objv[i+1], &iSectorSize) ){
        //        return TCL.TCL_ERROR;
        //      }
        //      setSectorsize = 1;
        //    }else{
        //      int j;
        //      Tcl_Obj **apObj;
        //      int nObj;
        //      if( Tcl_ListObjGetElements(interp, objv[i+1], &nObj, &apObj) ){
        //        return TCL.TCL_ERROR;
        //      }
        //      for(j=0; j<nObj; j++){
        //        int rc;
        //        int iChoice;
        //        Tcl_Obj *pFlag = Tcl_DuplicateObj(apObj[j]);
        //        Tcl_IncrRefCount(pFlag);
        //        Tcl_UtfToLower(Tcl_GetString(pFlag));

        //        rc = Tcl_GetIndexFromObjStruct(
        //            interp, pFlag, aFlag, sizeof(aFlag[0]), "no such flag", 0, &iChoice
        //        );
        //        Tcl_DecrRefCount(pFlag);
        //        if( rc ){
        //          return TCL.TCL_ERROR;
        //        }

        //        iDc |= aFlag[iChoice].iValue;
        //      }
        //      setDeviceChar = 1;
        //    }
        //  }

        //  if( setDeviceChar ){
        //    *piDeviceChar = iDc;
        //  }
        //  if( setSectorsize ){
        //    *piSectorSize = iSectorSize;
        //  }

        //  return TCL.TCL_OK;
        //}

        /*
        ** tclcmd:   sqlite_crash_enable ENABLE
        **
        ** Parameter ENABLE must be a boolean value. If true, then the "crash"
        ** vfs is added to the system. If false, it is removed.
        */
        //static int crashEnableCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  int isEnable;
        //  static sqlite3_vfs crashVfs = {
        //    1,                  /* iVersion */
        //    0,                  /* szOsFile */
        //    0,                  /* mxPathname */
        //    0,                  /* pNext */
        //    "crash",            /* zName */
        //    0,                  /* pAppData */

        //    cfOpen,               /* xOpen */
        //    cfDelete,             /* xDelete */
        //    cfAccess,             /* xAccess */
        //    cfFullPathname,       /* xFullPathname */
        //    cfDlOpen,             /* xDlOpen */
        //    cfDlError,            /* xDlError */
        //    cfDlSym,              /* xDlSym */
        //    cfDlClose,            /* xDlClose */
        //    cfRandomness,         /* xRandomness */
        //    cfSleep,              /* xSleep */
        //    cfCurrentTime         /* xCurrentTime */
        //  };

        //  if( objc!=2 ){
        //    Tcl_WrongNumArgs(interp, 1, objv, "ENABLE");
        //    return TCL.TCL_ERROR;
        //  }

        //  if( Tcl_GetBooleanFromObj(interp, objv[1], &isEnable) ){
        //    return TCL.TCL_ERROR;
        //  }

        //  if( (isEnable && crashVfs.pAppData) || (!isEnable && !crashVfs.pAppData) ){
        //    return TCL.TCL_OK;
        //  }

        //  if( crashVfs.pAppData==0 ){
        //    sqlite3_vfs *pOriginalVfs = sqlite3_vfs_find(0);
        //    crashVfs.mxPathname = pOriginalVfs.mxPathname;
        //    crashVfs.pAppData = (void *)pOriginalVfs;
        //    crashVfs.szOsFile = sizeof(CrashFile) + pOriginalVfs.szOsFile;
        //    sqlite3_vfs_register(&crashVfs, 0);
        //  }else{
        //    crashVfs.pAppData = 0;
        //    sqlite3_vfs_unregister(&crashVfs);
        //  }

        //  return TCL.TCL_OK;
        //}

        /*
        ** tclcmd:   sqlite_crashparams ?OPTIONS? DELAY CRASHFILE
        **
        ** This procedure implements a TCL command that enables crash testing
        ** in testfixture.  Once enabled, crash testing cannot be disabled.
        **
        ** Available options are "-characteristics" and "-sectorsize". Both require
        ** an argument. For -sectorsize, this is the simulated sector size in
        ** bytes. For -characteristics, the argument must be a list of io-capability
        ** flags to simulate. Valid flags are "atomic", "atomic512", "atomic1K",
        ** "atomic2K", "atomic4K", "atomic8K", "atomic16K", "atomic32K",
        ** "atomic64K", "sequential" and "safe_append".
        **
        ** Example:
        **
        **   sqlite_crashparams -sect 1024 -char {atomic sequential} ./test.db 1
        **
        */
        //static int crashParamsObjCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  int iDelay;
        //  const char *zCrashFile;
        //  int nCrashFile, iDc, iSectorSize;

        //  iDc = -1;
        //  iSectorSize = -1;

        //  if( objc<3 ){
        //    Tcl_WrongNumArgs(interp, 1, objv, "?OPTIONS? DELAY CRASHFILE");
        //    goto error;
        //  }

        //  zCrashFile = Tcl_GetStringFromObj(objv[objc-1], &nCrashFile);
        //  if( nCrashFile>=sizeof(g.zCrashFile) ){
        //    Tcl_AppendResult(interp, "Filename is too long: \"", zCrashFile, "\"", 0);
        //    goto error;
        //  }
        //  if( Tcl_GetIntFromObj(interp, objv[objc-2], &iDelay) ){
        //    goto error;
        //  }

        //  if( processDevSymArgs(interp, objc-3, &objv[1], &iDc, &iSectorSize) ){
        //    return TCL.TCL_ERROR;
        //  }

        //  if( iDc>=0 ){
        //    g.iDeviceCharacteristics = iDc;
        //  }
        //  if( iSectorSize>=0 ){
        //    g.iSectorSize = iSectorSize;
        //  }

        //  g.iCrash = iDelay;
        //  memcpy(g.zCrashFile, zCrashFile, nCrashFile+1);
        //  sqlite3CrashTestEnable = 1;
        //  return TCL.TCL_OK;

        //error:
        //  return TCL.TCL_ERROR;
        //}

        //static int devSymObjCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  void devsym_register(int iDeviceChar, int iSectorSize);

        //  int iDc = -1;
        //  int iSectorSize = -1;

        //  if( processDevSymArgs(interp, objc-1, &objv[1], &iDc, &iSectorSize) ){
        //    return TCL.TCL_ERROR;
        //  }
        //  devsym_register(iDc, iSectorSize);

        //  return TCL.TCL_OK;
        //}

        /*
        ** tclcmd: register_jt_vfs ?-default? PARENT-VFS
        */
        //static int jtObjCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  int jt_register(char *, int);
        //  char *zParent = 0;

        //  if( objc!=2 && objc!=3 ){
        //    Tcl_WrongNumArgs(interp, 1, objv, "?-default? PARENT-VFS");
        //    return TCL.TCL_ERROR;
        //  }
        //  zParent = Tcl_GetString(objv[1]);
        //  if( objc==3 ){
        //    if( strcmp(zParent, "-default") ){
        //      Tcl_AppendResult(interp,
        //          "bad option \"", zParent, "\": must be -default", 0
        //      );
        //      return TCL.TCL_ERROR;
        //    }
        //    zParent = Tcl_GetString(objv[2]);
        //  }

        //  if( !(*zParent) ){
        //    zParent = 0;
        //  }
        //  if( jt_register(zParent, objc==3) ){
        //    Tcl_AppendResult(interp, "Error in jt_register", 0);
        //    return TCL.TCL_ERROR;
        //  }

        //  return TCL.TCL_OK;
        //}

        /*
        ** tclcmd: unregister_jt_vfs
        */
        //static int jtUnregisterObjCmd(
        //  void * clientData,
        //  Tcl_Interp *interp,
        //  int objc,
        //  Tcl_Obj *CONST objv[]
        //){
        //  void jt_unregister(void);

        //  if( objc!=1 ){
        //    Tcl_WrongNumArgs(interp, 1, objv, "");
        //    return TCL.TCL_ERROR;
        //  }

        //  jt_unregister();
        //  return TCL.TCL_OK;
        //}
#endif //* SQLITE_OMIT_DISKIO */

        /*
        ** This procedure registers the TCL procedures defined in this file.
        */
        static public int Sqlitetest6_Init(Tcl_Interp interp)
        {
#if !SQLITE_OMIT_DISKIO
            //Tcl_CreateObjCommand(interp, "sqlite3_crash_enable", crashEnableCmd, 0, 0);
            //Tcl_CreateObjCommand(interp, "sqlite3_crashparams", crashParamsObjCmd, 0, 0);
            //Tcl_CreateObjCommand(interp, "sqlite3_simulate_device", devSymObjCmd, 0, 0);
            //Tcl_CreateObjCommand(interp, "register_jt_vfs", jtObjCmd, 0, 0);
            //Tcl_CreateObjCommand(interp, "unregister_jt_vfs", jtUnregisterObjCmd, 0, 0);
#endif
            return(TCL.TCL_OK);
        }
示例#21
0
        /*
        ** tclcmd:   sqlite3_auto_extension_broken
        **
        ** Register the broken extension to be loaded automatically.
        */
        static int autoExtBrokenObjCmd(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            int rc = sqlite3_auto_extension((dxInit)broken_init);

            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(SQLITE_OK);
        }
示例#22
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);
        }
示例#23
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);
        }
示例#24
0
        //static class _aObjCmd {
        //   public string zName;
        //   public Tcl_ObjCmdProc xProc;
        //   public object clientData;
        //}

        /*
        ** Register commands with the TCL interpreter.
        */
        static public int Sqlitetestwholenumber_Init(Tcl_Interp interp)
        {
            _aObjCmd[] aObjCmd = new _aObjCmd[] {
                new _aObjCmd("register_wholenumber_module", register_wholenumber_module, 0),
            };
            int i;

            for (i = 0; i < aObjCmd.Length; i++)
            {//sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
                TCL.Tcl_CreateObjCommand(interp, aObjCmd[i].zName,
                                         aObjCmd[i].xProc, aObjCmd[i].clientData, null);
            }
            return(TCL.TCL_OK);
        }
示例#25
0
        /*
        ** This procedure registers the TCL procs defined in this file.
        */
        public static int Sqlitetest_autoext_Init(Tcl_Interp interp)
        {
#if !SQLITE_OMIT_LOAD_EXTENSION
            TCL.Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_sqr",
                                     autoExtSqrObjCmd, null, null);
            TCL.Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_cube",
                                     autoExtCubeObjCmd, null, null);
            TCL.Tcl_CreateObjCommand(interp, "sqlite3_auto_extension_broken",
                                     autoExtBrokenObjCmd, null, null);
#endif
            TCL.Tcl_CreateObjCommand(interp, "sqlite3_reset_auto_extension",
                                     resetAutoExtObjCmd, null, null);
            return(TCL.TCL_OK);
        }
示例#26
0
        /*
        ** Create and free a mutex.  Return the mutex pointer.  The pointer
        ** will be invalid since the mutex has already been freed.  The
        ** return pointer just checks to see if the mutex really was allocated.
        */
        static int test_alloc_mutex(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv)
        {
#if SQLITE_THREADSAFE
            sqlite3_mutex p    = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
            string        zBuf = "";//[100];
            sqlite3_mutex_free(ref p);
            sqlite3_snprintf(100, ref zBuf, "%p", p);
            TCL.Tcl_AppendResult(interp, zBuf);
#endif
            return(TCL.TCL_OK);
        }
示例#27
0
        /*
        ** Create and free a mutex.  Return the mutex pointer.  The pointer
        ** will be invalid since the mutex has already been freed.  The
        ** return pointer just checks to see if the mutex really was allocated.
        */
        static int test_alloc_mutex(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv)
        {
#if SQLITE_THREADSAFE
            sqlite3_mutex p    = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
            StringBuilder zBuf = new StringBuilder(100);
            sqlite3_mutex_free(p);
            sqlite3_snprintf(100, zBuf, "->%p", p);
            TCL.Tcl_AppendResult(interp, zBuf);
#endif
            return(TCL.TCL_OK);
        }
示例#28
0
        /*
        ** Usage:   btree_pager_stats ID
        **
        ** Returns pager statistics
        */
        static int btree_pager_stats(
            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   i;

            int[] a;

            if (argc != 2)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
                                     " ID\"");
                return(TCL.TCL_ERROR);
            }
            pBt = (Btree)sqlite3TestTextToPtr(interp, argv[1].ToString());

            /* Normally in this file, with a b-tree handle opened using the
            ** [btree_open] command it is safe to call sqlite3BtreeEnter() directly.
            ** But this function is sometimes called with a btree handle obtained
            ** from an open SQLite connection (using [btree_from_db]). In this case
            ** we need to obtain the mutex for the controlling SQLite handle before
            ** it is safe to call sqlite3BtreeEnter().
            */
            sqlite3_mutex_enter(pBt.db.mutex);

            sqlite3BtreeEnter(pBt);
            a = sqlite3PagerStats(sqlite3BtreePager(pBt));
            for (i = 0; i < 11; i++)
            {
                string[] zName = new string[] {
                    "ref", "page", "max", "size", "state", "err",
                    "hit", "miss", "ovfl", "read", "write"
                };
                string zBuf = "";//char zBuf[100];
                TCL.Tcl_AppendElement(interp, zName[i]);
                sqlite3_snprintf(100, ref zBuf, "%d", a[i]);
                TCL.Tcl_AppendElement(interp, zBuf);
            }
            sqlite3BtreeLeave(pBt);
            /* Release the mutex on the SQLite handle that controls this b-tree */
            sqlite3_mutex_leave(pBt.db.mutex);
            return(TCL.TCL_OK);
        }
示例#29
0
        /*
        ** TCLCMD:  autoinstall_test_functions
        **
        ** Invoke this TCL command to use sqlite3_auto_extension() to cause
        ** the standard set of test functions to be loaded into each new
        ** database connection.
        */
        static int autoinstall_test_funcs(
            object clientdata,
            Tcl_Interp interp,
            int objc,
            Tcl_Obj[] objv
            )
        {
            //extern int Md5_Register(sqlite3*);
            int rc = sqlite3_auto_extension((dxInit)registerTestFunctions);

            if (rc == SQLITE_OK)
            {
                rc = sqlite3_auto_extension((dxInit)Md5_Register);
            }
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(TCL.TCL_OK);
        }
示例#30
0
        /*
        ** sqlite3BitvecBuiltinTest SIZE PROGRAM
        **
        ** Invoke the SQLITE_TESTCTRL_BITVEC_TEST operator on test_control.
        ** See comments on sqlite3BitvecBuiltinTest() for additional information.
        */
        static int testBitvecBuiltinTest(
            object NotUsed,
            Tcl_Interp interp, /* The TCL interpreter that invoked this command */
            int argc,          /* Number of arguments */
            TclObject[] argv   /* Text of each argument */
            )
        {
            int sz = 0, rc;
            int nProg = 0;

            int[]  aProg = new int[100];
            string z;

            if (argc != 3)
            {
                TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
                                     " SIZE PROGRAM\"");
            }
            if (TCL.Tcl_GetInt(interp, argv[1], ref sz))
            {
                return(TCL.TCL_ERROR);
            }
            z = argv[2].ToString() + '\0';
            int iz = 0;

            while (nProg < 99 && z[iz] != 0)
            {
                while (z[iz] != 0 && !sqlite3Isdigit(z[iz]))
                {
                    iz++;
                }
                if (z[iz] == 0)
                {
                    break;
                }
                while (sqlite3Isdigit(z[iz]))
                {
                    aProg[nProg] = aProg[nProg] * 10 + (z[iz] - 48); iz++;
                }
                nProg++;
            }
            aProg[nProg] = 0;
            rc           = sqlite3_test_control(SQLITE_TESTCTRL_BITVEC_TEST, sz, aProg);
            TCL.Tcl_SetObjResult(interp, TCL.Tcl_NewIntObj(rc));
            return(TCL.TCL_OK);
        }
示例#31
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);
        }
示例#32
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;
 }
示例#33
0
    /*
    ** 2007 March 29
    **
    ** The author disclaims copyright to this source code.  In place of
    ** a legal notice, here is a blessing:
    **
    **    May you do good and not evil.
    **    May you find forgiveness for yourself and forgive others.
    **    May you share freely, never taking more than you give.
    **
    *************************************************************************
    **
    ** This file contains obscure tests of the C-interface required
    ** for completeness. Test code is written in C for these cases
    ** as there is not much point in binding to Tcl.
    *************************************************************************
    **  Included in SQLite3 port to C#-SQLite;  2008 Noah B Hart
    **  C#-SQLite is an independent reimplementation of the SQLite software library
    **
    **  SQLITE_SOURCE_ID: 2010-08-23 18:52:01 42537b60566f288167f1b5864a5435986838e3a3
    **
    *************************************************************************
    */
    //#include "sqliteInt.h"
    //#include "tcl.h"
    //#include <stdlib.h>
    //#include <string.h>

    /*
    ** c_collation_test
    */
    static int c_collation_test(
    object 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 */
    )
    {
      string zErrFunction = "N/A";
      sqlite3 db = null;

      int rc;
      if ( objc != 1 )
      {
        TCL.Tcl_WrongNumArgs( interp, 1, objv, "" );
        return TCL.TCL_ERROR;
      }

      /* Open a database. */
      rc = sqlite3_open( ":memory:", out db );
      if ( rc != SQLITE_OK )
      {
        zErrFunction = "sqlite3_open";
        goto error_out;
      }

      rc = sqlite3_create_collation( db, "collate", 456, null, null );
      if ( rc != SQLITE_MISUSE )
      {
        sqlite3_close( db );
        zErrFunction = "sqlite3_create_collation";
        goto error_out;
      }

      sqlite3_close( db );
      return TCL.TCL_OK;

error_out:
      TCL.Tcl_ResetResult( interp );
      TCL.Tcl_AppendResult( interp, "Error testing function: ", zErrFunction, null );
      return TCL.TCL_ERROR;
    }
示例#34
0
    /*
    ** Usage:   btree_pager_stats ID
    **
    ** Returns pager statistics
    */
    static int btree_pager_stats(
    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 i;
      int[] a;

      if ( argc != 2 )
      {
        TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0].ToString(),
        " ID\"" );
        return TCL.TCL_ERROR;
      }
      pBt = (Btree)sqlite3TestTextToPtr( interp, argv[1].ToString() );

      /* Normally in this file, with a b-tree handle opened using the
      ** [btree_open] command it is safe to call sqlite3BtreeEnter() directly.
      ** But this function is sometimes called with a btree handle obtained
      ** from an open SQLite connection (using [btree_from_db]). In this case
      ** we need to obtain the mutex for the controlling SQLite handle before
      ** it is safe to call sqlite3BtreeEnter().
      */
      sqlite3_mutex_enter( pBt.db.mutex );

      sqlite3BtreeEnter( pBt );
      a = sqlite3PagerStats( sqlite3BtreePager( pBt ) );
      for ( i = 0; i < 11; i++ )
      {
        string[] zName = new string[]{
"ref", "page", "max", "size", "state", "err",
"hit", "miss", "ovfl", "read", "write"
};
        StringBuilder zBuf = new StringBuilder( 100 );
        TCL.Tcl_AppendElement( interp, zName[i] );
        sqlite3_snprintf( 100, zBuf, "%d", a[i] );
        TCL.Tcl_AppendElement( interp, zBuf );
      }
      sqlite3BtreeLeave( pBt );
      /* Release the mutex on the SQLite handle that controls this b-tree */
      sqlite3_mutex_leave( pBt.db.mutex );
      return TCL.TCL_OK;
    }
示例#35
0
 /*
 ** Usage:   btree_begin_transaction ID
 **
 ** Start a new transaction
 */
 static int btree_begin_transaction(
 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 rc;
   if ( argc != 2 )
   {
     TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0].ToString(),
     " ID\"", null );
     return TCL.TCL_ERROR;
   }
   pBt = (Btree)sqlite3TestTextToPtr( interp, argv[1].ToString() );
   sqlite3BtreeEnter( pBt );
   rc = sqlite3BtreeBeginTrans( pBt, 1 );
   sqlite3BtreeLeave( pBt );
   if ( rc != SQLITE_OK )
   {
     TCL.Tcl_AppendResult( interp, errorName( rc ), null );
     ;
     return TCL.TCL_ERROR;
   }
   return TCL.TCL_OK;
 }
示例#36
0
 /*
 ** Usage:   btree_close ID
 **
 ** Close the given database.
 */
 static int btree_close(
 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 rc;
   if ( argc != 2 )
   {
     TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0].ToString(),
     " ID\"", null );
     return TCL.TCL_ERROR;
   }
   pBt = (Btree)sqlite3TestTextToPtr( interp, argv[1].ToString() );
   rc = sqlite3BtreeClose( ref pBt );
   if ( rc != SQLITE_OK )
   {
     TCL.Tcl_AppendResult( interp, errorName( rc ), null );
     return TCL.TCL_ERROR;
   }
   nRefSqlite3--;
   if ( nRefSqlite3 == 0 )
   {
     sqlite3_mutex_leave( sDb.mutex );
     sqlite3_mutex_free( sDb.mutex );
     sDb.mutex = null;
     sDb.pVfs = null;
   }
   return TCL.TCL_OK;
 }
示例#37
0
    /*
** Register commands with the TCL interpreter.
*/
    static public int Sqlitetest8_Init( Tcl_Interp interp )
    {
#if !SQLITE_OMIT_VIRTUALTABLE
      //static struct {
      //   string zName;
      //   Tcl_ObjCmdProc *xProc;
      //   void *clientData;
      //} 
      _aObjCmd[] aObjCmd = new _aObjCmd[]{
     new _aObjCmd( "register_echo_module",   register_echo_module, 0 ),
     new _aObjCmd(  "sqlite3_declare_vtab",   declare_vtab, 0 ),
  };
      int i;
      for ( i = 0; i < aObjCmd.Length; i++ )//sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++)
      {
        TCL.Tcl_CreateObjCommand( interp, aObjCmd[i].zName,
            aObjCmd[i].xProc, aObjCmd[i].clientData, null );
      }
#endif
      return TCL.TCL_OK;
    }
示例#38
0
    /*
    ** Usage:   btree_ismemdb ID
    **
    ** Return true if the B-Tree is in-memory.
    */
    static int btree_ismemdb(
    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 res;

      if ( argc != 2 )
      {
        TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0],
        " ID\"" );
        return TCL.TCL_ERROR;
      }
      pBt = (Btree)sqlite3TestTextToPtr( interp, argv[1].ToString() );
      sqlite3_mutex_enter( pBt.db.mutex );
      sqlite3BtreeEnter( pBt );
      res = sqlite3PagerIsMemdb( sqlite3BtreePager( pBt ) ) ? 1 : 0;
      sqlite3BtreeLeave( pBt );
      sqlite3_mutex_leave( pBt.db.mutex );
      TCL.Tcl_SetObjResult( interp, TCL.Tcl_NewBooleanObj( res ) );
      return TCL.TCL_OK;
    }
示例#39
0
    /*
    ** usage:   varint_test  START  MULTIPLIER  COUNT  INCREMENT
    **
    ** This command tests the putVarint() and getVarint()
    ** routines, both for accuracy and for speed.
    **
    ** An integer is written using putVarint() and read back with
    ** getVarint() and varified to be unchanged.  This repeats COUNT
    ** times.  The first integer is START*MULTIPLIER.  Each iteration
    ** increases the integer by INCREMENT.
    **
    ** This command returns nothing if it works.  It returns an error message
    ** if something goes wrong.
    */
    static int btree_varint_test(
    object NotUsed,
    Tcl_Interp interp,    /* The TCL interpreter that _invoked this command */
    int argc,              /* Number of arguments */
    TclObject[] argv      /* Text of each argument */
    )
    {
      int start = 0, mult = 0, count = 0, incr = 0;
      int _in;
      u32 _out = 0;
      int n1, n2, i, j;
      byte[] zBuf = new byte[100];
      if ( argc != 5 )
      {
        TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0].ToString(),
        " START MULTIPLIER COUNT incrEMENT\"", 0 );
        return TCL.TCL_ERROR;
      }
      if ( TCL.Tcl_GetInt( interp, argv[1], out start ) )
        return TCL.TCL_ERROR;
      if ( TCL.Tcl_GetInt( interp, argv[2], out mult ) )
        return TCL.TCL_ERROR;
      if ( TCL.Tcl_GetInt( interp, argv[3], out count ) )
        return TCL.TCL_ERROR;
      if ( TCL.Tcl_GetInt( interp, argv[4], out incr ) )
        return TCL.TCL_ERROR;
      _in = start;
      _in *= mult;
      for ( i = 0; i < count; i++ )
      {
        StringBuilder zErr = new StringBuilder( 200 );
        n1 = putVarint( zBuf, 0, _in );
        if ( n1 > 9 || n1 < 1 )
        {
          sqlite3_snprintf( 100, zErr, "putVarint returned %d - should be between 1 and 9", n1 );
          TCL.Tcl_AppendResult( interp, zErr );
          return TCL.TCL_ERROR;
        }
        n2 = getVarint( zBuf, 0, out _out );
        if ( n1 != n2 )
        {
          sqlite3_snprintf( 100, zErr, "putVarint returned %d and GetVar_int returned %d", n1, n2 );
          TCL.Tcl_AppendResult( interp, zErr );
          return TCL.TCL_ERROR;
        }
        if ( _in != (int)_out )
        {
          sqlite3_snprintf( 100, zErr, "Wrote 0x%016llx and got back 0x%016llx", _in, _out );
          TCL.Tcl_AppendResult( interp, zErr );
          return TCL.TCL_ERROR;
        }
        if ( ( _in & 0xffffffff ) == _in )
        {
          u32 _out32 = 0;
          n2 = getVarint32( zBuf, out _out32 );
          _out = _out32;
          if ( n1 != n2 )
          {
            sqlite3_snprintf( 100, zErr, "putVarint returned %d and GetVar_int32 returned %d",
            n1, n2 );
            TCL.Tcl_AppendResult( interp, zErr );
            return TCL.TCL_ERROR;
          }
          if ( _in != (int)_out )
          {
            sqlite3_snprintf( 100, zErr, "Wrote 0x%016llx and got back 0x%016llx from GetVar_int32",
            _in, _out );
            TCL.Tcl_AppendResult( interp, zErr );
            return TCL.TCL_ERROR;
          }
        }

        /* _in order to get realistic tim_ings, run getVar_int 19 more times.
        ** This is because getVar_int is called ab_out 20 times more often
        ** than putVarint.
        */
        for ( j = 0; j < 19; j++ )
        {
          getVarint( zBuf, 0, out _out );
        }
        _in += incr;
      }
      return TCL.TCL_OK;
    }
示例#40
0
    /*
    ** Usage:   btree_first ID
    **
    ** Move the cursor to the first entry in the table.  Return 0 if the
    ** cursor was left point to something and 1 if the table is empty.
    */
    static int btree_first(
    object NotUsed,
    Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
    int argc,              /* Number of arguments */
    TclObject[] argv      /* Text of each argument */
    )
    {
      BtCursor pCur;
      int rc;
      int res = 0;
      StringBuilder zBuf = new StringBuilder( 100 );

      if ( argc != 2 )
      {
        TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0].ToString(),
        " ID\"" );
        return TCL.TCL_ERROR;
      }
      pCur = (BtCursor)sqlite3TestTextToPtr( interp, argv[1].ToString() );
#if SQLITE_TEST
      sqlite3BtreeEnter( pCur.pBtree );
#endif
      rc = sqlite3BtreeFirst( pCur, ref res );
#if SQLITE_TEST
      sqlite3BtreeLeave( pCur.pBtree );
#endif
      if ( rc != 0 )
      {
        TCL.Tcl_AppendResult( interp, errorName( rc ), null );
        ;
        return TCL.TCL_ERROR;
      }
      sqlite3_snprintf( 100, zBuf, "%d", res );
      TCL.Tcl_AppendResult( interp, zBuf );
      return SQLITE_OK;
    }
示例#41
0
    /*
    ** Register commands with the TCL interpreter.
    */
    static public int Sqlitetest9_Init( Tcl_Interp interp )
    {
      //static struct {
      //   string zName;
      //   Tcl_ObjCmdProc *xProc;
      //   void *object;
      //}
      _aObjCmd[] aObjCmd = new _aObjCmd[]  {
new _aObjCmd( "c_misuse_test",    c_misuse_test, 0 ),
new _aObjCmd( "c_realloc_test",   c_realloc_test, 0 ),
new _aObjCmd( "c_collation_test", c_collation_test, 0 ),
};
      int i;
      for ( i = 0; i < aObjCmd.Length; i++ )
      {//sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++){
        TCL.Tcl_CreateObjCommand( interp, aObjCmd[i].zName,
        aObjCmd[i].xProc, aObjCmd[i].clientData, null );
      }
      return TCL.TCL_OK;
    }
示例#42
0
 /*
 ** Register the echo virtual table module.
 */
 static int register_echo_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;
   ;
   ;
   EchoModule pMod;
   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;
   pMod = new EchoModule();//sqlite3_malloc(sizeof(EchoModule));
   pMod.interp = interp;
   sqlite3_create_module_v2( db, "echo", echoModule, pMod, moduleDestroy );
   return TCL.TCL_OK;
 }
示例#43
0
    /*
    ** c_misuse_test
    */
    static int c_misuse_test(
    object 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 */
    )
    {
      string zErrFunction = "N/A";
      sqlite3 db = null;
      sqlite3_stmt pStmt;
      int rc;

      if ( objc != 1 )
      {
        TCL.Tcl_WrongNumArgs( interp, 1, objv, "" );
        return TCL.TCL_ERROR;
      }

      /* Open a database. Then close it again. We need to do this so that
      ** we have a "closed database handle" to pass to various API functions.
      */
      rc = sqlite3_open( ":memory:", out db );
      if ( rc != SQLITE_OK )
      {
        zErrFunction = "sqlite3_open";
        goto error_out;
      }
      sqlite3_close( db );


      rc = sqlite3_errcode( db );
      if ( rc != SQLITE_MISUSE )
      {
        zErrFunction = "sqlite3_errcode";
        goto error_out;
      }

      pStmt = new sqlite3_stmt();
      pStmt.pc = 1234;
      rc = sqlite3_prepare( db, (StringBuilder)null, 0, ref pStmt, 0 );
      if ( rc != SQLITE_MISUSE )
      {
        zErrFunction = "sqlite3_prepare";
        goto error_out;
      }
      Debug.Assert( pStmt == null ); /* Verify that pStmt is zeroed even on a MISUSE error */


      pStmt = new sqlite3_stmt();
      pStmt.pc = 1234;
      rc = sqlite3_prepare_v2( db, null, 0, ref pStmt, 0 );
      if ( rc != SQLITE_MISUSE )
      {
        zErrFunction = "sqlite3_prepare_v2";
        goto error_out;
      }
      Debug.Assert( pStmt == null );

#if !SQLITE_OMIT_UTF16
pStmt = (sqlite3_stmt)1234;
rc = sqlite3_prepare16( db, null, 0, ref pStmt, 0 );
if( rc!=SQLITE_MISUSE ){
zErrFunction = "sqlite3_prepare16";
goto error_out;
}
Debug.Assert( pStmt==0 );
pStmt = (sqlite3_stmt)1234;
rc = sqlite3_prepare16_v2( db, null, 0, ref pStmt, 0 );
if( rc!=SQLITE_MISUSE ){
zErrFunction = "sqlite3_prepare16_v2";
goto error_out;
}
Debug.Assert( pStmt==0 );
#endif

      return TCL.TCL_OK;

error_out:
      TCL.Tcl_ResetResult( interp );
      TCL.Tcl_AppendResult( interp, "Error testing function: ", zErrFunction );
      return TCL.TCL_ERROR;
    }
示例#44
0
   /*
   ** Register commands with the TCL interpreter.
   */
   static public int Sqlitetestintarray_Init( Tcl_Interp interp )
   {
     //static struct {
     //   char *zName;
     //   Tcl_ObjCmdProc *xProc;
     //   void *clientData;
     //} 
     _aObjCmd[] aObjCmd = new _aObjCmd[] {
    new _aObjCmd( "sqlite3_intarray_create", test_intarray_create, 0 ),
    new _aObjCmd(  "sqlite3_intarray_bind", test_intarray_bind, 0 ),
 };
     int i;
     for ( i = 0; i < aObjCmd.Length; i++ )//sizeof(aObjCmd)/sizeof(aObjCmd[0]); i++)
     {
       TCL.Tcl_CreateObjCommand( interp, aObjCmd[i].zName,
           aObjCmd[i].xProc, aObjCmd[i].clientData, null );
     }
     return TCL.TCL_OK;
   }
示例#45
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;
    }
示例#46
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;
    }
示例#47
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;
    }
示例#48
0
    /*
    ** c_realloc_test
    */
    static int c_realloc_test(
    object 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 */
    )
    {
      object p;
      string zErrFunction = "N/A";

      if ( objc != 1 )
      {
        TCL.Tcl_WrongNumArgs( interp, 1, objv, "" );
        return TCL.TCL_ERROR;
      }

      p = sqlite3Malloc( 5 );
      if ( p == null )
      {
        zErrFunction = "sqlite3Malloc";
        goto error_out;
      }

      /* Test that realloc()ing a block of memory to a negative size is
      ** the same as free()ing that memory.
      */
      //TODO -- ignore realloc
      //p = sqlite3_realloc(p, -1);
      //if( p!=null ){
      //  zErrFunction = "sqlite3_realloc";
      //  goto error_out;
      //}

      return TCL.TCL_OK;

error_out:
      TCL.Tcl_ResetResult( interp );
      TCL.Tcl_AppendResult( interp, "Error testing function: ", zErrFunction );
      return TCL.TCL_ERROR;
    }
示例#49
0
    /*
    ** Usage:   btree_close_cursor ID
    **
    ** Close a cursor opened using btree_cursor.
    */
    static int btree_close_cursor(
    object NotUsed,
    Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
    int argc,              /* Number of arguments */
    TclObject[] argv      /* Text of each argument */
    )
    {
      BtCursor pCur;
      Btree pBt;
      int rc;

      if ( argc != 2 )
      {
        TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0].ToString(),
        " ID\"" );
        return TCL.TCL_ERROR;
      }
      pCur = (BtCursor)sqlite3TestTextToPtr( interp, argv[1].ToString() );
      pBt = pCur.pBtree;
      sqlite3BtreeEnter( pBt );
      rc = sqlite3BtreeCloseCursor( pCur );
      sqlite3BtreeLeave( pBt );
      pCur = null;//ckfree( (char*)pCur );
      if ( rc != 0 )
      {
        TCL.Tcl_AppendResult( interp, errorName( rc ), null );
        ;
        return TCL.TCL_ERROR;
      }
      return SQLITE_OK;
    }
示例#50
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;
    }
示例#51
0
    /*
    ** Usage:   btree_eof ID
    **
    ** Return TRUE if the given cursor is not pointing at a valid entry.
    ** Return FALSE if the cursor does point to a valid entry.
    */
    //static int btree_eof(
    //  object NotUsed,
    // Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
    //  int argc,              /* Number of arguments */
    //  TclObject[] argv      /* Text of each argument */
    //){
    //  BtCursor pCur;
    //  int rc;
    //  char zBuf[50];

    //  if( argc!=2 ){
    //   TCL.Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0].ToString(),
    //       " ID\"");
    //    return TCL.TCL_ERROR;
    //  }
    //  pCur = (BtCursor)sqlite3TestTextToPtr(interp,argv[1].ToString());
    //  sqlite3BtreeEnter(pCur.pBtree);
    //  rc = sqlite3BtreeEof(pCur);
    //  sqlite3BtreeLeave(pCur.pBtree);
    //  sqlite3_snprintf(100, ref zBuf, "%d", rc);
    // TCL.Tcl_AppendResult(interp, zBuf);
    //  return SQLITE_OK;
    //}

    /*
    ** Usage:   btree_payload_size ID
    **
    ** Return the number of bytes of payload
    */
    static int btree_payload_size(
    object NotUsed,
    Tcl_Interp interp,    /* The TCL interpreter that invoked this command */
    int argc,              /* Number of arguments */
    TclObject[] argv      /* Text of each argument */
    )
    {
      BtCursor pCur;
      i64 n1 = 0;
      u32 n2 = 0;
      StringBuilder zBuf = new StringBuilder( 50 );

      if ( argc != 2 )
      {
        TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0].ToString(),
        " ID\"" );
        return TCL.TCL_ERROR;
      }
      pCur = (BtCursor)sqlite3TestTextToPtr( interp, argv[1].ToString() );
#if SQLITE_TEST
      sqlite3BtreeEnter( pCur.pBtree );
#endif

      /* The cursor may be in "require-seek" state. If this is the case, the
  ** call to BtreeDataSize() will fix it. */
      sqlite3BtreeDataSize( pCur, ref n2 );
      if ( pCur.apPage[pCur.iPage].intKey != 0 )
      {
        n1 = 0;
      }
      else
      {
        sqlite3BtreeKeySize( pCur, ref n1 );
      }
      sqlite3BtreeLeave( pCur.pBtree );
      sqlite3_snprintf( 30, zBuf, "%d", (int)( n1 + n2 ) );
      TCL.Tcl_AppendResult( interp, zBuf );
      return SQLITE_OK;
    }
示例#52
0
 public static int Sqlitetestbackup_Init( Tcl_Interp interp )
 {
   TCL.Tcl_CreateObjCommand( interp, "sqlite3_backup", backupTestInit, 0, null );
   return TCL.TCL_OK;
 }
示例#53
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 */
    )
    {
      StringBuilder zBuf = new StringBuilder( 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(), out 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, 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;
    }
示例#54
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;
    }
示例#55
0
    public static int Sqlitetest3_Init( Tcl_Interp interp )
    {
      _aCmd[] aCmd = new _aCmd[] {
new _aCmd( "btree_open",               (Tcl_CmdProc)btree_open               ),
new _aCmd( "btree_close",              (Tcl_CmdProc)btree_close              ),
new _aCmd( "btree_begin_transaction",  (Tcl_CmdProc)btree_begin_transaction  ),
new _aCmd( "btree_pager_stats",        (Tcl_CmdProc)btree_pager_stats        ),
new _aCmd( "btree_cursor",             (Tcl_CmdProc)btree_cursor             ),
new _aCmd( "btree_close_cursor",       (Tcl_CmdProc)btree_close_cursor       ),
new _aCmd( "btree_next",               (Tcl_CmdProc)btree_next               ),
//new _aCmd( "btree_eof",                (Tcl_CmdProc)btree_eof                ),
new _aCmd( "btree_payload_size",       (Tcl_CmdProc)btree_payload_size       ),
new _aCmd( "btree_first",              (Tcl_CmdProc)btree_first              ),
new _aCmd( "btree_varint_test",        (Tcl_CmdProc)btree_varint_test        ),
new _aCmd( "btree_from_db",            (Tcl_CmdProc)btree_from_db            ),
new _aCmd( "btree_ismemdb",        (Tcl_CmdProc)btree_ismemdb       ),
//new _aCmd( "btree_set_cache_size",     (Tcl_CmdProc)btree_set_cache_size     ),
};
      int i;

      for ( i = 0; i < aCmd.Length; i++ )
      { //sizeof(aCmd)/sizeof(aCmd[0]); i++){
        TCL.Tcl_CreateCommand( interp, aCmd[i].zName, aCmd[i].xProc, null, null );
      }

      return TCL.TCL_OK;
    }
示例#56
0
 /*
 ** Register the two TCL commands above with the TCL interpreter.
 */
 static public int Md5_Init( Tcl_Interp interp )
 {
   TCL.Tcl_CreateCommand( interp, "md5", md5_cmd, null, null );
   TCL.Tcl_CreateCommand( interp, "md5file", md5file_cmd, null, null );
   return TCL.TCL_OK;
 }
示例#57
0
 /*
 ** Tcl interface to sqlite3_declare_vtab, invoked as follows from Tcl:
 **
 ** sqlite3_declare_vtab DB SQL
 */
 static int declare_vtab(
   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;
   int rc;
   if ( objc != 3 )
   {
     TCL.Tcl_WrongNumArgs( interp, 1, objv, "DB SQL" );
     return TCL.TCL_ERROR;
   }
   if ( getDbPointer( interp, TCL.Tcl_GetString( objv[1] ), out db ) != 0 )
     return TCL.TCL_ERROR;
   rc = sqlite3_declare_vtab( db, TCL.Tcl_GetString( objv[2] ) );
   if ( rc != SQLITE_OK )
   {
     TCL.Tcl_SetResult( interp, sqlite3_errmsg( db ), TCL.TCL_VOLATILE );
     return TCL.TCL_ERROR;
   }
   return TCL.TCL_OK;
 }
示例#58
0
    /*
    ** A TCL command for md5.  The argument is the text to be hashed.  The
    ** Result is the hash in base64.
    */
    static int md5_cmd( object cd, Tcl_Interp interp, int argc, Tcl_Obj[] argv )
    {
      MD5Context ctx = new MD5Context();
      byte[] digest = new byte[16];
      byte[] zBuf = new byte[32];


      if ( argc != 2 )
      {
        TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0],
        " TEXT\"" );
        return TCL.TCL_ERROR;
      }
      MD5Init( ctx );
      MD5Update( ctx, Encoding.UTF8.GetBytes( argv[1].ToString() ), Encoding.UTF8.GetByteCount( argv[1].ToString() ) );
      MD5Final( digest, ctx );
      DigestToBase16( digest, zBuf );
      TCL.Tcl_AppendResult( interp, Encoding.UTF8.GetString( zBuf ) );
      return TCL.TCL_OK;
    }
示例#59
0
 /*
 ** Global Tcl variable $echo_module is a list. This routine appends
 ** the string element zArg to that list in interpreter interp.
 */
 static void appendToEchoModule( Tcl_Interp interp, string zArg )
 {
   int flags = ( TCL.TCL_APPEND_VALUE | TCL.TCL_LIST_ELEMENT | TCL.TCL_GLOBAL_ONLY );
   TCL.Tcl_SetVar( interp, "echo_module", ( zArg != null ? zArg : "" ), flags );
 }
示例#60
0
    /*
    ** A TCL command to take the md5 hash of a file.  The argument is the
    ** name of the file.
    */
    static int md5file_cmd( object cd, Tcl_Interp interp, int argc, Tcl_Obj[] argv )
    {
      StreamReader _in = null;
      byte[] digest = new byte[16];
      StringBuilder zBuf = new StringBuilder( 10240 );

      if ( argc != 2 )
      {
        TCL.Tcl_AppendResult( interp, "wrong # args: should be \"", argv[0],
        " FILENAME\"", 0 );
        return TCL.TCL_ERROR;
      }
      Debugger.Break(); // TODO --   _in = fopen( argv[1], "rb" );
      if ( _in == null )
      {
        TCL.Tcl_AppendResult( interp, "unable to open file \"", argv[1],
        "\" for reading", 0 );
        return TCL.TCL_ERROR;
      }
      Debugger.Break(); // TODO
      //MD5Init( ctx );
      //for(;;){
      //  int n;
      //  n = fread(zBuf, 1, zBuf.Capacity, _in);
      //  if( n<=0 ) break;
      //  MD5Update(ctx, zBuf.ToString(), (unsigned)n);
      //}
      //fclose(_in);
      //MD5Final(digest, ctx);
      //  DigestToBase16(digest, zBuf);
      //Tcl_AppendResult( interp, zBuf );
      return TCL.TCL_OK;
    }