1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

Enhance location(X) so that it works with indexes and WITHOUT ROWID tables.

The function might return an offset to the main table or to an index,
depending on whether the column X would be loaded from the main table or
from the index.

FossilOrigin-Name: dd94d6a880dfec4bddd247239b815b84964f804d24841e25f33f1d46a4b5274d
This commit is contained in:
drh
2017-12-29 14:33:54 +00:00
parent 7a8573bafa
commit fe6d20e9f4
7 changed files with 27 additions and 23 deletions

View File

@@ -2349,22 +2349,27 @@ case OP_IfNullRow: { /* jump */
break;
}
/* Opcode: Location P1 P2 * * *
** Synopsis: r[P2] = location(P1)
/* Opcode: Location P1 P2 P3 * *
** Synopsis: r[P3] = location(P1)
**
** Store in register r[P2] the location in the database file that is the
** Store in register r[P3] the location in the database file that is the
** start of the payload for the record at which that cursor P1 is currently
** pointing.
**
** P2 is the column number for the argument to the location() function.
** This opcode does not use P2 itself, but the P2 value is used by the
** code generator. The P1, P2, and P3 operands to this opcode are the
** as as for OP_Column.
*/
case OP_Location: { /* out2 */
case OP_Location: { /* out3 */
VdbeCursor *pC; /* The VDBE cursor */
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
pC = p->apCsr[pOp->p1];
pOut = out2Prerelease(p, pOp);
pOut = &p->aMem[pOp->p3];
if( pC==0 || pC->eCurType!=CURTYPE_BTREE ){
pOut->flags = MEM_Null;
sqlite3VdbeMemSetNull(pOut);
}else{
pOut->u.i = sqlite3BtreeLocation(pC->uc.pCursor);
sqlite3VdbeMemSetInt64(pOut, sqlite3BtreeLocation(pC->uc.pCursor));
}
break;
}