Wildcards with the same name map into the same variable number. New
api sqlite3_bind_parameter_index() added to map wildcard names into
wildcard index numbers. Support for "?nnn" wildcards. (CVS 1945)
FossilOrigin-Name: 435b3f301fbb6953adc974c7f03589b06e9114c3
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index b238c7f..f5abe0e 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -525,16 +525,11 @@
}
/*
-** Return the name of a wildcard parameter. Return NULL if the index
-** is out of range or if the wildcard is unnamed.
-**
-** The result is always UTF-8.
+** Create a mapping from variable numbers to variable names
+** in the Vdbe.azVar[] array, if such a mapping does not already
+** exist.
*/
-const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
- Vdbe *p = (Vdbe*)pStmt;
- if( p==0 || i<1 || i>p->nVar ){
- return 0;
- }
+static void createVarMap(Vdbe *p){
if( !p->okVar ){
int j;
Op *pOp;
@@ -546,5 +541,39 @@
}
p->okVar = 1;
}
+}
+
+/*
+** Return the name of a wildcard parameter. Return NULL if the index
+** is out of range or if the wildcard is unnamed.
+**
+** The result is always UTF-8.
+*/
+const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
+ Vdbe *p = (Vdbe*)pStmt;
+ if( p==0 || i<1 || i>p->nVar ){
+ return 0;
+ }
+ createVarMap(p);
return p->azVar[i-1];
}
+
+/*
+** Given a wildcard parameter name, return the index of the variable
+** with that name. If there is no variable with the given name,
+** return 0.
+*/
+int sqlite3_bind_parameter_index(sqlite3_stmt *pStmt, const char *zName){
+ Vdbe *p = (Vdbe*)pStmt;
+ int i;
+ if( p==0 ){
+ return 0;
+ }
+ createVarMap(p);
+ for(i=0; i<p->nVar; i++){
+ if( strcmp(p->azVar[i],zName)==0 ){
+ return i+1;
+ }
+ }
+ return 0;
+}