示例#1
0
文件: rowset_c.cs 项目: cyecp/GF.Core
        /*
        ** Check to see if element iRowid was inserted into the the rowset as
        ** part of any insert batch prior to iBatch.  Return 1 or 0.
        */
        static int sqlite3RowSetTest(RowSet pRowSet, u8 iBatch, sqlite3_int64 iRowid)
        {
            RowSetEntry p;

            if (iBatch != pRowSet.iBatch)
            {
                if (pRowSet.pEntry != null)
                {
                    rowSetToList(pRowSet);
                    pRowSet.pTree  = rowSetListToTree(pRowSet.pEntry);
                    pRowSet.pEntry = null;
                    pRowSet.pLast  = null;
                }
                pRowSet.iBatch = iBatch;
            }
            p = pRowSet.pTree;
            while (p != null)
            {
                if (p.v < iRowid)
                {
                    p = p.pRight;
                }
                else if (p.v > iRowid)
                {
                    p = p.pLeft;
                }
                else
                {
                    return(1);
                }
            }
            return(0);
        }
示例#2
0
    /*
** Deprecated external interface.  Internal/core SQLite code
** should call sqlite3MemoryAlarm.
*/
    static int sqlite3_memory_alarm(
    dxalarmCallback xCallback, //void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
    object pArg,
    sqlite3_int64 iThreshold
    )
    {
      return sqlite3MemoryAlarm( xCallback, pArg, iThreshold );
    }
示例#3
0
        /*
        ** This callback is invoked once for each index when reading the
        ** sqlite_stat1 table.
        **
        **     argv[0] = name of the table
        **     argv[1] = name of the index (might be NULL)
        **     argv[2] = results of analysis - on integer for each column
        **
        ** Entries for which argv[1]==NULL simply record the number of rows in
        ** the table.
        */
        static int analysisLoader(object pData, sqlite3_int64 argc, object Oargv, object NotUsed)
        {
            string[]     argv  = (string[])Oargv;
            analysisInfo pInfo = (analysisInfo)pData;
            Index        pIndex;
            Table        pTable;
            int          i, c, n;
            int          v;
            string       z;

            Debug.Assert(argc == 3);
            UNUSED_PARAMETER2(NotUsed, argc);
            if (argv == null || argv[0] == null || argv[2] == null)
            {
                return(0);
            }
            pTable = sqlite3FindTable(pInfo.db, argv[0], pInfo.zDatabase);
            if (pTable == null)
            {
                return(0);
            }
            if (!String.IsNullOrEmpty(argv[1]))
            {
                pIndex = sqlite3FindIndex(pInfo.db, argv[1], pInfo.zDatabase);
            }
            else
            {
                pIndex = null;
            }

            n = pIndex != null ? pIndex.nColumn : 0;
            z = argv[2];
            int zIndex = 0;

            for (i = 0; z != null && i <= n; i++)
            {
                v = 0;
                while (zIndex < z.Length && (c = z[zIndex]) >= '0' && c <= '9')
                {
                    v = v * 10 + c - '0';
                    zIndex++;
                }
                if (i == 0)
                {
                    pTable.nRowEst = (uint)v;
                }
                if (pIndex == null)
                {
                    break;
                }
                pIndex.aiRowEst[i] = v;
                if (zIndex < z.Length && z[zIndex] == ' ')
                {
                    zIndex++;
                }
            }
            return(0);
        }
示例#4
0
    /*
    ** 2001 September 15
    **
    ** 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.
    **
    *************************************************************************
    **
    ** Memory allocation functions used throughout sqlite.
    *************************************************************************
    **  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 "sqliteInt.h"
    //#include <stdarg.h>

    /*
    ** This routine runs when the memory allocator sees that the
    ** total memory allocation is about to exceed the soft heap
    ** limit.
    */

    static void softHeapLimitEnforcer(
      object NotUsed,
      sqlite3_int64 NotUsed2,
      int allocSize
    )
    {
      UNUSED_PARAMETER2( NotUsed, NotUsed2 );
      sqlite3_release_memory( allocSize );
    }
示例#5
0
        /*
        ** Write data to the file.
        */
        static int memjrnlWrite(
            sqlite3_file pJfd,  /* The journal file into which to write */
            byte[] zBuf,        /* Take data to be written from here */
            int iAmt,           /* Number of bytes to write */
            sqlite3_int64 iOfst /* Begin writing at this offset into the file */
            )
        {
            MemJournal p      = (MemJournal)pJfd;
            int        nWrite = iAmt;

            byte[] zWrite  = zBuf;
            int    izWrite = 0;

            /* An in-memory journal file should only ever be appended to. Random
            ** access writes are not required by sqlite.
            */
            Debug.Assert(iOfst == p.endpoint.iOffset);
            UNUSED_PARAMETER(iOfst);

            while (nWrite > 0)
            {
                FileChunk pChunk       = p.endpoint.pChunk;
                int       iChunkOffset = (int)(p.endpoint.iOffset % JOURNAL_CHUNKSIZE);
                int       iSpace       = MIN(nWrite, JOURNAL_CHUNKSIZE - iChunkOffset);

                if (iChunkOffset == 0)
                {
                    /* New chunk is required to extend the file. */
                    FileChunk pNew = new FileChunk();// sqlite3_malloc( sizeof( FileChunk ) );
                    if (null == pNew)
                    {
                        return(SQLITE_IOERR_NOMEM);
                    }
                    pNew.pNext = null;
                    if (pChunk != null)
                    {
                        Debug.Assert(p.pFirst != null);
                        pChunk.pNext = pNew;
                    }
                    else
                    {
                        Debug.Assert(null == p.pFirst);
                        p.pFirst = pNew;
                    }
                    p.endpoint.pChunk = pNew;
                }

                Buffer.BlockCopy(zWrite, izWrite, p.endpoint.pChunk.zChunk, iChunkOffset, iSpace); //memcpy( &p.endpoint.pChunk.zChunk[iChunkOffset], zWrite, iSpace );
                izWrite            += iSpace;                                                      //zWrite += iSpace;
                nWrite             -= iSpace;
                p.endpoint.iOffset += iSpace;
            }

            return(SQLITE_OK);
        }
示例#6
0
 public Mem0Global( int nScratchFree, int nPageFree, sqlite3_mutex mutex, sqlite3_int64 alarmThreshold, dxalarmCallback alarmCallback, object alarmArg, int alarmBusy, int[] aScratchFree, int[] aPageFree )
 {
   this.nScratchFree = nScratchFree;
   this.nPageFree = nPageFree;
   this.mutex = mutex;
   this.alarmThreshold = alarmThreshold;
   this.alarmCallback = alarmCallback;
   this.alarmArg = alarmArg;
   this.alarmBusy = alarmBusy;
   this.aScratchFree = aScratchFree;
   this.aPageFree = aPageFree;
 }
示例#7
0
 /*
 ** Change the alarm callback
 */
 static int sqlite3MemoryAlarm(
     dxalarmCallback xCallback, //void(*xCallback)(void pArg, sqlite3_int64 used,int N),
     object pArg,
   sqlite3_int64 iThreshold
 )
 {
   sqlite3_mutex_enter( mem0.mutex );
   mem0.alarmCallback = xCallback;
   mem0.alarmArg = pArg;
   mem0.alarmThreshold = iThreshold;
   sqlite3_mutex_leave( mem0.mutex );
   return SQLITE_OK;
 }
示例#8
0
        /*
        ** Read data from the in-memory journal file.  This is the implementation
        ** of the sqlite3_vfs.xRead method.
        */
        static int memjrnlRead(
            sqlite3_file pJfd,  /* The journal file from which to read */
            byte[] zBuf,        /* Put the results here */
            int iAmt,           /* Number of bytes to read */
            sqlite3_int64 iOfst /* Begin reading at this offset */
            )
        {
            MemJournal p = (MemJournal)pJfd;

            byte[]    zOut  = zBuf;
            int       nRead = iAmt;
            int       iChunkOffset;
            FileChunk pChunk;

            /* SQLite never tries to read past the end of a rollback journal file */
            Debug.Assert(iOfst + iAmt <= p.endpoint.iOffset);

            if (p.readpoint.iOffset != iOfst || iOfst == 0)
            {
                int iOff = 0;
                for (pChunk = p.pFirst;
                     ALWAYS(pChunk != null) && (iOff + JOURNAL_CHUNKSIZE) <= iOfst;
                     pChunk = pChunk.pNext
                     )
                {
                    iOff += JOURNAL_CHUNKSIZE;
                }
            }
            else
            {
                pChunk = p.readpoint.pChunk;
            }

            iChunkOffset = (int)(iOfst % JOURNAL_CHUNKSIZE);
            int izOut = 0;

            do
            {
                int iSpace = JOURNAL_CHUNKSIZE - iChunkOffset;
                int nCopy  = MIN(nRead, (JOURNAL_CHUNKSIZE - iChunkOffset));
                Buffer.BlockCopy(pChunk.zChunk, iChunkOffset, zOut, izOut, nCopy); //memcpy( zOut, pChunk.zChunk[iChunkOffset], nCopy );
                izOut       += nCopy;                                              // zOut += nCopy;
                nRead       -= iSpace;
                iChunkOffset = 0;
            } while (nRead >= 0 && (pChunk = pChunk.pNext) != null && nRead > 0);
            p.readpoint.iOffset = (int)(iOfst + iAmt);
            p.readpoint.pChunk  = pChunk;

            return(SQLITE_OK);
        }
示例#9
0
        /*
        ** Truncate the file.
        */
        static int memjrnlTruncate(sqlite3_file pJfd, sqlite3_int64 size)
        {
            MemJournal p = (MemJournal)pJfd;
            FileChunk  pChunk;

            Debug.Assert(size == 0);
            UNUSED_PARAMETER(size);
            pChunk = p.pFirst;
            while (pChunk != null)
            {
                FileChunk pTmp = pChunk;
                pChunk = pChunk.pNext;
                //sqlite3_free( ref pTmp );
            }
            sqlite3MemJournalOpen(pJfd);
            return(SQLITE_OK);
        }
示例#10
0
 public Mem0Global( int nScratchFree, int nPageFree, sqlite3_mutex mutex, sqlite3_int64 alarmThreshold, dxalarmCallback alarmCallback, object alarmArg, int Byte_Allocation, int Int_Allocation, int Mem_Allocation, int BtCursor_Allocation )
 {
   this.nScratchFree = nScratchFree;
   this.nPageFree = nPageFree;
   this.mutex = mutex;
   this.alarmThreshold = alarmThreshold;
   this.alarmCallback = alarmCallback;
   this.alarmArg = alarmArg;
   this.msByte.next = -1;
   this.msInt.next = -1;
   this.msMem.next = -1;
   this.aByteSize = new int[] { 32, 256, 1024, 8192, 0 };
   this.aByte_used = new int[] { -1, -1, -1, -1, -1 };
   this.aByte = new byte[this.aByteSize.Length][][];
   for ( int i = 0; i < this.aByteSize.Length; i++ ) this.aByte[i] = new byte[Byte_Allocation][];
   this.aInt = new int[Int_Allocation][];
   this.aMem = new Mem[Mem_Allocation <= 4 ? 4 : Mem_Allocation];
   this.aBtCursor = new BtCursor[BtCursor_Allocation <= 4 ? 4 : BtCursor_Allocation];
 }
示例#11
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);
        }
示例#12
0
        /*
        ** This callback is invoked once for each index when reading the
        ** sqlite_stat1 table.
        **
        **     argv[0] = name of the index
        **     argv[1] = results of analysis - on integer for each column
        */
        static int analysisLoader(object pData, sqlite3_int64 argc, object Oargv, object NotUsed)
        {
            string[]     argv  = (string[])Oargv;
            analysisInfo pInfo = (analysisInfo)pData;
            Index        pIndex;
            int          i, c;
            int          v;
            string       z;

            Debug.Assert(argc == 2);
            UNUSED_PARAMETER2(NotUsed, argc);
            if (argv == null || argv[0] == null || argv[1] == null)
            {
                return(0);
            }
            pIndex = sqlite3FindIndex(pInfo.db, argv[0], pInfo.zDatabase);
            if (pIndex == null)
            {
                return(0);
            }
            z = argv[1];
            int zIndex = 0;

            for (i = 0; z != null && i <= pIndex.nColumn; i++)
            {
                v = 0;
                while (zIndex < z.Length && (c = z[zIndex]) >= '0' && c <= '9')
                {
                    v = v * 10 + c - '0';
                    zIndex++;
                }
                pIndex.aiRowEst[i] = v;
                if (zIndex < z.Length && z[zIndex] == ' ')
                {
                    zIndex++;
                }
            }
            return(0);
        }
示例#13
0
    /*
    ** Read data from the in-memory journal file.  This is the implementation
    ** of the sqlite3_vfs.xRead method.
    */
    static int memjrnlRead(
    sqlite3_file pJfd,     /* The journal file from which to read */
    byte[] zBuf,           /* Put the results here */
    int iAmt,              /* Number of bytes to read */
    sqlite3_int64 iOfst    /* Begin reading at this offset */
    )
    {
      MemJournal p = (MemJournal)pJfd;
      byte[] zOut = zBuf;
      int nRead = iAmt;
      int iChunkOffset;
      FileChunk pChunk;

      /* SQLite never tries to read past the end of a rollback journal file */
      Debug.Assert( iOfst + iAmt <= p.endpoint.iOffset );

      if ( p.readpoint.iOffset != iOfst || iOfst == 0 )
      {
        int iOff = 0;
        for ( pChunk = p.pFirst;
        ALWAYS( pChunk != null ) && ( iOff + JOURNAL_CHUNKSIZE ) <= iOfst;
        pChunk = pChunk.pNext
        )
        {
          iOff += JOURNAL_CHUNKSIZE;
        }
      }
      else
      {
        pChunk = p.readpoint.pChunk;
      }

      iChunkOffset = (int)( iOfst % JOURNAL_CHUNKSIZE );
      int izOut = 0;
      do
      {
        int iSpace = JOURNAL_CHUNKSIZE - iChunkOffset;
        int nCopy = MIN( nRead, ( JOURNAL_CHUNKSIZE - iChunkOffset ) );
        Buffer.BlockCopy( pChunk.zChunk, iChunkOffset, zOut, izOut, nCopy ); //memcpy( zOut, pChunk.zChunk[iChunkOffset], nCopy );
        izOut += nCopy;// zOut += nCopy;
        nRead -= iSpace;
        iChunkOffset = 0;
      } while ( nRead >= 0 && ( pChunk = pChunk.pNext ) != null && nRead > 0 );
      p.readpoint.iOffset = (int)( iOfst + iAmt );
      p.readpoint.pChunk = pChunk;

      return SQLITE_OK;
    }
示例#14
0
/*
** This callback is invoked once for each index when reading the
** sqlite_stat1 table.  
**
**     argv[0] = name of the table
**     argv[1] = name of the index (might be NULL)
**     argv[2] = results of analysis - on integer for each column
**
** Entries for which argv[1]==NULL simply record the number of rows in
** the table.
*/
static int analysisLoader( object pData, sqlite3_int64 argc, object Oargv, object NotUsed )
{
  string[] argv = (string[])Oargv;
  analysisInfo pInfo = (analysisInfo)pData;
  Index pIndex;
  Table pTable;
  int i, c, n;
  int v;
  string z;

  Debug.Assert( argc == 3 );
  UNUSED_PARAMETER2( NotUsed, argc );
  if ( argv == null || argv[0] == null || argv[2] == null )
  {
    return 0;
  }
  pTable = sqlite3FindTable( pInfo.db, argv[0], pInfo.zDatabase );
  if ( pTable == null )
  {
    return 0;
  }
  if ( !String.IsNullOrEmpty( argv[1] ) )
  {
    pIndex = sqlite3FindIndex( pInfo.db, argv[1], pInfo.zDatabase );
  }
  else
  {
    pIndex = null;
  }

  n = pIndex != null ? pIndex.nColumn : 0;
  z = argv[2];
  int zIndex = 0;
  for ( i = 0; z != null && i <= n; i++ )
  {
    v = 0;
    while ( zIndex < z.Length && ( c = z[zIndex] ) >= '0' && c <= '9' )
    {
      v = v * 10 + c - '0';
      zIndex++;
    }
    if ( i == 0 )
      pTable.nRowEst = (uint)v;
    if ( pIndex == null )
      break;
    pIndex.aiRowEst[i] = v;
    if ( zIndex < z.Length && z[zIndex] == ' ' )
      zIndex++;
    if ( z.Substring(zIndex).CompareTo("unordered")==0)//memcmp( z, "unordered", 10 ) == 0 )
    {
      pIndex.bUnordered = 1;
      break;
    }
  }
  return 0;
}
示例#15
0
 /*
 ** Check to see if element iRowid was inserted into the the rowset as
 ** part of any insert batch prior to iBatch.  Return 1 or 0.
 */
 static int sqlite3RowSetTest( RowSet pRowSet, u8 iBatch, sqlite3_int64 iRowid )
 {
   RowSetEntry p;
   if ( iBatch != pRowSet.iBatch )
   {
     if ( pRowSet.pEntry != null )
     {
       rowSetToList( pRowSet );
       pRowSet.pTree = rowSetListToTree( pRowSet.pEntry );
       pRowSet.pEntry = null;
       pRowSet.pLast = null;
     }
     pRowSet.iBatch = iBatch;
   }
   p = pRowSet.pTree;
   while ( p != null )
   {
     if ( p.v < iRowid )
     {
       p = p.pRight;
     }
     else if ( p.v > iRowid )
     {
       p = p.pLeft;
     }
     else
     {
       return 1;
     }
   }
   return 0;
 }
示例#16
0
    /*
    ** This callback is invoked once for each index when reading the
    ** sqlite_stat1 table.
    **
    **     argv[0] = name of the index
    **     argv[1] = results of analysis - on integer for each column
    */
    static int analysisLoader( object pData, sqlite3_int64 argc, object Oargv, object NotUsed )
    {
      string[] argv = (string[])Oargv;
      analysisInfo pInfo = (analysisInfo)pData;
      Index pIndex;
      int i, c;
      int v;
      string z;

      Debug.Assert( argc == 2 );
      UNUSED_PARAMETER2( NotUsed, argc );
      if ( argv == null || argv[0] == null || argv[1] == null )
      {
        return 0;
      }
      pIndex = sqlite3FindIndex( pInfo.db, argv[0], pInfo.zDatabase );
      if ( pIndex == null )
      {
        return 0;
      }
      z = argv[1];
      int zIndex = 0;
      for ( i = 0 ; z != null && i <= pIndex.nColumn ; i++ )
      {
        v = 0;
        while ( zIndex < z.Length && ( c = z[zIndex] ) >= '0' && c <= '9' )
        {
          v = v * 10 + c - '0';
          zIndex++;
        }
        pIndex.aiRowEst[i] = v;
        if ( zIndex < z.Length && z[zIndex] == ' ' ) zIndex++;
      }
      return 0;
    }
示例#17
0
/*
** File control method. For custom operations on an tvfs-file.
*/
static int tvfsFileControl( sqlite3_file pFile, int op, ref sqlite3_int64 pArg )
{
  TestvfsFd p = tvfsGetFd(pFile);
  return sqlite3OsFileControl( p.pReal, (u32)op, ref pArg );
}
示例#18
0
    /*
** Deprecated external interface.  Internal/core SQLite code
** should call sqlite3MemoryAlarm.
*/
    static int sqlite3_memory_alarm(
    dxalarmCallback xCallback, //void(*xCallback)(void *pArg, sqlite3_int64 used,int N),
    object pArg,
    sqlite3_int64 iThreshold
    )
    {
      return sqlite3MemoryAlarm( xCallback, pArg, iThreshold );
    }
示例#19
0
 /*
 ** Truncate the file.
 */
 static int memjrnlTruncate( sqlite3_file pJfd, sqlite3_int64 size )
 {
   MemJournal p = (MemJournal)pJfd;
   FileChunk pChunk;
   Debug.Assert( size == 0 );
   UNUSED_PARAMETER( size );
   pChunk = p.pFirst;
   while ( pChunk != null )
   {
     ////FileChunk pTmp = pChunk;
     pChunk = pChunk.pNext;
     //sqlite3_free( ref pTmp );
   }
   sqlite3MemJournalOpen( pJfd );
   return SQLITE_OK;
 }
示例#20
0
 public static extern ResultCode sqlite3_bind_int64(sqlite3_stmt pStmt, int index, sqlite3_int64 value);
示例#21
0
 /*
 ** Bind a new array array of integers to a specific intarray object.
 **
 ** The array of integers bound must be unchanged for the duration of
 ** any query against the corresponding virtual table.  If the integer
 ** array does change or is deallocated undefined behavior will result.
 */
 static int sqlite3_intarray_bind(
   sqlite3_intarray pIntArray,    /* The intarray object to bind to */
   int nElements,                 /* Number of elements in the intarray */
   sqlite3_int64[] aElements,     /* Content of the intarray */
   dxFree xFree//void (*xFree)(void*)           /* How to dispose of the intarray when done */
 )
 {
   if ( pIntArray.xFree != null )
   {
     pIntArray.a = null;//pIntArray.xFree( pIntArray.a );
   }
   pIntArray.n = nElements;
   pIntArray.a = aElements;
   pIntArray.xFree = xFree;
   return SQLITE_OK;
 }
示例#22
0
 public Mem0Global( int nScratchFree, int nPageFree, sqlite3_mutex mutex, sqlite3_int64 alarmThreshold, dxalarmCallback alarmCallback, object alarmArg, int alarmBusy, int[] aScratchFree, int[] aPageFree )
 {
   this.nScratchFree = nScratchFree;
   this.nPageFree = nPageFree;
   this.mutex = mutex;
   this.alarmThreshold = alarmThreshold;
   this.alarmCallback = alarmCallback;
   this.alarmArg = alarmArg;
   this.alarmBusy = alarmBusy;
   this.aScratchFree = aScratchFree;
   this.aPageFree = aPageFree;
 }
示例#23
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;
    }
示例#24
0
    /*
    ** Write data to the file.
    */
    static int memjrnlWrite(
    sqlite3_file pJfd,    /* The journal file into which to write */
    byte[] zBuf,          /* Take data to be written from here */
    int iAmt,             /* Number of bytes to write */
    sqlite3_int64 iOfst   /* Begin writing at this offset into the file */
    )
    {
      MemJournal p = (MemJournal)pJfd;
      int nWrite = iAmt;
      byte[] zWrite = zBuf;
      int izWrite = 0;

      /* An in-memory journal file should only ever be appended to. Random
      ** access writes are not required by sqlite.
      */
      Debug.Assert( iOfst == p.endpoint.iOffset );
      UNUSED_PARAMETER( iOfst );

      while ( nWrite > 0 )
      {
        FileChunk pChunk = p.endpoint.pChunk;
        int iChunkOffset = (int)( p.endpoint.iOffset % JOURNAL_CHUNKSIZE );
        int iSpace = MIN( nWrite, JOURNAL_CHUNKSIZE - iChunkOffset );

        if ( iChunkOffset == 0 )
        {
          /* New chunk is required to extend the file. */
          FileChunk pNew = new FileChunk();// sqlite3_malloc( sizeof( FileChunk ) );
          if ( null == pNew )
          {
            return SQLITE_IOERR_NOMEM;
          }
          pNew.pNext = null;
          if ( pChunk != null )
          {
            Debug.Assert( p.pFirst != null );
            pChunk.pNext = pNew;
          }
          else
          {
            Debug.Assert( null == p.pFirst );
            p.pFirst = pNew;
          }
          p.endpoint.pChunk = pNew;
        }

        Buffer.BlockCopy( zWrite, izWrite, p.endpoint.pChunk.zChunk, iChunkOffset, iSpace ); //memcpy( &p.endpoint.pChunk.zChunk[iChunkOffset], zWrite, iSpace );
        izWrite += iSpace;//zWrite += iSpace;
        nWrite -= iSpace;
        p.endpoint.iOffset += iSpace;
      }

      return SQLITE_OK;
    }
示例#25
0
    /*
    ** The callback routine for sqlite3_exec_printf().
    */
    static int exec_printf_cb( object pArg, sqlite3_int64 argc, object p2, object p3 )
    {
      string[] name = (string[])p3;
      string[] argv = (string[])p2;
      TclObject str = (TclObject)pArg;
      int i;

      if ( TCL.Tcl_DStringLength( str ) == 0 )
      {
        for ( i = 0 ; i < argc ; i++ )
        {
          TCL.Tcl_DStringAppendElement( str, name[i] != null ? name[i] + " " : "NULL " );
        }
      }
      string beginbrace = "", endbrace = "";
      for ( i = 0 ; i < argc ; i++ )
      {
        if ( argc > 1 )
        {
          if ( Util.scanElement( null, argv[i].ToString() ) != 0 )
          {
            beginbrace = "{";
            endbrace = "}";
          }
          else
          {
            beginbrace = "";
            endbrace = "";
          }
        }
        TCL.Tcl_DStringAppendElement( str, argv[i] != null ? beginbrace + argv[i] + endbrace + ( i < argc - 1 ? " " : "" ) : "NULL" );
      }
      return 0;
    }