Lines Matching defs:pMem

2194 ** 8-byte aligned memory (pMem), the size of each page cache line (sz),
2201 ** for the sz parameter to be larger than necessary. The pMem
2205 ** ^When pMem is not NULL, SQLite will strive to use the memory provided
2207 ** a page cache line is larger than sz bytes or if all of the pMem buffer
2209 ** ^If pMem is NULL and N is non-zero, then each database connection
15898 Mem *pMem; /* Used when p4type is P4_MEM */
22781 Mem *pMem; /* Memory cell used to store aggregate context */
23044 SQLITE_PRIVATE int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
23045 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int n);
23101 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr);
23105 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem);
33239 ** This routine transforms the internal text encoding used by pMem to
33241 ** encoding, or if *pMem does not contain a string value.
33243 SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemTranslate(Mem *pMem, u8 desiredEnc){
33251 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
33252 assert( pMem->flags&MEM_Str );
33253 assert( pMem->enc!=desiredEnc );
33254 assert( pMem->enc!=0 );
33255 assert( pMem->n>=0 );
33262 sqlite3VdbeMemPrettyPrint(pMem, &acc);
33271 if( pMem->enc!=SQLITE_UTF8 && desiredEnc!=SQLITE_UTF8 ){
33274 rc = sqlite3VdbeMemMakeWriteable(pMem);
33279 zIn = (u8*)pMem->z;
33280 zTerm = &zIn[pMem->n&~1];
33287 pMem->enc = desiredEnc;
33298 pMem->n &= ~1;
33299 len = 2 * (sqlite3_int64)pMem->n + 1;
33306 len = 2 * (sqlite3_int64)pMem->n + 2;
33315 zIn = (u8*)pMem->z;
33316 zTerm = &zIn[pMem->n];
33317 zOut = sqlite3DbMallocRaw(pMem->db, len);
33323 if( pMem->enc==SQLITE_UTF8 ){
33338 pMem->n = (int)(z - zOut);
33342 if( pMem->enc==SQLITE_UTF16LE ){
33401 pMem->n = (int)(z - zOut);
33404 assert( (pMem->n+(desiredEnc==SQLITE_UTF8?1:2))<=len );
33406 c = MEM_Str|MEM_Term|(pMem->flags&(MEM_AffMask|MEM_Subtype));
33407 sqlite3VdbeMemRelease(pMem);
33408 pMem->flags = c;
33409 pMem->enc = desiredEnc;
33410 pMem->z = (char*)zOut;
33411 pMem->zMalloc = pMem->z;
33412 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->z);
33420 sqlite3VdbeMemPrettyPrint(pMem, &acc);
33431 ** UTF-16 string stored in *pMem. If one is present, it is removed and
33438 SQLITE_PRIVATE int sqlite3VdbeMemHandleBom(Mem *pMem){
33442 assert( pMem->n>=0 );
33443 if( pMem->n>1 ){
33444 u8 b1 = *(u8 *)pMem->z;
33445 u8 b2 = *(((u8 *)pMem->z) + 1);
33455 rc = sqlite3VdbeMemMakeWriteable(pMem);
33457 pMem->n -= 2;
33458 memmove(pMem->z, &pMem->z[2], pMem->n);
33459 pMem->z[pMem->n] = '\0';
33460 pMem->z[pMem->n+1] = '\0';
33461 pMem->flags |= MEM_Term;
33462 pMem->enc = bom;
41719 void *pMem;
41721 pMem = osMmap(0, nMap,
41725 if( pMem==MAP_FAILED ){
41730 pMem = sqlite3_malloc64(nMap);
41731 if( pMem==0 ){
41735 memset(pMem, 0, nMap);
41739 pShmNode->apRegion[pShmNode->nRegion+i] = &((char*)pMem)[szRegion*i];
46367 MUTEX_LOGIC( sqlite3_mutex *pMem; ) /* The memsys static mutex */
46369 MUTEX_LOGIC( pMem = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MEM); )
46371 sqlite3_mutex_enter(pMem);
46398 sqlite3_mutex_leave(pMem);
80579 ** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
80680 ** Validity checks on pMem. pMem holds a string.
80682 ** (1) Check that string value of pMem agrees with its integer or real value.
80694 ** This routine looks at pMem to verify that if it has both a numeric
80735 ** If pMem is an object with a valid string representation, this routine
80739 ** If pMem is not a string object, or the encoding of the string
80747 SQLITE_PRIVATE int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){
80751 assert( pMem!=0 );
80752 assert( !sqlite3VdbeMemIsRowSet(pMem) );
80755 if( !(pMem->flags&MEM_Str) ){
80756 pMem->enc = desiredEnc;
80759 if( pMem->enc==desiredEnc ){
80762 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
80770 rc = sqlite3VdbeMemTranslate(pMem, (u8)desiredEnc);
80772 assert(rc==SQLITE_OK || pMem->enc!=desiredEnc);
80773 assert(rc==SQLITE_NOMEM || pMem->enc==desiredEnc);
80779 ** Make sure pMem->z points to a writable allocation of at least n bytes.
80782 ** pMem->z into the new allocation. pMem must be either a string or
80784 ** in pMem->z is discarded.
80786 SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
80787 assert( sqlite3VdbeCheckMemInvariants(pMem) );
80788 assert( !sqlite3VdbeMemIsRowSet(pMem) );
80789 testcase( pMem->db==0 );
80793 assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) );
80794 testcase( bPreserve && pMem->z==0 );
80796 assert( pMem->szMalloc==0
80797 || (pMem->flags==MEM_Undefined
80798 && pMem->szMalloc<=sqlite3DbMallocSize(pMem->db,pMem->zMalloc))
80799 || pMem->szMalloc==sqlite3DbMallocSize(pMem->db,pMem->zMalloc));
80800 if( pMem->szMalloc>0 && bPreserve && pMem->z==pMem->zMalloc ){
80801 if( pMem->db ){
80802 pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n);
80804 pMem->zMalloc = sqlite3Realloc(pMem->z, n);
80805 if( pMem->zMalloc==0 ) sqlite3_free(pMem->z);
80806 pMem->z = pMem->zMalloc;
80810 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
80811 pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n);
80813 if( pMem->zMalloc==0 ){
80814 sqlite3VdbeMemSetNull(pMem);
80815 pMem->z = 0;
80816 pMem->szMalloc = 0;
80819 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
80822 if( bPreserve && pMem->z ){
80823 assert( pMem->z!=pMem->zMalloc );
80824 memcpy(pMem->zMalloc, pMem->z, pMem->n);
80826 if( (pMem->flags&MEM_Dyn)!=0 ){
80827 assert( pMem->xDel!=0 && pMem->xDel!=SQLITE_DYNAMIC );
80828 pMem->xDel((void *)(pMem->z));
80831 pMem->z = pMem->zMalloc;
80832 pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
80837 ** Change the pMem->zMalloc allocation to be at least szNew bytes.
80838 ** If pMem->zMalloc already meets or exceeds the requested size, this
80841 ** Any prior string or blob content in the pMem object may be discarded.
80842 ** The pMem->xDel destructor is called, if it exists. Though MEM_Str
80849 SQLITE_PRIVATE int sqlite3VdbeMemClearAndResize(Mem *pMem, int szNew){
80851 assert( (pMem->flags & MEM_Dyn)==0 || pMem->szMalloc==0 );
80852 if( pMem->szMalloc<szNew ){
80853 return sqlite3VdbeMemGrow(pMem, szNew, 0);
80855 assert( (pMem->flags & MEM_Dyn)==0 );
80856 pMem->z = pMem->zMalloc;
80857 pMem->flags &= (MEM_Null|MEM_Int|MEM_Real|MEM_IntReal);
80862 ** It is already known that pMem contains an unterminated string.
80870 static SQLITE_NOINLINE int vdbeMemAddTerminator(Mem *pMem){
80871 if( sqlite3VdbeMemGrow(pMem, pMem->n+3, 1) ){
80874 pMem->z[pMem->n] = 0;
80875 pMem->z[pMem->n+1] = 0;
80876 pMem->z[pMem->n+2] = 0;
80877 pMem->flags |= MEM_Term;
80882 ** Change pMem so that its MEM_Str or MEM_Blob value is stored in
80887 SQLITE_PRIVATE int sqlite3VdbeMemMakeWriteable(Mem *pMem){
80888 assert( pMem!=0 );
80889 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
80890 assert( !sqlite3VdbeMemIsRowSet(pMem) );
80891 if( (pMem->flags & (MEM_Str|MEM_Blob))!=0 ){
80892 if( ExpandBlob(pMem) ) return SQLITE_NOMEM;
80893 if( pMem->szMalloc==0 || pMem->z!=pMem->zMalloc ){
80894 int rc = vdbeMemAddTerminator(pMem);
80898 pMem->flags &= ~MEM_Ephem;
80900 pMem->pScopyFrom = 0;
80911 SQLITE_PRIVATE int sqlite3VdbeMemExpandBlob(Mem *pMem){
80913 assert( pMem!=0 );
80914 assert( pMem->flags & MEM_Zero );
80915 assert( (pMem->flags&MEM_Blob)!=0 || MemNullNochng(pMem) );
80916 testcase( sqlite3_value_nochange(pMem) );
80917 assert( !sqlite3VdbeMemIsRowSet(pMem) );
80918 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
80921 nByte = pMem->n + pMem->u.nZero;
80923 if( (pMem->flags & MEM_Blob)==0 ) return SQLITE_OK;
80926 if( sqlite3VdbeMemGrow(pMem, nByte, 1) ){
80929 assert( pMem->z!=0 );
80930 assert( sqlite3DbMallocSize(pMem->db,pMem->z) >= nByte );
80932 memset(&pMem->z[pMem->n], 0, pMem->u.nZero);
80933 pMem->n += pMem->u.nZero;
80934 pMem->flags &= ~(MEM_Zero|MEM_Term);
80942 SQLITE_PRIVATE int sqlite3VdbeMemNulTerminate(Mem *pMem){
80943 assert( pMem!=0 );
80944 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
80945 testcase( (pMem->flags & (MEM_Term|MEM_Str))==(MEM_Term|MEM_Str) );
80946 testcase( (pMem->flags & (MEM_Term|MEM_Str))==0 );
80947 if( (pMem->flags & (MEM_Term|MEM_Str))!=MEM_Str ){
80950 return vdbeMemAddTerminator(pMem);
80956 ** routine is only called if pMem is a number of some kind, not a NULL
80968 SQLITE_PRIVATE int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){
80971 assert( pMem!=0 );
80972 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
80973 assert( !(pMem->flags&MEM_Zero) );
80974 assert( !(pMem->flags&(MEM_Str|MEM_Blob)) );
80975 assert( pMem->flags&(MEM_Int|MEM_Real|MEM_IntReal) );
80976 assert( !sqlite3VdbeMemIsRowSet(pMem) );
80977 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
80980 if( sqlite3VdbeMemClearAndResize(pMem, nByte) ){
80981 pMem->enc = 0;
80985 vdbeMemRenderNum(nByte, pMem->z, pMem);
80986 assert( pMem->z!=0 );
80987 pMem->n = sqlite3Strlen30NN(pMem->z);
80988 pMem->enc = SQLITE_UTF8;
80989 pMem->flags |= MEM_Str|MEM_Term;
80990 if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal);
80991 sqlite3VdbeChangeEncoding(pMem, enc);
80996 ** Memory cell pMem contains the context of an aggregate function.
80998 ** result of the aggregate is stored back into pMem.
81003 SQLITE_PRIVATE int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
81007 assert( pMem!=0 );
81008 assert( pMem->db!=0 );
81010 assert( (pMem->flags & MEM_Null)!=0 || pFunc==pMem->u.pDef );
81011 assert( sqlite3_mutex_held(pMem->db->mutex) );
81015 t.db = pMem->db;
81017 ctx.pMem = pMem;
81021 assert( (pMem->flags & MEM_Dyn)==0 );
81022 if( pMem->szMalloc>0 ) sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
81023 memcpy(pMem, &t, sizeof(t));
81030 ** the results in memory cell pMem.
81046 ctx.pMem = pAccum;
81154 ** at representing the value that *pMem describes as an integer.
81155 ** If pMem is an integer, then the value is exact. If pMem is
81157 ** If pMem is a string or blob, then we make an attempt to convert
81158 ** it into an integer and return that. If pMem represents an
81161 ** If pMem represents a string value, its encoding might be changed.
81163 static SQLITE_NOINLINE i64 memIntValue(const Mem *pMem){
81165 sqlite3Atoi64(pMem->z, &value, pMem->n, pMem->enc);
81168 SQLITE_PRIVATE i64 sqlite3VdbeIntValue(const Mem *pMem){
81170 assert( pMem!=0 );
81171 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81172 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
81173 flags = pMem->flags;
81176 return pMem->u.i;
81178 return doubleToInt64(pMem->u.r);
81179 }else if( (flags & (MEM_Str|MEM_Blob))!=0 && pMem->z!=0 ){
81180 return memIntValue(pMem);
81187 ** Return the best representation of pMem that we can get into a
81188 ** double. If pMem is already a double or an integer, return its
81192 static SQLITE_NOINLINE double memRealValue(Mem *pMem){
81195 sqlite3AtoF(pMem->z, &val, pMem->n, pMem->enc);
81198 SQLITE_PRIVATE double sqlite3VdbeRealValue(Mem *pMem){
81199 assert( pMem!=0 );
81200 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81201 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
81202 if( pMem->flags & MEM_Real ){
81203 return pMem->u.r;
81204 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
81205 testcase( pMem->flags & MEM_IntReal );
81206 return (double)pMem->u.i;
81207 }else if( pMem->flags & (MEM_Str|MEM_Blob) ){
81208 return memRealValue(pMem);
81216 ** Return 1 if pMem represents true, and return 0 if pMem represents false.
81217 ** Return the value ifNull if pMem is NULL.
81219 SQLITE_PRIVATE int sqlite3VdbeBooleanValue(Mem *pMem, int ifNull){
81220 testcase( pMem->flags & MEM_IntReal );
81221 if( pMem->flags & (MEM_Int|MEM_IntReal) ) return pMem->u.i!=0;
81222 if( pMem->flags & MEM_Null ) return ifNull;
81223 return sqlite3VdbeRealValue(pMem)!=0.0;
81230 SQLITE_PRIVATE void sqlite3VdbeIntegerAffinity(Mem *pMem){
81232 assert( pMem!=0 );
81233 assert( pMem->flags & MEM_Real );
81234 assert( !sqlite3VdbeMemIsRowSet(pMem) );
81235 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81236 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
81238 ix = doubleToInt64(pMem->u.r);
81250 if( pMem->u.r==ix && ix>SMALLEST_INT64 && ix<LARGEST_INT64 ){
81251 pMem->u.i = ix;
81252 MemSetTypeFlag(pMem, MEM_Int);
81257 ** Convert pMem to type integer. Invalidate any prior representations.
81259 SQLITE_PRIVATE int sqlite3VdbeMemIntegerify(Mem *pMem){
81260 assert( pMem!=0 );
81261 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81262 assert( !sqlite3VdbeMemIsRowSet(pMem) );
81263 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
81265 pMem->u.i = sqlite3VdbeIntValue(pMem);
81266 MemSetTypeFlag(pMem, MEM_Int);
81271 ** Convert pMem so that it is of type MEM_Real.
81274 SQLITE_PRIVATE int sqlite3VdbeMemRealify(Mem *pMem){
81275 assert( pMem!=0 );
81276 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81277 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
81279 pMem->u.r = sqlite3VdbeRealValue(pMem);
81280 MemSetTypeFlag(pMem, MEM_Real);
81311 ** Convert pMem so that it has type MEM_Real or MEM_Int.
81318 SQLITE_PRIVATE int sqlite3VdbeMemNumerify(Mem *pMem){
81319 assert( pMem!=0 );
81320 testcase( pMem->flags & MEM_Int );
81321 testcase( pMem->flags & MEM_Real );
81322 testcase( pMem->flags & MEM_IntReal );
81323 testcase( pMem->flags & MEM_Null );
81324 if( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))==0 ){
81327 assert( (pMem->flags & (MEM_Blob|MEM_Str))!=0 );
81328 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81329 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
81330 if( ((rc==0 || rc==1) && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1)
81331 || sqlite3RealSameAsInt(pMem->u.r, (ix = sqlite3RealToI64(pMem->u.r)))
81333 pMem->u.i = ix;
81334 MemSetTypeFlag(pMem, MEM_Int);
81336 MemSetTypeFlag(pMem, MEM_Real);
81339 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null))!=0 );
81340 pMem->flags &= ~(MEM_Str|MEM_Blob|MEM_Zero);
81345 ** Cast the datatype of the value in pMem according to the affinity
81351 SQLITE_PRIVATE int sqlite3VdbeMemCast(Mem *pMem, u8 aff, u8 encoding){
81352 if( pMem->flags & MEM_Null ) return SQLITE_OK;
81355 if( (pMem->flags & MEM_Blob)==0 ){
81356 sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding);
81357 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
81358 if( pMem->flags & MEM_Str ) MemSetTypeFlag(pMem, MEM_Blob);
81360 pMem->flags &= ~(MEM_TypeMask&~MEM_Blob);
81365 sqlite3VdbeMemNumerify(pMem);
81369 sqlite3VdbeMemIntegerify(pMem);
81373 sqlite3VdbeMemRealify(pMem);
81379 pMem->flags |= (pMem->flags&MEM_Blob)>>3;
81380 sqlite3ValueApplyAffinity(pMem, SQLITE_AFF_TEXT, encoding);
81381 assert( pMem->flags & MEM_Str || pMem->db->mallocFailed );
81382 pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal|MEM_Blob|MEM_Zero);
81383 if( encoding!=SQLITE_UTF8 ) pMem->n &= ~1;
81384 return sqlite3VdbeChangeEncoding(pMem, encoding);
81395 SQLITE_PRIVATE void sqlite3VdbeMemInit(Mem *pMem, sqlite3 *db, u16 flags){
81397 pMem->flags = flags;
81398 pMem->db = db;
81399 pMem->szMalloc = 0;
81404 ** Delete any previous value and set the value stored in *pMem to NULL.
81415 SQLITE_PRIVATE void sqlite3VdbeMemSetNull(Mem *pMem){
81416 if( VdbeMemDynamic(pMem) ){
81417 vdbeMemClearExternAndSetNull(pMem);
81419 pMem->flags = MEM_Null;
81431 SQLITE_PRIVATE void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
81432 sqlite3VdbeMemRelease(pMem);
81433 pMem->flags = MEM_Blob|MEM_Zero;
81434 pMem->n = 0;
81436 pMem->u.nZero = n;
81437 pMem->enc = SQLITE_UTF8;
81438 pMem->z = 0;
81441 SQLITE_PRIVATE int sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
81443 if( sqlite3VdbeMemGrow(pMem, nByte, 0) ){
81446 assert( pMem->z!=0 );
81447 assert( sqlite3DbMallocSize(pMem->db, pMem->z)>=nByte );
81448 memset(pMem->z, 0, nByte);
81449 pMem->n = n>0?n:0;
81450 pMem->flags = MEM_Blob;
81451 pMem->enc = SQLITE_UTF8;
81457 ** The pMem is known to contain content that needs to be destroyed prior
81461 static SQLITE_NOINLINE void vdbeReleaseAndSetInt64(Mem *pMem, i64 val){
81462 sqlite3VdbeMemSetNull(pMem);
81463 pMem->u.i = val;
81464 pMem->flags = MEM_Int;
81468 ** Delete any previous value and set the value stored in *pMem to val,
81471 SQLITE_PRIVATE void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
81472 if( VdbeMemDynamic(pMem) ){
81473 vdbeReleaseAndSetInt64(pMem, val);
81475 pMem->u.i = val;
81476 pMem->flags = MEM_Int;
81484 ** Set the value stored in *pMem should already be a NULL.
81488 Mem *pMem,
81493 assert( pMem->flags==MEM_Null );
81494 vdbeMemClear(pMem);
81495 pMem->u.zPType = zPType ? zPType : "";
81496 pMem->z = pPtr;
81497 pMem->flags = MEM_Null|MEM_Dyn|MEM_Subtype|MEM_Term;
81498 pMem->eSubtype = 'p';
81499 pMem->xDel = xDestructor ? xDestructor : sqlite3NoopDestructor;
81504 ** Delete any previous value and set the value stored in *pMem to val,
81507 SQLITE_PRIVATE void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
81508 sqlite3VdbeMemSetNull(pMem);
81510 pMem->u.r = val;
81511 pMem->flags = MEM_Real;
81521 SQLITE_PRIVATE int sqlite3VdbeMemIsRowSet(const Mem *pMem){
81522 return (pMem->flags&(MEM_Blob|MEM_Dyn))==(MEM_Blob|MEM_Dyn)
81523 && pMem->xDel==sqlite3RowSetDelete;
81528 ** Delete any previous value and set the value of pMem to be an
81534 SQLITE_PRIVATE int sqlite3VdbeMemSetRowSet(Mem *pMem){
81535 sqlite3 *db = pMem->db;
81538 assert( !sqlite3VdbeMemIsRowSet(pMem) );
81539 sqlite3VdbeMemRelease(pMem);
81542 pMem->z = (char*)p;
81543 pMem->flags = MEM_Blob|MEM_Dyn;
81544 pMem->xDel = sqlite3RowSetDelete;
81573 SQLITE_PRIVATE void sqlite3VdbeMemAboutToChange(Vdbe *pVdbe, Mem *pMem){
81577 if( pX->pScopyFrom==pMem ){
81581 (int)(pX - pVdbe->aMem), (int)(pMem - pVdbe->aMem));
81583 /* If pX is marked as a shallow copy of pMem, then try to verify that
81589 mFlags = pMem->flags & pX->flags & pX->mScopyFlags;
81590 assert( (mFlags&(MEM_Int|MEM_IntReal))==0 || pMem->u.i==pX->u.i );
81592 /* pMem is the register that is changing. But also mark pX as
81598 pMem->pScopyFrom = 0;
81675 ** is required to store the string, then value of pMem is unchanged. In
81686 Mem *pMem, /* Memory cell to set to string value */
81692 i64 nByte = n; /* New value for pMem->n */
81694 u16 flags; /* New value for pMem->flags */
81696 assert( pMem!=0 );
81697 assert( pMem->db==0 || sqlite3_mutex_held(pMem->db->mutex) );
81698 assert( !sqlite3VdbeMemIsRowSet(pMem) );
81701 /* If z is a NULL pointer, set pMem to contain an SQL NULL. */
81703 sqlite3VdbeMemSetNull(pMem);
81707 if( pMem->db ){
81708 iLimit = pMem->db->aLimit[SQLITE_LIMIT_LENGTH];
81729 sqlite3DbFree(pMem->db, (void*)z);
81734 sqlite3VdbeMemSetNull(pMem);
81735 return sqlite3ErrorToParser(pMem->db, SQLITE_TOOBIG);
81750 if( sqlite3VdbeMemClearAndResize(pMem, (int)MAX(nAlloc,32)) ){
81753 memcpy(pMem->z, z, nAlloc);
81755 sqlite3VdbeMemRelease(pMem);
81756 pMem->z = (char *)z;
81758 pMem->zMalloc = pMem->z;
81759 pMem->szMalloc = sqlite3DbMallocSize(pMem->db, pMem->zMalloc);
81761 pMem->xDel = xDel;
81766 pMem->n = (int)(nByte & 0x7fffffff);
81767 pMem->flags = flags;
81768 pMem->enc = enc;
81771 if( enc>SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
81784 ** The result is written into the pMem element.
81786 ** The pMem object must have been initialized. This routine will use
81787 ** pMem->zMalloc to hold the content from the btree, if possible. New
81788 ** pMem->zMalloc space will be allocated if necessary. The calling routine
81789 ** is responsible for making sure that the pMem object is eventually
81793 ** to read from the disk) then the pMem is left in an inconsistent state.
81799 Mem *pMem /* OUT: Return data in this Mem structure. */
81802 pMem->flags = MEM_Null;
81806 if( SQLITE_OK==(rc = sqlite3VdbeMemClearAndResize(pMem, amt+1)) ){
81807 rc = sqlite3BtreePayload(pCur, offset, amt, pMem->z);
81809 pMem->z[amt] = 0; /* Overrun area used when reading malformed records */
81810 pMem->flags = MEM_Blob;
81811 pMem->n = (int)amt;
81813 sqlite3VdbeMemRelease(pMem);
81821 Mem *pMem /* OUT: Return data in this Mem structure. */
81827 assert( !VdbeMemDynamic(pMem) );
81831 assert( !sqlite3VdbeMemIsRowSet(pMem) );
81832 pMem->z = (char *)sqlite3BtreePayloadFetch(pCur, &available);
81833 assert( pMem->z!=0 );
81836 pMem->flags = MEM_Blob|MEM_Ephem;
81837 pMem->n = (int)amt;
81839 rc = sqlite3VdbeMemFromBtree(pCur, 0, amt, pMem);
82437 Mem *pMem = *ppVal; /* Write result into this Mem object */
82454 if( pMem==0 ){
82455 pMem = *ppVal = sqlite3ValueNew(db);
82456 if( pMem==0 ) return SQLITE_NOMEM_BKPT;
82458 sqlite3VdbeSerialGet(&a[iField-szField], t, pMem);
82459 pMem->enc = ENC(db);
84343 Mem *pMem = pOp->p4.pMem;
84344 if( pMem->flags & MEM_Str ){
84345 zP4 = pMem->z;
84346 }else if( pMem->flags & (MEM_Int|MEM_IntReal) ){
84347 sqlite3_str_appendf(&x, "%lld", pMem->u.i);
84348 }else if( pMem->flags & MEM_Real ){
84349 sqlite3_str_appendf(&x, "%.16g", pMem->u.r);
84350 }else if( pMem->flags & MEM_Null ){
84353 assert( pMem->flags & MEM_Blob );
84779 Mem *pMem = &p->aMem[1]; /* First Mem of result set */
84792 releaseMemArray(pMem, 8);
84825 sqlite3VdbeMemSetInt64(pMem, pOp->p1);
84826 sqlite3VdbeMemSetInt64(pMem+1, pOp->p2);
84827 sqlite3VdbeMemSetInt64(pMem+2, pOp->p3);
84828 sqlite3VdbeMemSetStr(pMem+3, zP4, -1, SQLITE_UTF8, sqlite3_free);
84831 sqlite3VdbeMemSetInt64(pMem+0, i);
84832 sqlite3VdbeMemSetStr(pMem+1, (char*)sqlite3OpcodeName(pOp->opcode),
84834 sqlite3VdbeMemSetInt64(pMem+2, pOp->p1);
84835 sqlite3VdbeMemSetInt64(pMem+3, pOp->p2);
84836 sqlite3VdbeMemSetInt64(pMem+4, pOp->p3);
84837 /* pMem+5 for p4 is done last */
84838 sqlite3VdbeMemSetInt64(pMem+6, pOp->p5);
84842 sqlite3VdbeMemSetStr(pMem+7, zCom, -1, SQLITE_UTF8, sqlite3_free);
84845 sqlite3VdbeMemSetNull(pMem+7);
84847 sqlite3VdbeMemSetStr(pMem+5, zP4, -1, SQLITE_UTF8, sqlite3_free);
84850 p->pResultSet = pMem;
86258 ** Return the serial-type for the value stored in pMem.
86268 SQLITE_PRIVATE u32 sqlite3VdbeSerialType(Mem *pMem, int file_format, u32 *pLen){
86269 int flags = pMem->flags;
86280 i64 i = pMem->u.i;
86307 pMem->u.r = (double)pMem->u.i;
86308 pMem->flags &= ~MEM_IntReal;
86309 pMem->flags |= MEM_Real;
86318 assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );
86319 assert( pMem->n>=0 );
86320 n = (u32)pMem->n;
86322 n += pMem->u.nZero;
86428 ** and store the result in pMem.
86438 Mem *pMem /* Memory cell to write value into */
86446 pMem->u.i = *(i64*)&x;
86447 pMem->flags = MEM_Int;
86448 testcase( pMem->u.i<0 );
86464 assert( sizeof(x)==8 && sizeof(pMem->u.r)==8 );
86466 memcpy(&pMem->u.r, &x, sizeof(x));
86467 pMem->flags = IsNaN(x) ? MEM_Null : MEM_Real;
86473 Mem *pMem /* Memory cell to write value into */
86478 pMem->flags = MEM_Null|MEM_Zero;
86479 pMem->n = 0;
86480 pMem->u.nZero = 0;
86486 pMem->flags = MEM_Null;
86492 pMem->u.i = ONE_BYTE_INT(buf);
86493 pMem->flags = MEM_Int;
86494 testcase( pMem->u.i<0 );
86500 pMem->u.i = TWO_BYTE_INT(buf);
86501 pMem->flags = MEM_Int;
86502 testcase( pMem->u.i<0 );
86508 pMem->u.i = THREE_BYTE_INT(buf);
86509 pMem->flags = MEM_Int;
86510 testcase( pMem->u.i<0 );
86516 pMem->u.i = FOUR_BYTE_INT(buf);
86519 if( buf[0]&0x80 ) pMem->u.i |= 0xffffffff80000000LL;
86521 pMem->flags = MEM_Int;
86522 testcase( pMem->u.i<0 );
86528 pMem->u.i = FOUR_BYTE_UINT(buf+2) + (((i64)1)<<32)*TWO_BYTE_INT(buf);
86529 pMem->flags = MEM_Int;
86530 testcase( pMem->u.i<0 );
86537 serialGet(buf,serial_type,pMem);
86544 pMem->u.i = serial_type-8;
86545 pMem->flags = MEM_Int;
86554 pMem->z = (char *)buf;
86555 pMem->n = (serial_type-12)/2;
86556 pMem->flags = aFlag[serial_type&1];
86607 Mem *pMem = p->aMem;
86610 assert( EIGHT_BYTE_ALIGNMENT(pMem) );
86618 pMem->enc = pKeyInfo->enc;
86619 pMem->db = pKeyInfo->db;
86620 /* pMem->flags = 0; // sqlite3VdbeSerialGet() will set this for us */
86621 pMem->szMalloc = 0;
86622 pMem->z = 0;
86623 sqlite3VdbeSerialGet(&aKey[d], serial_type, pMem);
86625 pMem++;
86630 /* In a corrupt record entry, the last pMem might have been set up using
86633 sqlite3VdbeMemSetNull(pMem-1);
87687 Mem *pMem = &v->aVar[iVar-1];
87689 if( 0==(pMem->flags & MEM_Null) ){
87692 sqlite3VdbeMemCopy((Mem *)pRet, pMem);
87782 Mem *pMem = &p->aMem[i];
87783 if( pMem->zMalloc ) sqlite3VdbeMemReleaseMalloc(pMem);
88065 Mem *pMem = (Mem*)pVal;
88066 return ((pMem->flags & MEM_Subtype) ? pMem->eSubtype : 0);
88871 ** its pMem->z element.
88874 Mem *pMem = p->pMem;
88875 assert( (pMem->flags & MEM_Agg)==0 );
88877 sqlite3VdbeMemSetNull(pMem);
88878 pMem->z = 0;
88880 sqlite3VdbeMemClearAndResize(pMem, nByte);
88881 pMem->flags = MEM_Agg;
88882 pMem->u.pDef = p->pFunc;
88883 if( pMem->z ){
88884 memset(pMem->z, 0, nByte);
88887 return (void*)pMem->z;
88899 if( (p->pMem->flags & MEM_Agg)==0 ){
88902 return (void*)p->pMem->z;
88998 assert( p && p->pMem && p->pFunc && p->pFunc->xFinalize );
88999 return p->pMem->n;
89832 Mem *pMem;
89870 pMem = *ppValue = &p->pUnpacked->aMem[iIdx];
89872 sqlite3VdbeMemSetInt64(pMem, p->iKey1);
89876 if( pMem->flags & (MEM_Int|MEM_IntReal) ){
89877 testcase( pMem->flags & MEM_Int );
89878 testcase( pMem->flags & MEM_IntReal );
89879 sqlite3VdbeMemRealify(pMem);
89937 Mem *pMem;
89966 pMem = &pUnpack->aMem[iIdx];
89968 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
89970 pMem = (sqlite3_value *)columnNullValue();
89987 pMem = &p->aNew[iIdx];
89988 if( pMem->flags==0 ){
89990 sqlite3VdbeMemSetInt64(pMem, p->iKey2);
89992 rc = sqlite3VdbeMemCopy(pMem, &p->v->aMem[p->iNewReg+1+iIdx]);
89997 *ppValue = pMem;
90534 Mem *pMem = iCur>0 ? &p->aMem[p->nMem-iCur] : p->aMem;
90549 ** the pMem used to hold space for the cursor has enough storage available
90550 ** in pMem->zMalloc. But for the special case of the aMem[] entries used
90552 assert( pMem->flags==MEM_Undefined );
90553 assert( (pMem->flags & MEM_Dyn)==0 );
90554 assert( pMem->szMalloc==0 || pMem->z==pMem->zMalloc );
90555 if( pMem->szMalloc<nByte ){
90556 if( pMem->szMalloc>0 ){
90557 sqlite3DbFreeNN(pMem->db, pMem->zMalloc);
90559 pMem->z = pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, nByte);
90560 if( pMem->zMalloc==0 ){
90561 pMem->szMalloc = 0;
90564 pMem->szMalloc = nByte;
90567 p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->zMalloc;
90574 &pMem->z[ROUND8P(sizeof(VdbeCursor))+2*sizeof(u32)*nField];
90693 Mem *pMem = (Mem*)pVal;
90694 applyNumericAffinity(pMem, 0);
90713 ** pMem currently only holds a string type (or maybe a BLOB that we can
90715 ** numeric type, if has one. Set the pMem->u.r and pMem->u.i fields
90718 static u16 SQLITE_NOINLINE computeNumericType(Mem *pMem){
90721 assert( (pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 );
90722 assert( (pMem->flags & (MEM_Str|MEM_Blob))!=0 );
90723 if( ExpandBlob(pMem) ){
90724 pMem->u.i = 0;
90727 rc = sqlite3AtoF(pMem->z, &pMem->u.r, pMem->n, pMem->enc);
90729 if( rc==0 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)<=1 ){
90730 pMem->u.i = ix;
90735 }else if( rc==1 && sqlite3Atoi64(pMem->z, &ix, pMem->n, pMem->enc)==0 ){
90736 pMem->u.i = ix;
90743 ** Return the numeric type for pMem, either MEM_Int or MEM_Real or both or
90746 ** Unlike applyNumericAffinity(), this routine does not modify pMem->flags.
90747 ** But it does set pMem->u.r and pMem->u.i appropriately.
90749 static u16 numericType(Mem *pMem){
90750 assert( (pMem->flags & MEM_Null)==0
90751 || pMem->db==0 || pMem->db->mallocFailed );
90752 if( pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null) ){
90753 testcase( pMem->flags & MEM_Int );
90754 testcase( pMem->flags & MEM_Real );
90755 testcase( pMem->flags & MEM_IntReal );
90756 return pMem->flags & (MEM_Int|MEM_Real|MEM_IntReal|MEM_Null);
90758 assert( pMem->flags & (MEM_Str|MEM_Blob) );
90759 testcase( pMem->flags & MEM_Str );
90760 testcase( pMem->flags & MEM_Blob );
90761 return computeNumericType(pMem);
90766 ** Write a nice string representation of the contents of cell pMem
90769 SQLITE_PRIVATE void sqlite3VdbeMemPrettyPrint(Mem *pMem, StrAccum *pStr){
90770 int f = pMem->flags;
90788 for(i=0; i<25 && i<pMem->n; i++){
90789 sqlite3_str_appendf(pStr, "%02X", ((int)pMem->z[i] & 0xFF));
90792 for(i=0; i<25 && i<pMem->n; i++){
90793 char z = pMem->z[i];
90798 sqlite3_str_appendf(pStr, "+%dz",pMem->u.nZero);
90815 sqlite3_str_appendf(pStr, " %c%d[", c, pMem->n);
90816 for(j=0; j<25 && j<pMem->n; j++){
90817 c = pMem->z[j];
90820 sqlite3_str_appendf(pStr, "]%s", encnames[pMem->enc]);
90864 /**/ void sqlite3PrintMem(Mem *pMem){
90865 memTracePrint(pMem);
90924 Mem *pMem,
90935 switch (sqlite3_value_type(&pMem[i])) {
90937 rc = p->pSharedBlock->xPutLong(pCtx, p->addedRows, i, (sqlite3_int64)pMem[i].u.i);
90941 rc = p->pSharedBlock->xPutDouble(pCtx, p->addedRows, i, pMem[i].u.r);
90945 Deephemeralize(&pMem[i]);
90946 sqlite3VdbeMemNulTerminate(&pMem[i]);
90947 sqlite3VdbeChangeEncoding(&pMem[i],SQLITE_UTF8);
90948 rc = p->pSharedBlock->xPutString(pCtx, p->addedRows, i, pMem[i].z, pMem[i].n+1);
90952 rc = p->pSharedBlock->xPutBlob(pCtx, p->addedRows, i, pMem[i].z, pMem[i].n);
91022 ** Return the symbolic name for the data type of a pMem
91024 static const char *vdbeMemTypeName(Mem *pMem){
91032 return azTypes[sqlite3_value_type(pMem)-1];
91932 Mem *pMem = &aMem[pOp->p1];
91933 rc = copySharedBlockRow(p, pOp, pMem, pCtx);
91939 rc = copySharedBlockRow(p, pOp, pMem, pCtx);
91967 Mem *pMem = p->pResultSet;
91970 assert( memIsValid(&pMem[i]) );
91971 REGISTER_TRACE(pOp->p1+i, &pMem[i]);
91977 pMem[i].pScopyFrom = 0;
93364 sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
95744 Mem *pMem; /* Register holding largest rowid for AUTOINCREMENT */
95809 pMem = &pFrame->aMem[pOp->p3];
95813 pMem = &aMem[pOp->p3];
95814 memAboutToChange(p, pMem);
95816 assert( memIsValid(pMem) );
95818 REGISTER_TRACE(pOp->p3, pMem);
95819 sqlite3VdbeMemIntegerify(pMem);
95820 assert( (pMem->flags & MEM_Int)!=0 ); /* mem(P3) holds an integer */
95821 if( pMem->u.i==MAX_ROWID || pC->useRandomRowid ){
95825 if( v<pMem->u.i+1 ){
95826 v = pMem->u.i + 1;
95828 pMem->u.i = v;
97470 Mem *pMem; /* Used to iterate through memory cells */
97549 for(pMem=VdbeFrameMem(pFrame); pMem!=pEnd; pMem++){
97550 pMem->flags = MEM_Undefined;
97551 pMem->db = db;
97860 pCtx->pMem = 0;
97883 Mem *pMem;
97887 pMem = &aMem[pOp->p3];
97893 assert( pMem->uTemp==0x1122e0e3 );
97896 pMem->uTemp = 0x1122e0e3;
97904 if( pCtx->pMem != pMem ){
97905 pCtx->pMem = pMem;
97916 pMem->n++;
97976 Mem *pMem;
97979 pMem = &aMem[pOp->p1];
97980 assert( (pMem->flags & ~(MEM_Null|MEM_Agg))==0 );
97984 rc = sqlite3VdbeMemAggValue(pMem, &aMem[pOp->p3], pOp->p4.pFunc);
97985 pMem = &aMem[pOp->p3];
97989 rc = sqlite3VdbeMemFinalize(pMem, pOp->p4.pFunc);
97993 sqlite3VdbeError(p, "%s", sqlite3_value_text(pMem));
97996 sqlite3VdbeChangeEncoding(pMem, encoding);
97997 UPDATE_MAX_BLOBSIZE(pMem);
98016 Mem *pMem; /* Write results here */
98032 for(i=0, pMem = &aMem[pOp->p3]; i<3; i++, pMem++){
98033 sqlite3VdbeMemSetInt64(pMem, (i64)aRes[i]);
99090 Mem *pMem;
99095 pMem = &aMem[pOp->p1];
99097 for(i=0; i<pOp->p2; i++, pMem++){
99099 pMem->pScopyFrom = 0;
99100 if( i<32 && pOp->p5 ) MemSetTypeFlag(pMem, MEM_Undefined);
173923 ** SQLITE_CONFIG_PAGECACHE: A pointer to 8-byte aligned memory (pMem),