Fossil SCM

Added the cgi() SQL function implemented by Brain Theado.

jeremy_c 2010-01-09 12:35 trunk
Commit 19f552795b5c4ba33817aa37cfa118c03f4b61c7
1 file changed +20
+20
--- src/db.c
+++ src/db.c
@@ -1067,10 +1067,28 @@
10671067
){
10681068
if( g.zLogin!=0 ){
10691069
sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
10701070
}
10711071
}
1072
+
1073
+/*
1074
+** Implement the cgi() SQL function. cgi() takes a an argument which is
1075
+** a name of CGI query parameter. The value of that parameter is returned,
1076
+** if available. optional second argument will be returned if the first
1077
+** doesn't exist as a CGI parameter.
1078
+*/
1079
+static void db_sql_cgi(sqlite3_context *context, int argc, sqlite3_value **argv){
1080
+ const char* zP;
1081
+ if( argc!=1 && argc!=2 ) return;
1082
+ zP = P((const char*)sqlite3_value_text(argv[0]));
1083
+ if( zP ){
1084
+ sqlite3_result_text(context, zP, -1, SQLITE_STATIC);
1085
+ }else if( argc==2 ){
1086
+ zP = (const char*)sqlite3_value_text(argv[1]);
1087
+ if( zP ) sqlite3_result_text(context, zP, -1, SQLITE_TRANSIENT);
1088
+ }
1089
+}
10721090
10731091
/*
10741092
** This is used by the [commit] command.
10751093
**
10761094
** Return true if either:
@@ -1165,10 +1183,12 @@
11651183
LOCAL void db_connection_init(void){
11661184
static int once = 1;
11671185
if( once ){
11681186
sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
11691187
sqlite3_create_function(g.db, "user", 0, SQLITE_ANY, 0, db_sql_user, 0, 0);
1188
+ sqlite3_create_function(g.db, "cgi", 1, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
1189
+ sqlite3_create_function(g.db, "cgi", 2, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
11701190
sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
11711191
sqlite3_create_function(
11721192
g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
11731193
);
11741194
if( g.fSqlTrace ){
11751195
--- src/db.c
+++ src/db.c
@@ -1067,10 +1067,28 @@
1067 ){
1068 if( g.zLogin!=0 ){
1069 sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
1070 }
1071 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1072
1073 /*
1074 ** This is used by the [commit] command.
1075 **
1076 ** Return true if either:
@@ -1165,10 +1183,12 @@
1165 LOCAL void db_connection_init(void){
1166 static int once = 1;
1167 if( once ){
1168 sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
1169 sqlite3_create_function(g.db, "user", 0, SQLITE_ANY, 0, db_sql_user, 0, 0);
 
 
1170 sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
1171 sqlite3_create_function(
1172 g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
1173 );
1174 if( g.fSqlTrace ){
1175
--- src/db.c
+++ src/db.c
@@ -1067,10 +1067,28 @@
1067 ){
1068 if( g.zLogin!=0 ){
1069 sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
1070 }
1071 }
1072
1073 /*
1074 ** Implement the cgi() SQL function. cgi() takes a an argument which is
1075 ** a name of CGI query parameter. The value of that parameter is returned,
1076 ** if available. optional second argument will be returned if the first
1077 ** doesn't exist as a CGI parameter.
1078 */
1079 static void db_sql_cgi(sqlite3_context *context, int argc, sqlite3_value **argv){
1080 const char* zP;
1081 if( argc!=1 && argc!=2 ) return;
1082 zP = P((const char*)sqlite3_value_text(argv[0]));
1083 if( zP ){
1084 sqlite3_result_text(context, zP, -1, SQLITE_STATIC);
1085 }else if( argc==2 ){
1086 zP = (const char*)sqlite3_value_text(argv[1]);
1087 if( zP ) sqlite3_result_text(context, zP, -1, SQLITE_TRANSIENT);
1088 }
1089 }
1090
1091 /*
1092 ** This is used by the [commit] command.
1093 **
1094 ** Return true if either:
@@ -1165,10 +1183,12 @@
1183 LOCAL void db_connection_init(void){
1184 static int once = 1;
1185 if( once ){
1186 sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
1187 sqlite3_create_function(g.db, "user", 0, SQLITE_ANY, 0, db_sql_user, 0, 0);
1188 sqlite3_create_function(g.db, "cgi", 1, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
1189 sqlite3_create_function(g.db, "cgi", 2, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
1190 sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
1191 sqlite3_create_function(
1192 g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
1193 );
1194 if( g.fSqlTrace ){
1195

Keyboard Shortcuts

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