Fossil SCM

Fill in SQL parameters in report formats using HTTP query parameter values.

drh 2016-08-22 15:20 trunk
Commit 0ef09dc9cd8b7bad61930e7e3a18a6db651fecdb
1 file changed +13 -3
+13 -3
--- src/report.c
+++ src/report.c
@@ -896,10 +896,11 @@
896896
sqlite3_stmt *pStmt = 0; /* The current SQL statement */
897897
const char **azCols = 0; /* Names of result columns */
898898
int nCol; /* Number of columns of output */
899899
const char **azVals = 0; /* Text of all output columns */
900900
int i; /* Loop counter */
901
+ int nVar; /* Number of parameters */
901902
902903
pStmt = 0;
903904
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
904905
assert( rc==SQLITE_OK || pStmt==0 );
905906
if( rc!=SQLITE_OK ){
@@ -912,13 +913,22 @@
912913
if( !sqlite3_stmt_readonly(pStmt) ){
913914
sqlite3_finalize(pStmt);
914915
return SQLITE_ERROR;
915916
}
916917
917
- i = sqlite3_bind_parameter_index(pStmt, "$login");
918
- if( i ) sqlite3_bind_text(pStmt, i, g.zLogin, -1, SQLITE_TRANSIENT);
919
-
918
+ nVar = sqlite3_bind_parameter_count(pStmt);
919
+ for(i=1; i<=nVar; i++){
920
+ const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
921
+ if( zVar==0 ) continue;
922
+ if( zVar[0]!='$' && zVar[0]!='$' && zVar[0]!=':' ) continue;
923
+ if( !fossil_islower(zVar[1]) ) continue;
924
+ if( strcmp(zVar, "$login")==0 ){
925
+ sqlite3_bind_text(pStmt, i, g.zLogin, -1, SQLITE_TRANSIENT);
926
+ }else{
927
+ sqlite3_bind_text(pStmt, i, P(zVar+1), -1, SQLITE_TRANSIENT);
928
+ }
929
+ }
920930
nCol = sqlite3_column_count(pStmt);
921931
azVals = fossil_malloc(2*nCol*sizeof(const char*) + 1);
922932
while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
923933
if( azCols==0 ){
924934
azCols = &azVals[nCol];
925935
--- src/report.c
+++ src/report.c
@@ -896,10 +896,11 @@
896 sqlite3_stmt *pStmt = 0; /* The current SQL statement */
897 const char **azCols = 0; /* Names of result columns */
898 int nCol; /* Number of columns of output */
899 const char **azVals = 0; /* Text of all output columns */
900 int i; /* Loop counter */
 
901
902 pStmt = 0;
903 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
904 assert( rc==SQLITE_OK || pStmt==0 );
905 if( rc!=SQLITE_OK ){
@@ -912,13 +913,22 @@
912 if( !sqlite3_stmt_readonly(pStmt) ){
913 sqlite3_finalize(pStmt);
914 return SQLITE_ERROR;
915 }
916
917 i = sqlite3_bind_parameter_index(pStmt, "$login");
918 if( i ) sqlite3_bind_text(pStmt, i, g.zLogin, -1, SQLITE_TRANSIENT);
919
 
 
 
 
 
 
 
 
 
920 nCol = sqlite3_column_count(pStmt);
921 azVals = fossil_malloc(2*nCol*sizeof(const char*) + 1);
922 while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
923 if( azCols==0 ){
924 azCols = &azVals[nCol];
925
--- src/report.c
+++ src/report.c
@@ -896,10 +896,11 @@
896 sqlite3_stmt *pStmt = 0; /* The current SQL statement */
897 const char **azCols = 0; /* Names of result columns */
898 int nCol; /* Number of columns of output */
899 const char **azVals = 0; /* Text of all output columns */
900 int i; /* Loop counter */
901 int nVar; /* Number of parameters */
902
903 pStmt = 0;
904 rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, &zLeftover);
905 assert( rc==SQLITE_OK || pStmt==0 );
906 if( rc!=SQLITE_OK ){
@@ -912,13 +913,22 @@
913 if( !sqlite3_stmt_readonly(pStmt) ){
914 sqlite3_finalize(pStmt);
915 return SQLITE_ERROR;
916 }
917
918 nVar = sqlite3_bind_parameter_count(pStmt);
919 for(i=1; i<=nVar; i++){
920 const char *zVar = sqlite3_bind_parameter_name(pStmt, i);
921 if( zVar==0 ) continue;
922 if( zVar[0]!='$' && zVar[0]!='$' && zVar[0]!=':' ) continue;
923 if( !fossil_islower(zVar[1]) ) continue;
924 if( strcmp(zVar, "$login")==0 ){
925 sqlite3_bind_text(pStmt, i, g.zLogin, -1, SQLITE_TRANSIENT);
926 }else{
927 sqlite3_bind_text(pStmt, i, P(zVar+1), -1, SQLITE_TRANSIENT);
928 }
929 }
930 nCol = sqlite3_column_count(pStmt);
931 azVals = fossil_malloc(2*nCol*sizeof(const char*) + 1);
932 while( (rc = sqlite3_step(pStmt))==SQLITE_ROW ){
933 if( azCols==0 ){
934 azCols = &azVals[nCol];
935

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button