aboutsummaryrefslogtreecommitdiff
path: root/src/vdbeapi.c
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2004-09-07 16:19:52 +0000
committerdrh <drh@noemail.net>2004-09-07 16:19:52 +0000
commitfa6bc0000fc5b52903cbcb36bacc78833d320e4e (patch)
tree0affec0b5d7fbaecde46d403133d36ce45dbc300 /src/vdbeapi.c
parent1807ce37b84a2a41638f01e59c501a6800bb7883 (diff)
downloadsqlite-fa6bc0000fc5b52903cbcb36bacc78833d320e4e.tar.gz
sqlite-fa6bc0000fc5b52903cbcb36bacc78833d320e4e.zip
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
Diffstat (limited to 'src/vdbeapi.c')
-rw-r--r--src/vdbeapi.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/src/vdbeapi.c b/src/vdbeapi.c
index b238c7fe7..f5abe0ee6 100644
--- a/src/vdbeapi.c
+++ b/src/vdbeapi.c
@@ -525,16 +525,11 @@ int sqlite3_bind_parameter_count(sqlite3_stmt *pStmt){
}
/*
-** 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 @@ const char *sqlite3_bind_parameter_name(sqlite3_stmt *pStmt, int i){
}
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;
+}