From 6003884975d47db730bfcfa0b4f8ea1d039a6da3 Mon Sep 17 00:00:00 2001 From: "vladimir%pobox.com" Date: Wed, 13 Apr 2005 23:25:41 +0000 Subject: [PATCH] add parameter_indexes api --- db/sqlite3/src/vdbeapi.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/db/sqlite3/src/vdbeapi.c b/db/sqlite3/src/vdbeapi.c index 663bc9a60b29..ba4bf4ef2e68 100644 --- a/db/sqlite3/src/vdbeapi.c +++ b/db/sqlite3/src/vdbeapi.c @@ -623,14 +623,46 @@ int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){ return 0; } +/* +** Given a wildcard parameter name, return the set of indexes of the +** variables with that name. If there are no variables with the given +** name, return 0. Otherwise, return the number of indexes returned +** in *pIndexes. The array should be freed with +** sqlite3_free_parameter_indexes. +*/ int sqlite3_bind_parameter_indexes( sqlite3_stmt *pStmt, const char *zName, int **pIndexes ){ + Vdbe *p = (Vdbe*)pStmt; + int i, j, nVars, *indexes; + if( p==0 ){ return 0; + } + createVarMap(p); + if( !zName ) + return 0; + /* first count */ + nVars = 0; + for(i=0; inVar; i++){ + const char *z = p->azVar[i]; + if( z && strcmp(z,zName)==0 ){ + nVars++; + } + } + indexes = sqliteMalloc( sizeof(int) * nVars ); + j = 0; + for(i=0; inVar; i++){ + const char *z = p->azVar[i]; + if( z && strcmp(z,zName)==0 ) + indexes[j++] = i+1; + } + *pIndexes = indexes; + return nVars; } void sqlite3_free_parameter_indexes(int *pIndexes) { + sqliteFree( pIndexes ); }