Fossil SCM
Added the cgi() SQL function implemented by Brain Theado.
Commit
19f552795b5c4ba33817aa37cfa118c03f4b61c7
Parent
2239226012a7f4b…
1 file changed
+20
M
src/db.c
+20
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1067,10 +1067,28 @@ | ||
| 1067 | 1067 | ){ |
| 1068 | 1068 | if( g.zLogin!=0 ){ |
| 1069 | 1069 | sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC); |
| 1070 | 1070 | } |
| 1071 | 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 | +} | |
| 1072 | 1090 | |
| 1073 | 1091 | /* |
| 1074 | 1092 | ** This is used by the [commit] command. |
| 1075 | 1093 | ** |
| 1076 | 1094 | ** Return true if either: |
| @@ -1165,10 +1183,12 @@ | ||
| 1165 | 1183 | LOCAL void db_connection_init(void){ |
| 1166 | 1184 | static int once = 1; |
| 1167 | 1185 | if( once ){ |
| 1168 | 1186 | sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0); |
| 1169 | 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); | |
| 1170 | 1190 | sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0); |
| 1171 | 1191 | sqlite3_create_function( |
| 1172 | 1192 | g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0 |
| 1173 | 1193 | ); |
| 1174 | 1194 | if( g.fSqlTrace ){ |
| 1175 | 1195 |
| --- 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 |