Exemple #1
0
		/*
		** Make sure pMem.z points to a writable allocation of at least
		** n bytes.
		**
		** If the memory cell currently contains string or blob data
		** and the third argument passed to this function is true, the
		** current content of the cell is preserved. Otherwise, it may
		** be discarded.
		**
		** This function sets the MEM_Dyn flag and clears any xDel callback.
		** It also clears MEM_Ephem and MEM_Static. If the preserve flag is
		** not set, Mem.n is zeroed.
		*/

		private static int sqlite3VdbeMemGrow(Mem pMem, int n, int preserve)
		{
			// TODO -- What do we want to do about this routine?
			//Debug.Assert( 1 >=
			//  ((pMem.zMalloc !=null )? 1 : 0) + //&& pMem.zMalloc==pMem.z) ? 1 : 0) +
			//  (((pMem.flags & MEM_Dyn)!=0 && pMem.xDel!=null) ? 1 : 0) +
			//  ((pMem.flags & MEM_Ephem)!=0 ? 1 : 0) +
			//  ((pMem.flags & MEM_Static)!=0 ? 1 : 0)
			//);
			//assert( (pMem->flags&MEM_RowSet)==0 );

			//if( n<32 ) n = 32;
			//if( sqlite3DbMallocSize(pMem->db, pMem.zMalloc)<n ){
			if (preserve != 0)
			{//& pMem.z==pMem.zMalloc ){
				if (pMem.z == null)
					pMem.z = "";//      sqlite3DbReallocOrFree( pMem.db, pMem.z, n );
				else
					if (n < pMem.z.Length)
						pMem.z = pMem.z.Substring(0, n);
				preserve = 0;
			}
			else
			{
				//  sqlite3DbFree(pMem->db,ref pMem.zMalloc);
				pMem.z = "";//   sqlite3DbMallocRaw( pMem.db, n );
			}
			//}

			//  if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){
			// memcpy(pMem.zMalloc, pMem.z, pMem.n);
			//}
			if ((pMem.flags & MEM_Dyn) != 0 && pMem.xDel != null)
			{
				pMem.xDel(ref pMem.z);
			}

			// TODO --pMem.z = pMem.zMalloc;
			if (pMem.z == null)
			{
				pMem.flags = MEM_Null;
			}
			else
			{
				pMem.flags = (u16)(pMem.flags & ~(MEM_Ephem | MEM_Static));
			}
			pMem.xDel = null;
			return pMem.z != null ? SQLITE_OK : SQLITE_NOMEM;
		}
Exemple #2
0
		/*
		** If the memory cell contains a string value that must be freed by
		** invoking an external callback, free it now. Calling this function
		** does not free any Mem.zMalloc buffer.
		*/

		private static void sqlite3VdbeMemReleaseExternal(Mem p)
		{
			Debug.Assert(p.db == null || sqlite3_mutex_held(p.db.mutex));
			testcase(p.flags & MEM_Agg);
			testcase(p.flags & MEM_Dyn);
			testcase(p.flags & MEM_RowSet);
			testcase(p.flags & MEM_Frame);
			if ((p.flags & (MEM_Agg | MEM_Dyn | MEM_RowSet | MEM_Frame)) != 0)
			{
				if ((p.flags & MEM_Agg) != 0)
				{
					sqlite3VdbeMemFinalize(p, p.u.pDef);
					Debug.Assert((p.flags & MEM_Agg) == 0);
					sqlite3VdbeMemRelease(p);
				}
				else if ((p.flags & MEM_Dyn) != 0 && p.xDel != null)
				{
					Debug.Assert((p.flags & MEM_RowSet) == 0);
					p.xDel(ref p.z);
					p.xDel = null;
				}
				else if ((p.flags & MEM_RowSet) != 0)
				{
					sqlite3RowSetClear(p.u.pRowSet);
				}
				else if ((p.flags & MEM_Frame) != 0)
				{
					sqlite3VdbeMemSetNull(p);
				}
			}
			p.n = 0;
			p.z = null;
			p.zBLOB = null;
		}
Exemple #3
0
 /*
 ** If the memory cell contains a string value that must be freed by
 ** invoking an external callback, free it now. Calling this function
 ** does not free any Mem.zMalloc buffer.
 */
 static void sqlite3VdbeMemReleaseExternal( ref Mem p )
 {
   Debug.Assert( p.db == null || sqlite3_mutex_held( p.db.mutex ) );
   if ( ( p.flags & ( MEM_Agg | MEM_Dyn | MEM_RowSet ) ) != 0 )
   {
     if ( ( p.flags & MEM_Agg ) != 0 )
     {
       sqlite3VdbeMemFinalize( ref p, p.upDef );
       Debug.Assert( ( p.flags & MEM_Agg ) == 0 );
       sqlite3VdbeMemRelease( ref p );
     }
     else if ( ( p.flags & MEM_Dyn ) != 0 && p.xDel != null )
     {
       Debug.Assert( ( p.flags & MEM_RowSet ) == 0 );
       p.xDel( ref p.z );
       p.xDel = null;
     }
     else if ( ( p.flags & MEM_RowSet ) != 0 )
     {
       sqlite3RowSetClear( p.upRowSet );
     }
   }
   p.n = 0;
   p.z = null;
   p.zBLOB = null;
   //
   // Release additional C# pointers for backlinks
   p._Mem = null;
   p._SumCtx = null;
   p._MD5Context = null;
 }