Remove the NullCallback opcode. Handle the empty_result_set pragma inside

the sqlite_exec() function. (CVS 1244)

FossilOrigin-Name: f72134852bf33d13fd2bc6f35251e4b33bc10fac
This commit is contained in:
drh 2004-02-16 03:44:01 +00:00
parent 826fb5a3f8
commit d6502758b4
10 changed files with 63 additions and 90 deletions

View File

@ -1,5 +1,5 @@
C Eliminate\sobsolete\scode\sassociated\swith\sthe\solder\scallback\sfunctionality.\s(CVS\s1243)
D 2004-02-14T23:59:57
C Remove\sthe\sNullCallback\sopcode.\s\sHandle\sthe\sempty_result_set\spragma\sinside\nthe\ssqlite_exec()\sfunction.\s(CVS\s1244)
D 2004-02-16T03:44:02
F Makefile.in cfd75c46b335881999333a9e4b982fa8491f200b
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@ -27,26 +27,26 @@ F src/btree.c 0a40efb01fa3a431a16d8604f603431d8c9cebfa
F src/btree.h 41cb3ff6ebc3f6da2d0a074e39ff8c7a2287469f
F src/btree_rb.c 32b2cb4285c0fbd53b89de021637b63d52257e54
F src/build.c e6d71a3babd1f523abdd806555be3430adbd69eb
F src/copy.c 9e47975ea96751c658bcf1a0c4f0bb7c6ee61e73
F src/copy.c 391ce142f6b1faa093867ecee134f61a5028a9af
F src/date.c c9d2bfd40b1c95f8f97d53a5eba981d7167c7b61
F src/delete.c 0778fe05df0a1d62ac27fd1a3dba237c186ff4d1
F src/delete.c b8e3fc122f4e103130d764085c3fd7b697b301c4
F src/encode.c 9e70ea1e4e746f23f18180949e94f1bb1c2220d3
F src/expr.c fdd57e18cf6f2dea42e1e1930930b32ec6351c47
F src/func.c cbc5edd10c82a5193b9ca0726873328be445e6c1
F src/hash.c 9b56ef3b291e25168f630d5643a4264ec011c70e
F src/hash.h 3247573ab95b9dd90bcca0307a75d9a16da1ccc7
F src/insert.c 01f66866f35c986eab4a57373ca689a3255ef2df
F src/main.c bb7cd00ac7551b542c8e54296ecec19d9732ef4e
F src/insert.c f0a95cb6e6b0aacc916c76a89649196e4f10adca
F src/main.c 992114429fa45f0015cab0648caeeb9d9a12294a
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
F src/os.c f5fc4954725b2fcd852979f2746085fe8ca27710
F src/os.h 250a3789be609adfee5c5aa20137ce8683276f24
F src/pager.c 29ddad4dd454f0aaa98e2bcd327710ab9f02f833
F src/pager.h 82332878799280145639a48d88cdb4058925e3f6
F src/parse.y 226bbdba2dee362d4b1cacc424bd82f7740071ee
F src/pragma.c 89d62c31c6f0a43376fe8d20549b87a6d30c467a
F src/pragma.c 23dac1d20cc278e1fbbae5181eba0508ca7f2d7a
F src/printf.c 84e4ea4ba49cbbf930e95e82295127ad5843ae1f
F src/random.c 775913e0b7fbd6295d21f12a7bd35b46387c44b2
F src/select.c 330166e328d7c8c737547b9d9a5bbe00431f9aed
F src/select.c 3b8eaf1a9585cbcf7a90bc9915b9b2f75ffe3921
F src/shell.c c3d3404fa82bb0808444fda9884d1bb572fd18b9
F src/sqlite.h.in 64f016cd5ce190643a0f47760188fdf4e0b2227e
F src/sqliteInt.h 2b5e327ba20a864a95ff12e0d243dabfbc37d613
@ -58,10 +58,10 @@ F src/test3.c 30985ebdfaf3ee1462a9b0652d3efbdc8d9798f5
F src/test4.c dcbbbb382626fd466a7c46907f74db35fc8bad64
F src/tokenize.c 6676b946fd8825b67ab52140af4fdc57a70bda48
F src/trigger.c c647a442427fb8c1cd761eb03b1710c9d5675a8b
F src/update.c 24260b4fda00c9726d27699a0561d53c0dccc397
F src/update.c 10459f44c9eb46c70b1c63e79cc35f3256f09986
F src/util.c 64995b5949a5d377629ffd2598747bc771cade1e
F src/vacuum.c d9e80c2b36ee1f623dbf1bdf3cedad24a23f87ac
F src/vdbe.c 90debe895f49342179f9670ee84da4c0a48cec19
F src/vdbe.c e1825bcb40da6dd8429b24f404dc31265face31e
F src/vdbe.h b9f6f1b5f9d1bfceb8bda5e396877ba584c4519c
F src/vdbeInt.h af83bd700b1cc10b9cad2af146002927e0d421c9
F src/vdbeaux.c 11f1fa94869870ebd8338ada489e64647414268b
@ -184,7 +184,7 @@ F www/sqlite.tcl 3c83b08cf9f18aa2d69453ff441a36c40e431604
F www/tclsqlite.tcl b9271d44dcf147a93c98f8ecf28c927307abd6da
F www/vdbe.tcl 9b9095d4495f37697fd1935d10e14c6015e80aa1
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P af5c2be4aed1c50f69eb9634cf051a26263dcf51
R 95d34ebfa714eff82ca160ac5c46d401
P 2dbc4593ca5c1cf75039c8b4471b1e47faa849f0
R 4f2635b8f97864f9158485f11af66f00
U drh
Z 7d29870d7ab5460e1dbcbf55076eba4b
Z 5bfa6a509eb1a2b3c9004d75dfbc7acf

View File

@ -1 +1 @@
2dbc4593ca5c1cf75039c8b4471b1e47faa849f0
f72134852bf33d13fd2bc6f35251e4b33bc10fac

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the COPY command.
**
** $Id: copy.c,v 1.6 2003/06/02 22:50:26 drh Exp $
** $Id: copy.c,v 1.7 2004/02/16 03:44:02 drh Exp $
*/
#include "sqliteInt.h"
@ -107,7 +107,7 @@ void sqliteCopy(
sqliteVdbeAddOp(v, OP_Noop, 0, 0);
sqliteEndWriteOperation(pParse);
if( db->flags & SQLITE_CountRows ){
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
}

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle DELETE FROM statements.
**
** $Id: delete.c,v 1.58 2004/01/19 04:54:29 jplyon Exp $
** $Id: delete.c,v 1.59 2004/02/16 03:44:02 drh Exp $
*/
#include "sqliteInt.h"
@ -305,7 +305,7 @@ void sqliteDeleteFrom(
** Return the number of rows that were deleted.
*/
if( db->flags & SQLITE_CountRows ){
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
sqliteVdbeChangeP3(v, -1, "rows deleted", P3_STATIC);
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
}

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle INSERT statements in SQLite.
**
** $Id: insert.c,v 1.90 2003/12/06 21:43:56 drh Exp $
** $Id: insert.c,v 1.91 2004/02/16 03:44:02 drh Exp $
*/
#include "sqliteInt.h"
@ -541,7 +541,7 @@ void sqliteInsert(
** Return the number of rows inserted.
*/
if( db->flags & SQLITE_CountRows ){
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
sqliteVdbeChangeP3(v, -1, "rows inserted", P3_STATIC);
sqliteVdbeAddOp(v, OP_MemLoad, iCntMem, 0);
sqliteVdbeAddOp(v, OP_Callback, 1, 0);

View File

@ -14,7 +14,7 @@
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
** $Id: main.c,v 1.155 2004/02/14 23:59:57 drh Exp $
** $Id: main.c,v 1.156 2004/02/16 03:44:02 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -614,6 +614,7 @@ int sqlite_exec(
sqlite_vm *pVm;
int nRetry = 0;
int nChange = 0;
int nCallback;
if( zSql==0 ) return SQLITE_OK;
while( rc==SQLITE_OK && zSql[0] ){
@ -628,16 +629,22 @@ int sqlite_exec(
break;
}
db->nChange += nChange;
nCallback = 0;
while(1){
int nArg;
char **azArg, **azCol;
rc = sqlite_step(pVm, &nArg, (const char***)&azArg,(const char***)&azCol);
if( rc==SQLITE_ROW ){
if( xCallback(pArg, nArg, azArg, azCol) ){
if( xCallback!=0 && xCallback(pArg, nArg, azArg, azCol) ){
sqlite_finalize(pVm, 0);
return SQLITE_ABORT;
}
nCallback++;
}else{
if( rc==SQLITE_DONE && nCallback==0
&& (db->flags & SQLITE_NullCallback)!=0 && xCallback!=0 ){
xCallback(pArg, nArg, azArg, azCol);
}
rc = sqlite_finalize(pVm, pzErrMsg);
if( rc==SQLITE_SCHEMA && nRetry<2 ){
nRetry++;

View File

@ -11,7 +11,7 @@
*************************************************************************
** This file contains code used to implement the PRAGMA command.
**
** $Id: pragma.c,v 1.13 2004/01/19 04:52:29 jplyon Exp $
** $Id: pragma.c,v 1.14 2004/02/16 03:44:02 drh Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -140,7 +140,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
{ OP_Integer, 0, 0, 0},
{ OP_Ne, 0, 6, 0},
{ OP_Integer, MAX_PAGES,0, 0},
{ OP_ColumnName, 0, 0, "cache_size"},
{ OP_ColumnName, 0, 1, "cache_size"},
{ OP_Callback, 1, 0, 0},
};
if( pRight->z==pLeft->z ){
@ -178,7 +178,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
*/
if( sqliteStrICmp(zLeft,"cache_size")==0 ){
static VdbeOp getCacheSize[] = {
{ OP_ColumnName, 0, 0, "cache_size"},
{ OP_ColumnName, 0, 1, "cache_size"},
{ OP_Callback, 1, 0, 0},
};
if( pRight->z==pLeft->z ){
@ -216,7 +216,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
*/
if( sqliteStrICmp(zLeft,"default_synchronous")==0 ){
static VdbeOp getSync[] = {
{ OP_ColumnName, 0, 0, "synchronous"},
{ OP_ColumnName, 0, 1, "synchronous"},
{ OP_ReadCookie, 0, 3, 0},
{ OP_Dup, 0, 0, 0},
{ OP_If, 0, 0, 0}, /* 3 */
@ -269,7 +269,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
*/
if( sqliteStrICmp(zLeft,"synchronous")==0 ){
static VdbeOp getSync[] = {
{ OP_ColumnName, 0, 0, "synchronous"},
{ OP_ColumnName, 0, 1, "synchronous"},
{ OP_Callback, 1, 0, 0},
};
if( pRight->z==pLeft->z ){
@ -344,7 +344,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
{ OP_ColumnName, 2, 0, "type"},
{ OP_ColumnName, 3, 0, "notnull"},
{ OP_ColumnName, 4, 0, "dflt_value"},
{ OP_ColumnName, 5, 0, "pk"},
{ OP_ColumnName, 5, 1, "pk"},
};
int i;
sqliteVdbeAddOpList(v, ArraySize(tableInfoPreface), tableInfoPreface);
@ -373,7 +373,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
static VdbeOp tableInfoPreface[] = {
{ OP_ColumnName, 0, 0, "seqno"},
{ OP_ColumnName, 1, 0, "cid"},
{ OP_ColumnName, 2, 0, "name"},
{ OP_ColumnName, 2, 1, "name"},
};
int i;
pTab = pIdx->pTable;
@ -403,7 +403,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
static VdbeOp indexListPreface[] = {
{ OP_ColumnName, 0, 0, "seq"},
{ OP_ColumnName, 1, 0, "name"},
{ OP_ColumnName, 2, 0, "unique"},
{ OP_ColumnName, 2, 1, "unique"},
};
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
@ -434,7 +434,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
{ OP_ColumnName, 1, 0, "seq"},
{ OP_ColumnName, 2, 0, "table"},
{ OP_ColumnName, 3, 0, "from"},
{ OP_ColumnName, 4, 0, "to"},
{ OP_ColumnName, 4, 1, "to"},
};
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
@ -463,7 +463,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
static VdbeOp indexListPreface[] = {
{ OP_ColumnName, 0, 0, "seq"},
{ OP_ColumnName, 1, 0, "name"},
{ OP_ColumnName, 2, 0, "file"},
{ OP_ColumnName, 2, 1, "file"},
};
sqliteVdbeAddOpList(v, ArraySize(indexListPreface), indexListPreface);
@ -494,7 +494,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
*/
if( sqliteStrICmp(zLeft, "temp_store")==0 ){
static VdbeOp getTmpDbLoc[] = {
{ OP_ColumnName, 0, 0, "temp_store"},
{ OP_ColumnName, 0, 1, "temp_store"},
{ OP_Callback, 1, 0, 0},
};
if( pRight->z==pLeft->z ){
@ -522,7 +522,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
*/
if( sqliteStrICmp(zLeft, "default_temp_store")==0 ){
static VdbeOp getTmpDbLoc[] = {
{ OP_ColumnName, 0, 0, "temp_store"},
{ OP_ColumnName, 0, 1, "temp_store"},
{ OP_ReadCookie, 0, 5, 0},
{ OP_Callback, 1, 0, 0}};
if( pRight->z==pLeft->z ){
@ -561,7 +561,7 @@ void sqlitePragma(Parse *pParse, Token *pLeft, Token *pRight, int minusFlag){
static VdbeOp initCode[] = {
{ OP_Integer, 0, 0, 0},
{ OP_MemStore, 0, 1, 0},
{ OP_ColumnName, 0, 0, "integrity_check"},
{ OP_ColumnName, 0, 1, "integrity_check"},
};
/* Code to do an BTree integrity check on a single database file.

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.155 2004/02/14 23:59:58 drh Exp $
** $Id: select.c,v 1.156 2004/02/16 03:44:02 drh Exp $
*/
#include "sqliteInt.h"
@ -689,17 +689,19 @@ static void generateColumnNames(
){
Vdbe *v = pParse->pVdbe;
int i, j;
assert( v!=0 );
if( pParse->colNamesSet || v==0 || sqlite_malloc_failed ) return;
pParse->colNamesSet = 1;
for(i=0; i<pEList->nExpr; i++){
Expr *p;
char *zType = 0;
int showFullNames;
int p2 = i==pEList->nExpr-1;
p = pEList->a[i].pExpr;
if( p==0 ) continue;
if( pEList->a[i].zName ){
char *zName = pEList->a[i].zName;
sqliteVdbeAddOp(v, OP_ColumnName, i, 0);
sqliteVdbeAddOp(v, OP_ColumnName, i, p2);
sqliteVdbeChangeP3(v, -1, zName, strlen(zName));
continue;
}
@ -721,7 +723,7 @@ static void generateColumnNames(
zType = pTab->aCol[iCol].zType;
}
if( p->span.z && p->span.z[0] && !showFullNames ){
int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, 0);
int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, p2);
sqliteVdbeChangeP3(v, -1, p->span.z, p->span.n);
sqliteVdbeCompressSpace(v, addr);
}else if( pTabList->nSrc>1 || showFullNames ){
@ -731,22 +733,22 @@ static void generateColumnNames(
zTab = pTabList->a[j].zAlias;
if( showFullNames || zTab==0 ) zTab = pTab->zName;
sqliteSetString(&zName, zTab, ".", zCol, 0);
sqliteVdbeAddOp(v, OP_ColumnName, i, 0);
sqliteVdbeAddOp(v, OP_ColumnName, i, p2);
sqliteVdbeChangeP3(v, -1, zName, strlen(zName));
sqliteFree(zName);
}else{
sqliteVdbeAddOp(v, OP_ColumnName, i, 0);
sqliteVdbeAddOp(v, OP_ColumnName, i, p2);
sqliteVdbeChangeP3(v, -1, zCol, 0);
}
}else if( p->span.z && p->span.z[0] ){
int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, 0);
int addr = sqliteVdbeAddOp(v,OP_ColumnName, i, p2);
sqliteVdbeChangeP3(v, -1, p->span.z, p->span.n);
sqliteVdbeCompressSpace(v, addr);
}else{
char zName[30];
assert( p->op!=TK_COLUMN || pTabList==0 );
sprintf(zName, "column%d", i+1);
sqliteVdbeAddOp(v, OP_ColumnName, i, 0);
sqliteVdbeAddOp(v, OP_ColumnName, i, p2);
sqliteVdbeChangeP3(v, -1, zName, strlen(zName));
}
}
@ -1496,12 +1498,6 @@ static int multiSelect(Parse *pParse, Select *p, int eDest, int iParm){
" do not have the same number of result columns", selectOpName(p->op));
return 1;
}
/* Issue a null callback if that is what the user wants.
*/
if( eDest==SRT_Callback ){
sqliteVdbeAddOp(v, OP_NullCallback, p->pEList->nExpr, 0);
}
return 0;
}
@ -2394,13 +2390,6 @@ int sqliteSelect(
generateSortTail(p, v, pEList->nExpr, eDest, iParm);
}
/* Issue a null callback if that is what the user wants.
*/
if( eDest==SRT_Callback ){
sqliteVdbeAddOp(v, OP_NullCallback, pEList->nExpr, 0);
}
/* If this was a subquery, we have now converted the subquery into a
** temporary table. So delete the subquery structure from the parent
** to prevent this subquery from being evaluated again and to force the

View File

@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle UPDATE statements.
**
** $Id: update.c,v 1.67 2003/06/01 01:10:33 drh Exp $
** $Id: update.c,v 1.68 2004/02/16 03:44:02 drh Exp $
*/
#include "sqliteInt.h"
@ -436,7 +436,7 @@ void sqliteUpdate(
** Return the number of rows that were changed.
*/
if( db->flags & SQLITE_CountRows && !pParse->trigStack ){
sqliteVdbeAddOp(v, OP_ColumnName, 0, 0);
sqliteVdbeAddOp(v, OP_ColumnName, 0, 1);
sqliteVdbeChangeP3(v, -1, "rows updated", P3_STATIC);
sqliteVdbeAddOp(v, OP_Callback, 1, 0);
}

View File

@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code.
**
** $Id: vdbe.c,v 1.264 2004/02/14 23:59:58 drh Exp $
** $Id: vdbe.c,v 1.265 2004/02/16 03:44:02 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
@ -837,15 +837,21 @@ case OP_Push: {
}
/* Opcode: ColumnName P1 * P3
/* Opcode: ColumnName P1 P2 P3
**
** P3 becomes the P1-th column name (first is 0). An array of pointers
** to all column names is passed as the 4th parameter to the callback.
** If P2==1 then this is the last column in the result set and thus the
** number of columns in the result set will be P1. There must be at least
** one OP_ColumnName with a P2==1 before invoking OP_Callback and the
** number of columns specified in OP_Callback must one more than the P1
** value of the OP_ColumnName that has P2==1.
*/
case OP_ColumnName: {
assert( pOp->p1>=0 && pOp->p1<p->nOp );
p->azColName[pOp->p1] = pOp->p3;
p->nCallback = 0;
if( pOp->p2 ) p->nResColumn = pOp->p1+1;
break;
}
@ -873,42 +879,13 @@ case OP_Callback: {
azArgv[i] = 0;
p->nCallback++;
p->azResColumn = azArgv;
p->nResColumn = pOp->p1;
assert( p->nResColumn==pOp->p1 );
p->popStack = pOp->p1;
p->pc = pc + 1;
p->pTos = pTos;
return SQLITE_ROW;
}
/* Opcode: NullCallback P1 * *
**
** Invoke the callback function once with the 2nd argument (the
** number of columns) equal to P1 and with the 4th argument (the
** names of the columns) set according to prior OP_ColumnName
** instructions. This is all like the regular
** OP_Callback or OP_SortCallback opcodes. But the 3rd argument
** which normally contains a pointer to an array of pointers to
** data is NULL.
**
** The callback is only invoked if there have been no prior calls
** to OP_Callback or OP_SortCallback.
**
** This opcode is used to report the number and names of columns
** in cases where the result set is empty.
*/
case OP_NullCallback: {
p->nResColumn = pOp->p1;
if( p->nCallback==0 && (db->flags & SQLITE_NullCallback)!=0 ){
p->azResColumn = 0;
p->popStack = 0;
p->pc = pc + 1;
p->pTos = pTos;
p->nCallback++;
return SQLITE_ROW;
}
break;
}
/* Opcode: Concat P1 P2 P3
**
** Look at the first P1 elements of the stack. Append them all
@ -4076,7 +4053,7 @@ case OP_SortCallback: {
p->nCallback++;
p->pc = pc+1;
p->azResColumn = (char**)pTos->z;
p->nResColumn = pOp->p1;
assert( p->nResColumn==pOp->p1 );
p->popStack = 1;
p->pTos = pTos;
return SQLITE_ROW;