1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
|
int argc,
sqlite3_value **argv
){
if( g.zLogin!=0 ){
sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
}
}
/*
** Implement the cgi() SQL function. cgi() takes a an argument which is
** a name of CGI query parameter. The value of that parameter is returned,
** if available. optional second argument will be returned if the first
** doesn't exist as a CGI parameter.
*/
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
|
int argc,
sqlite3_value **argv
){
if( g.zLogin!=0 ){
sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
}
}
/*
** Make the content_get function available within a SQL query.
*/
static void db_sql_content_get(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
int rid;
Blob content;
if( argc != 1 ) return;
rid = sqlite3_value_int(argv[0]);
content_get(rid, &content);
sqlite3_result_text(context, blob_str(&content), -1, SQLITE_TRANSIENT);
}
/*
** Retrieve the most recent revision ID of a file.
*/
static void db_sql_get_file_rid(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const unsigned char *fnid;
int rid;
Stmt q;
if ( argc != 1 ) return;
fnid = sqlite3_value_text(argv[0]);
db_prepare(&q, "SELECT fid FROM mlink WHERE fnid=%Q and mid= "
"(SELECT objid FROM (SELECT objid, mtime FROM event WHERE objid IN "
"(SELECT mid FROM mlink WHERE fnid=%Q) "
"ORDER BY mtime DESC) LIMIT 1);", fnid, fnid);
db_step(&q);
rid = db_column_int(&q, 0);
sqlite3_result_int(context, rid);
db_finalize(&q);
}
/*
** Retrieve the most recent revision ID of a wiki entry.
*/
static void db_sql_get_wiki_rid(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const unsigned char *tagid;
int rid;
Stmt q;
if ( argc != 1 ) return;
tagid = sqlite3_value_text(argv[0]);
db_prepare(&q, "SELECT rid FROM tagxref WHERE tagid=%Q ORDER BY mtime DESC LIMIT 1", tagid);
db_step(&q);
rid = db_column_int(&q, 0);
sqlite3_result_int(context, rid);
db_finalize(&q);
}
/*
** Implement the cgi() SQL function. cgi() takes a an argument which is
** a name of CGI query parameter. The value of that parameter is returned,
** if available. optional second argument will be returned if the first
** doesn't exist as a CGI parameter.
*/
|
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
|
*/
LOCAL void db_connection_init(void){
sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
sqlite3_create_function(g.db, "user", 0, SQLITE_ANY, 0, db_sql_user, 0, 0);
sqlite3_create_function(g.db, "cgi", 1, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
sqlite3_create_function(g.db, "cgi", 2, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
sqlite3_create_function(
g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
);
if( g.fSqlTrace ){
sqlite3_trace(g.db, db_sql_trace, 0);
}
}
|
>
>
>
|
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
|
*/
LOCAL void db_connection_init(void){
sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
sqlite3_create_function(g.db, "user", 0, SQLITE_ANY, 0, db_sql_user, 0, 0);
sqlite3_create_function(g.db, "cgi", 1, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
sqlite3_create_function(g.db, "cgi", 2, SQLITE_ANY, 0, db_sql_cgi, 0, 0);
sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
sqlite3_create_function(g.db, "content_get", 1, SQLITE_ANY, 0, db_sql_content_get, 0, 0);
sqlite3_create_function(g.db, "get_file_rid", 1, SQLITE_ANY, 0, db_sql_get_file_rid, 0, 0);
sqlite3_create_function(g.db, "get_wiki_rid", 1, SQLITE_ANY, 0, db_sql_get_wiki_rid, 0, 0);
sqlite3_create_function(
g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
);
if( g.fSqlTrace ){
sqlite3_trace(g.db, db_sql_trace, 0);
}
}
|