diff options
author | danielk1977 <danielk1977@noemail.net> | 2004-05-26 00:07:25 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2004-05-26 00:07:25 +0000 |
commit | 17240fd90f888b7c6e6d96010467ddb9acfd02e0 (patch) | |
tree | 66086dd23404a57a6055dbf1c5264fa56190a64e /src | |
parent | 8c6fa9b03b2024dbca85e80e0d8e033334b00ce1 (diff) | |
download | sqlite-17240fd90f888b7c6e6d96010467ddb9acfd02e0.tar.gz sqlite-17240fd90f888b7c6e6d96010467ddb9acfd02e0.zip |
More changes to do with the new sqlite3_step() API. (CVS 1458)
FossilOrigin-Name: e83138250ce0a8caacbd1822eec2e06796d2f5f2
Diffstat (limited to 'src')
-rw-r--r-- | src/sqlite.h.in | 52 | ||||
-rw-r--r-- | src/test1.c | 124 | ||||
-rw-r--r-- | src/vdbe.c | 83 |
3 files changed, 61 insertions, 198 deletions
diff --git a/src/sqlite.h.in b/src/sqlite.h.in index 3127a6375..fa1c0869c 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -12,7 +12,7 @@ ** This header file defines the interface that the SQLite library ** presents to client programs. ** -** @(#) $Id: sqlite.h.in,v 1.77 2004/05/25 23:35:19 danielk1977 Exp $ +** @(#) $Id: sqlite.h.in,v 1.78 2004/05/26 00:07:25 danielk1977 Exp $ */ #ifndef _SQLITE_H_ #define _SQLITE_H_ @@ -586,54 +586,6 @@ int sqlite3_compile( ); /* -** After an SQL statement has been compiled, it is handed to this routine -** to be executed. This routine executes the statement as far as it can -** go then returns. The return value will be one of SQLITE_DONE, -** SQLITE_ERROR, SQLITE_BUSY, SQLITE_ROW, or SQLITE_MISUSE. -** -** SQLITE_DONE means that the execute of the SQL statement is complete -** an no errors have occurred. sqlite3_step() should not be called again -** for the same virtual machine. *pN is set to the number of columns in -** the result set and *pazColName is set to an array of strings that -** describe the column names and datatypes. The name of the i-th column -** is (*pazColName)[i] and the datatype of the i-th column is -** (*pazColName)[i+*pN]. *pazValue is set to NULL. -** -** SQLITE_ERROR means that the virtual machine encountered a run-time -** error. sqlite3_step() should not be called again for the same -** virtual machine. *pN is set to 0 and *pazColName and *pazValue are set -** to NULL. Use sqlite3_finalize() to obtain the specific error code -** and the error message text for the error. -** -** SQLITE_BUSY means that an attempt to open the database failed because -** another thread or process is holding a lock. The calling routine -** can try again to open the database by calling sqlite3_step() again. -** The return code will only be SQLITE_BUSY if no busy handler is registered -** using the sqlite3_busy_handler() or sqlite3_busy_timeout() routines. If -** a busy handler callback has been registered but returns 0, then this -** routine will return SQLITE_ERROR and sqltie_finalize() will return -** SQLITE_BUSY when it is called. -** -** SQLITE_ROW means that a single row of the result is now available. -** The data is contained in *pazValue. The value of the i-th column is -** (*azValue)[i]. *pN and *pazColName are set as described in SQLITE_DONE. -** Invoke sqlite3_step() again to advance to the next row. -** -** SQLITE_MISUSE is returned if sqlite3_step() is called incorrectly. -** For example, if you call sqlite3_step() after the virtual machine -** has halted (after a prior call to sqlite3_step() has returned SQLITE_DONE) -** or if you call sqlite3_step() with an incorrectly initialized virtual -** machine or a virtual machine that has been deleted or that is associated -** with an sqlite structure that has been closed. -*/ -int sqlite3_step( - sqlite_vm *pVm, /* The virtual machine to execute */ - int *pN, /* OUT: Number of columns in result */ - const char ***pazValue, /* OUT: Column data */ - const char ***pazColName /* OUT: Column names and datatypes */ -); - -/* ** This routine is called to delete a virtual machine after it has finished ** executing. The return value is the result code. SQLITE_OK is returned ** if the statement executed successfully and some other value is returned if @@ -1123,7 +1075,7 @@ const void *sqlite3_column_decltype16(sqlite3_stmt*,int); ** SQLITE_DONE. Or it could be the case the the same database connection ** is being used simulataneously by two or more threads. */ -int sqlite3_step_new(sqlite3_stmt*); +int sqlite3_step(sqlite3_stmt*); /* diff --git a/src/test1.c b/src/test1.c index af783efa5..9ced503a3 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.52 2004/05/25 23:35:19 danielk1977 Exp $ +** $Id: test1.c,v 1.53 2004/05/26 00:07:26 danielk1977 Exp $ */ #include "sqliteInt.h" #include "tcl.h" @@ -759,68 +759,6 @@ static int sqlite_datatypes( } /* -** Usage: sqlite3_step VM ?NVAR? ?VALUEVAR? ?COLNAMEVAR? -** -** Step a virtual machine. Return a the result code as a string. -** Column results are written into three variables. -*/ -#if 0 -static int test_step( - void *NotUsed, - Tcl_Interp *interp, /* The TCL interpreter that invoked this command */ - int argc, /* Number of arguments */ - char **argv /* Text of each argument */ -){ - sqlite_vm *vm; - int rc, i; - const char **azValue = 0; - const char **azColName = 0; - int N = 0; - char *zRc; - char zBuf[50]; - 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 = sqlite3_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); - } - } - } - 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 ){ - case SQLITE_DONE: zRc = "SQLITE_DONE"; break; - case SQLITE_BUSY: zRc = "SQLITE_BUSY"; break; - case SQLITE_ROW: zRc = "SQLITE_ROW"; break; - case SQLITE_ERROR: zRc = "SQLITE_ERROR"; break; - case SQLITE_MISUSE: zRc = "SQLITE_MISUSE"; break; - default: zRc = "unknown"; break; - } - Tcl_AppendResult(interp, zRc, 0); - return TCL_OK; -} -#endif - -/* ** Usage: sqlite3_finalize STMT ** ** Finalize a statement handle. @@ -1416,7 +1354,7 @@ static int test_open16( ** ** Advance the statement to the next row. */ -static int test_step_new( +static int test_step( void * clientData, Tcl_Interp *interp, int objc, @@ -1432,9 +1370,10 @@ static int test_step_new( } if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; - rc = sqlite3_step_new(pStmt); + rc = sqlite3_step(pStmt); if( rc!=SQLITE_DONE && rc!=SQLITE_ROW ) return TCL_ERROR; + Tcl_SetResult(interp, errorName(rc), 0); return TCL_OK; } @@ -1506,6 +1445,56 @@ static int test_column_data16( } /* +** Usage: sqlite3_column_count STMT +** +** Return the number of columns returned by the sql statement STMT. +*/ +static int test_column_count( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + sqlite3_stmt *pStmt; + + if( objc!=2 ){ + Tcl_AppendResult(interp, "wrong # args: should be \"", + Tcl_GetString(objv[0]), " STMT column", 0); + return TCL_ERROR; + } + + if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; + + Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_column_count(pStmt))); + return TCL_OK; +} + +/* +** Usage: sqlite3_data_count STMT +** +** Return the number of columns returned by the sql statement STMT. +*/ +static int test_data_count( + void * clientData, + Tcl_Interp *interp, + int objc, + Tcl_Obj *CONST objv[] +){ + sqlite3_stmt *pStmt; + + if( objc!=2 ){ + Tcl_AppendResult(interp, "wrong # args: should be \"", + Tcl_GetString(objv[0]), " STMT column", 0); + return TCL_ERROR; + } + + if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR; + + Tcl_SetObjResult(interp, Tcl_NewIntObj(sqlite3_data_count(pStmt))); + return TCL_OK; +} + +/* ** This is a collating function named "REVERSE" which sorts text ** in reverse order. */ @@ -1577,7 +1566,6 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite_malloc_fail", (Tcl_CmdProc*)sqlite_malloc_fail }, { "sqlite_malloc_stat", (Tcl_CmdProc*)sqlite_malloc_stat }, #endif -/*{ "sqlite_step", (Tcl_CmdProc*)test_step * },*/ { "sqlite_bind", (Tcl_CmdProc*)test_bind }, { "breakpoint", (Tcl_CmdProc*)test_breakpoint }, }; @@ -1601,9 +1589,11 @@ int Sqlitetest1_Init(Tcl_Interp *interp){ { "sqlite3_open16", (Tcl_ObjCmdProc*)test_open16 }, { "sqlite3_finalize", (Tcl_ObjCmdProc*)test_finalize }, { "sqlite3_reset", (Tcl_ObjCmdProc*)test_reset }, - { "sqlite3_step", (Tcl_ObjCmdProc*)test_step_new }, + { "sqlite3_step", (Tcl_ObjCmdProc*)test_step}, { "sqlite3_column_data", (Tcl_ObjCmdProc*)test_column_data }, { "sqlite3_column_data16", (Tcl_ObjCmdProc*)test_column_data16 }, + { "sqlite3_column_count", (Tcl_ObjCmdProc*)test_column_count }, + { "sqlite3_data_count", (Tcl_ObjCmdProc*)test_data_count }, { "add_reverse_collating_func", (Tcl_ObjCmdProc*)reverse_collfunc }, }; int i; diff --git a/src/vdbe.c b/src/vdbe.c index af9189ddb..21c945beb 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -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.329 2004/05/25 23:35:19 danielk1977 Exp $ +** $Id: vdbe.c,v 1.330 2004/05/26 00:07:26 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -493,89 +493,10 @@ static void hardRealify(Mem *pStack, u8 enc){ } /* -** Advance the virtual machine to the next output row. -** -** The return vale will be either SQLITE_BUSY, SQLITE_DONE, -** SQLITE_ROW, SQLITE_ERROR, or SQLITE_MISUSE. -** -** SQLITE_BUSY means that the virtual machine attempted to open -** a locked database and there is no busy callback registered. -** Call sqlite3_step() again to retry the open. *pN is set to 0 -** and *pazColName and *pazValue are both set to NULL. -** -** SQLITE_DONE means that the virtual machine has finished -** executing. sqlite3_step() should not be called again on this -** virtual machine. *pN and *pazColName are set appropriately -** but *pazValue is set to NULL. -** -** SQLITE_ROW means that the virtual machine has generated another -** row of the result set. *pN is set to the number of columns in -** the row. *pazColName is set to the names of the columns followed -** by the column datatypes. *pazValue is set to the values of each -** column in the row. The value of the i-th column is (*pazValue)[i]. -** The name of the i-th column is (*pazColName)[i] and the datatype -** of the i-th column is (*pazColName)[i+*pN]. -** -** SQLITE_ERROR means that a run-time error (such as a constraint -** violation) has occurred. The details of the error will be returned -** by the next call to sqlite3_finalize(). sqlite3_step() should not -** be called again on the VM. -** -** SQLITE_MISUSE means that the this routine was called inappropriately. -** Perhaps it was called on a virtual machine that had already been -** finalized or on one that had previously returned SQLITE_ERROR or -** SQLITE_DONE. Or it could be the case the the same database connection -** is being used simulataneously by two or more threads. -*/ -#if 0 -int sqlite3_step( - sqlite_vm *pVm, /* The virtual machine to execute */ - int *pN, /* OUT: Number of columns in result */ - const char ***pazValue, /* OUT: Column data */ - const char ***pazColName /* OUT: Column names and datatypes */ -){ - sqlite3_stmt *pStmt = (sqlite3_stmt*)pVm; - int rc; - - rc = sqlite3_step_new(pStmt); - - if( pazValue ) *pazValue = 0; - if( pazColName ) *pazColName = 0; - if( pN ) *pN = 0; - - if( rc==SQLITE_DONE || rc==SQLITE_ROW ){ - int i; - int cols = sqlite3_column_count(pStmt) * (pazColName?1:0); - int vals = sqlite3_data_count(pStmt) * (pazValue?1:0); - - /* Temporary memory leak */ - if( cols ) *pazColName = sqliteMalloc(sizeof(char *)*cols * 2); - if( pN ) *pN = cols; - - for(i=0; i<cols; i++){ - (*pazColName)[i] = sqlite3_column_name(pStmt, i); - } - for(i=cols; i<(2*cols); i++){ - (*pazColName)[i] = sqlite3_column_decltype(pStmt, i-cols); - } - - if( rc==SQLITE_ROW ){ - if( vals ) *pazValue = sqliteMalloc(sizeof(char *)*vals); - for(i=0; i<vals; i++){ - (*pazValue)[i] = sqlite3_column_data(pStmt, i); - } - } - } - - return rc; -} -#endif - -/* ** Execute the statement pStmt, either until a row of data is ready, the ** statement is completely executed or an error occurs. */ -int sqlite3_step_new(sqlite3_stmt *pStmt){ +int sqlite3_step(sqlite3_stmt *pStmt){ Vdbe *p = (Vdbe*)pStmt; sqlite *db; int rc; |