mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Merge the latest fixes and enhancements from trunk.
FossilOrigin-Name: 007e5c6df60f9743ac6914332f59925e4a7a861c
This commit is contained in:
54
src/vdbe.c
54
src/vdbe.c
@@ -2384,7 +2384,6 @@ case OP_Column: {
|
||||
u64 offset64; /* 64-bit offset */
|
||||
u32 avail; /* Number of bytes of available data */
|
||||
u32 t; /* A type code from the record header */
|
||||
u16 fx; /* pDest->flags value */
|
||||
Mem *pReg; /* PseudoTable input register */
|
||||
|
||||
p2 = pOp->p2;
|
||||
@@ -2562,10 +2561,31 @@ case OP_Column: {
|
||||
assert( sqlite3VdbeCheckMemInvariants(pDest) );
|
||||
if( VdbeMemDynamic(pDest) ) sqlite3VdbeMemSetNull(pDest);
|
||||
assert( t==pC->aType[p2] );
|
||||
pDest->enc = encoding;
|
||||
if( pC->szRow>=aOffset[p2+1] ){
|
||||
/* This is the common case where the desired content fits on the original
|
||||
** page - where the content is not on an overflow page */
|
||||
sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], t, pDest);
|
||||
zData = pC->aRow + aOffset[p2];
|
||||
if( t<12 ){
|
||||
sqlite3VdbeSerialGet(zData, t, pDest);
|
||||
}else{
|
||||
/* If the column value is a string, we need a persistent value, not
|
||||
** a MEM_Ephem value. This branch is a fast short-cut that is equivalent
|
||||
** to calling sqlite3VdbeSerialGet() and sqlite3VdbeDeephemeralize().
|
||||
*/
|
||||
static const u16 aFlag[] = { MEM_Blob, MEM_Str|MEM_Term };
|
||||
pDest->n = len = (t-12)/2;
|
||||
if( pDest->szMalloc < len+2 ){
|
||||
pDest->flags = MEM_Null;
|
||||
if( sqlite3VdbeMemGrow(pDest, len+2, 0) ) goto no_mem;
|
||||
}else{
|
||||
pDest->z = pDest->zMalloc;
|
||||
}
|
||||
memcpy(pDest->z, zData, len);
|
||||
pDest->z[len] = 0;
|
||||
pDest->z[len+1] = 0;
|
||||
pDest->flags = aFlag[t&1];
|
||||
}
|
||||
}else{
|
||||
/* This branch happens only when content is on overflow pages */
|
||||
if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
|
||||
@@ -2577,38 +2597,20 @@ case OP_Column: {
|
||||
** 2. the length(X) function if X is a blob, and
|
||||
** 3. if the content length is zero.
|
||||
** So we might as well use bogus content rather than reading
|
||||
** content from disk. NULL will work for the value for strings
|
||||
** and blobs and whatever is in the payloadSize64 variable
|
||||
** will work for everything else. */
|
||||
sqlite3VdbeSerialGet(t<=13 ? (u8*)&payloadSize64 : 0, t, pDest);
|
||||
** content from disk. */
|
||||
static u8 aZero[8]; /* This is the bogus content */
|
||||
sqlite3VdbeSerialGet(aZero, t, pDest);
|
||||
}else{
|
||||
rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, !pC->isTable,
|
||||
pDest);
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto op_column_error;
|
||||
if( rc==SQLITE_OK ){
|
||||
sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
|
||||
pDest->flags &= ~MEM_Ephem;
|
||||
}
|
||||
sqlite3VdbeSerialGet((const u8*)pDest->z, t, pDest);
|
||||
pDest->flags &= ~MEM_Ephem;
|
||||
}
|
||||
}
|
||||
pDest->enc = encoding;
|
||||
|
||||
op_column_out:
|
||||
/* If the column value is an ephemeral string, go ahead and persist
|
||||
** that string in case the cursor moves before the column value is
|
||||
** used. The following code does the equivalent of Deephemeralize()
|
||||
** but does it faster. */
|
||||
if( (pDest->flags & MEM_Ephem)!=0 && pDest->z ){
|
||||
fx = pDest->flags & (MEM_Str|MEM_Blob);
|
||||
assert( fx!=0 );
|
||||
zData = (const u8*)pDest->z;
|
||||
len = pDest->n;
|
||||
if( sqlite3VdbeMemClearAndResize(pDest, len+2) ) goto no_mem;
|
||||
memcpy(pDest->z, zData, len);
|
||||
pDest->z[len] = 0;
|
||||
pDest->z[len+1] = 0;
|
||||
pDest->flags = fx|MEM_Term;
|
||||
}
|
||||
op_column_error:
|
||||
UPDATE_MAX_BLOBSIZE(pDest);
|
||||
REGISTER_TRACE(pOp->p3, pDest);
|
||||
|
Reference in New Issue
Block a user