1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-03 16:53:36 +03:00

Enhanced display of register ranges in the auxiliary comments added to EXPLAIN.

FossilOrigin-Name: d6b0c39281d0751ecec04d7c19d9d2931d133e8e
This commit is contained in:
drh
2013-10-30 00:25:03 +00:00
parent 81316f8908
commit f63552b258
4 changed files with 64 additions and 43 deletions

View File

@@ -855,10 +855,27 @@ VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){
}
#if defined(SQLITE_DEBUG)
/*
** Return an integer value for one of the parameters to the opcode pOp
** determined by character c.
*/
static int translateP(char c, const Op *pOp){
if( c=='1' ) return pOp->p1;
if( c=='2' ) return pOp->p2;
if( c=='3' ) return pOp->p3;
if( c=='4' ) return pOp->p4.i;
return pOp->p5;
}
/*
** Compute a string for the "comment" field of a VDBE opcode listing
*/
static int displayComment(Op *pOp, const char *zP4, char *zTemp, int nTemp){
static int displayComment(
const Op *pOp, /* The opcode to be commented */
const char *zP4, /* Previously obtained value for P4 */
char *zTemp, /* Write result here */
int nTemp /* Space available in zTemp[] */
){
const char *zOpName;
const char *zSynopsis;
int nOpName;
@@ -867,28 +884,32 @@ static int displayComment(Op *pOp, const char *zP4, char *zTemp, int nTemp){
nOpName = sqlite3Strlen30(zOpName);
if( zOpName[nOpName+1] ){
int seenCom = 0;
char c;
zSynopsis = zOpName += nOpName + 1;
for(ii=jj=0; jj<nTemp-1 && zSynopsis[ii]; ii++){
if( zSynopsis[ii]=='P' ){
int v;
const char *zShow = 0;
ii++;
switch( zSynopsis[ii] ){
case '1': v = pOp->p1; break;
case '2': v = pOp->p2; break;
case '3': v = pOp->p3; break;
case '5': v = pOp->p5; break;
case '4': zShow = zP4; break;
case 'X': zShow = pOp->zComment; seenCom = 1; break;
}
if( zShow ){
sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", zShow);
for(ii=jj=0; jj<nTemp-1 && (c = zSynopsis[ii])!=0; ii++){
if( c=='P' ){
c = zSynopsis[++ii];
if( c=='4' ){
sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", zP4);
}else if( c=='X' ){
sqlite3_snprintf(nTemp-jj, zTemp+jj, "%s", pOp->zComment);
seenCom = 1;
}else{
sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v);
int v1 = translateP(c, pOp);
int v2;
sqlite3_snprintf(nTemp-jj, zTemp+jj, "%d", v1);
if( strncmp(zSynopsis+ii+1, "@P", 2)==0 ){
ii += 3;
jj += sqlite3Strlen30(zTemp+jj);
v2 = translateP(zSynopsis[ii], pOp);
if( v2>1 ) sqlite3_snprintf(nTemp-jj, zTemp+jj, "..%d", v1+v2-1);
}else if( strncmp(zSynopsis+ii+1, "..P3", 4)==0 && pOp->p3==0 ){
ii += 4;
}
}
jj += sqlite3Strlen30(zTemp+jj);
}else{
zTemp[jj++] = zSynopsis[ii];
zTemp[jj++] = c;
}
}
if( !seenCom && jj<nTemp-5 && pOp->zComment ){