Fossil SCM

Added SQL function user() implemented by Brian

jeremy_c 2009-12-31 22:30 trunk
Commit a2c2e3b115a97d72202a6142a0f373ffe9a77be9
1 file changed +15
+15
--- src/db.c
+++ src/db.c
@@ -1053,10 +1053,24 @@
10531053
}
10541054
static void db_sql_trace(void *notUsed, const char *zSql){
10551055
int n = strlen(zSql);
10561056
fprintf(stderr, "%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";");
10571057
}
1058
+
1059
+/*
1060
+** Implement the user() SQL function. user() takes no arguments and
1061
+** returns the user ID of the current user.
1062
+*/
1063
+static void db_sql_user(
1064
+ sqlite3_context *context,
1065
+ int argc,
1066
+ sqlite3_value **argv
1067
+){
1068
+ if( g.zLogin!=0 ){
1069
+ sqlite3_result_text(context, g.zLogin, -1, SQLITE_STATIC);
1070
+ }
1071
+}
10581072
10591073
/*
10601074
** This is used by the [commit] command.
10611075
**
10621076
** Return true if either:
@@ -1150,10 +1164,11 @@
11501164
*/
11511165
LOCAL void db_connection_init(void){
11521166
static int once = 1;
11531167
if( once ){
11541168
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);
11551170
sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
11561171
sqlite3_create_function(
11571172
g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
11581173
);
11591174
if( g.fSqlTrace ){
11601175
--- src/db.c
+++ src/db.c
@@ -1053,10 +1053,24 @@
1053 }
1054 static void db_sql_trace(void *notUsed, const char *zSql){
1055 int n = strlen(zSql);
1056 fprintf(stderr, "%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";");
1057 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1058
1059 /*
1060 ** This is used by the [commit] command.
1061 **
1062 ** Return true if either:
@@ -1150,10 +1164,11 @@
1150 */
1151 LOCAL void db_connection_init(void){
1152 static int once = 1;
1153 if( once ){
1154 sqlite3_exec(g.db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
 
1155 sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
1156 sqlite3_create_function(
1157 g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
1158 );
1159 if( g.fSqlTrace ){
1160
--- src/db.c
+++ src/db.c
@@ -1053,10 +1053,24 @@
1053 }
1054 static void db_sql_trace(void *notUsed, const char *zSql){
1055 int n = strlen(zSql);
1056 fprintf(stderr, "%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";");
1057 }
1058
1059 /*
1060 ** Implement the user() SQL function. user() takes no arguments and
1061 ** returns the user ID of the current user.
1062 */
1063 static void db_sql_user(
1064 sqlite3_context *context,
1065 int argc,
1066 sqlite3_value **argv
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:
@@ -1150,10 +1164,11 @@
1164 */
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

Keyboard Shortcuts

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