1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-07 02:42:48 +03:00

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
This commit is contained in:
drh
2004-09-07 16:19:52 +00:00
parent 1807ce37b8
commit fa6bc0000f
11 changed files with 299 additions and 48 deletions

View File

@@ -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;
}