diff options
author | drh <drh@noemail.net> | 2003-07-09 00:28:13 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2003-07-09 00:28:13 +0000 |
commit | 073e5a7751dd1db2fbb044957a9324947ba86cde (patch) | |
tree | 921c89d1d9b8a04aba1db939fe6b37a7b1af3d10 /src | |
parent | 23af2f6eb2fd7ac5230bb71445ed89fde1212f14 (diff) | |
download | sqlite-073e5a7751dd1db2fbb044957a9324947ba86cde.tar.gz sqlite-073e5a7751dd1db2fbb044957a9324947ba86cde.zip |
Allow the output arguments in sqlite_compile and sqlite_step to be NULL
pointers. Tickets #384 and #385. (CVS 1049)
FossilOrigin-Name: dd84f88f6c4012e4a093a4881f6fe50527bb2006
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/test1.c | 46 | ||||
-rw-r--r-- | src/vdbe.c | 20 |
3 files changed, 39 insertions, 31 deletions
diff --git a/src/main.c b/src/main.c index 1c3b12021..6779ba2c7 100644 --- a/src/main.c +++ b/src/main.c @@ -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.137 2003/06/23 15:15:03 drh Exp $ +** $Id: main.c,v 1.138 2003/07/09 00:28:14 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -645,7 +645,7 @@ static int sqliteMain( if( sParse.useCallback==0 ){ assert( ppVm ); *ppVm = (sqlite_vm*)sParse.pVdbe; - *pzTail = sParse.zTail; + if( pzTail ) *pzTail = sParse.zTail; } if( sqliteSafetyOff(db) ) goto exec_misuse; return sParse.rc; diff --git a/src/test1.c b/src/test1.c index d477581d1..3ec97d7e7 100644 --- a/src/test1.c +++ b/src/test1.c @@ -13,7 +13,7 @@ ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.25 2003/06/16 03:08:19 drh Exp $ +** $Id: test1.c,v 1.26 2003/07/09 00:28:15 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -643,7 +643,7 @@ static int sqlite_datatypes( } /* -** Usage: sqlite_compile DB SQL TAILVAR +** Usage: sqlite_compile DB SQL ?TAILVAR? ** ** Attempt to compile an SQL statement. Return a pointer to the virtual ** machine used to execute that statement. Unprocessed SQL is written @@ -661,14 +661,14 @@ static int test_compile( char *zErr = 0; const char *zTail; char zBuf[50]; - if( argc!=4 ){ + if( argc!=3 && argc!=4 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " DB SQL TAILVAR", 0); return TCL_ERROR; } if( getDbPointer(interp, argv[1], &db) ) return TCL_ERROR; - rc = sqlite_compile(db, argv[2], &zTail, &vm, &zErr); - Tcl_SetVar(interp, argv[3], zTail, 0); + rc = sqlite_compile(db, argv[2], argc==4 ? &zTail : 0, &vm, &zErr); + if( argc==4 ) Tcl_SetVar(interp, argv[3], zTail, 0); if( rc ){ assert( vm==0 ); sprintf(zBuf, "(%d) ", rc); @@ -684,7 +684,7 @@ static int test_compile( } /* -** Usage: sqlite_step VM NVAR VALUEVAR COLNAMEVAR +** Usage: sqlite_step VM ?NVAR? ?VALUEVAR? ?COLNAMEVAR? ** ** Step a virtual machine. Return a the result code as a string. ** Column results are written into three variables. @@ -702,27 +702,33 @@ static int test_step( int N = 0; char *zRc; char zBuf[50]; - if( argc!=5 ){ + if( argc<2 || argc>5 ){ Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0], " VM NVAR VALUEVAR COLNAMEVAR", 0); return TCL_ERROR; } if( getVmPointer(interp, argv[1], &vm) ) return TCL_ERROR; - rc = sqlite_step(vm, &N, &azValue, &azColName); - sprintf(zBuf, "%d", N); - Tcl_SetVar(interp, argv[2], zBuf, 0); - Tcl_SetVar(interp, argv[3], "", 0); - if( azValue ){ - for(i=0; i<N; i++){ - Tcl_SetVar(interp, argv[3], azValue[i] ? azValue[i] : "", - TCL_APPEND_VALUE | TCL_LIST_ELEMENT); + rc = sqlite_step(vm, argc>=3?&N:0, argc>=4?&azValue:0, argc==5?&azColName:0); + if( argc>=3 ){ + sprintf(zBuf, "%d", N); + Tcl_SetVar(interp, argv[2], zBuf, 0); + } + if( argc>=4 ){ + Tcl_SetVar(interp, argv[3], "", 0); + if( azValue ){ + for(i=0; i<N; i++){ + Tcl_SetVar(interp, argv[3], azValue[i] ? azValue[i] : "", + TCL_APPEND_VALUE | TCL_LIST_ELEMENT); + } } } - Tcl_SetVar(interp, argv[4], "", 0); - if( azColName ){ - for(i=0; i<N*2; i++){ - Tcl_SetVar(interp, argv[4], azColName[i] ? azColName[i] : "", - TCL_APPEND_VALUE | TCL_LIST_ELEMENT); + if( argc==5 ){ + Tcl_SetVar(interp, argv[4], "", 0); + if( azColName ){ + for(i=0; i<N*2; i++){ + Tcl_SetVar(interp, argv[4], azColName[i] ? azColName[i] : "", + TCL_APPEND_VALUE | TCL_LIST_ELEMENT); + } } } switch( rc ){ diff --git a/src/vdbe.c b/src/vdbe.c index ee5b6b0ea..0183e127e 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -36,7 +36,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.232 2003/07/06 17:22:25 drh Exp $ +** $Id: vdbe.c,v 1.233 2003/07/09 00:28:15 drh Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -810,16 +810,18 @@ int sqlite_step( rc = sqliteVdbeExec(p); } if( rc==SQLITE_DONE || rc==SQLITE_ROW ){ - *pazColName = (const char**)p->azColName; - *pN = p->nResColumn; + if( pazColName ) *pazColName = (const char**)p->azColName; + if( pN ) *pN = p->nResColumn; }else{ - *pN = 0; - *pazColName = 0; + if( pazColName) *pazColName = 0; + if( pN ) *pN = 0; } - if( rc==SQLITE_ROW ){ - *pazValue = (const char**)p->azResColumn; - }else{ - *pazValue = 0; + if( pazValue ){ + if( rc==SQLITE_ROW ){ + *pazValue = (const char**)p->azResColumn; + }else{ + *pazValue = 0; + } } if( sqliteSafetyOff(db) ){ return SQLITE_MISUSE; |