Fossil SCM
Added SQL function user() implemented by Brian
Commit
a2c2e3b115a97d72202a6142a0f373ffe9a77be9
Parent
9b70675778479f7…
1 file changed
+15
M
src/db.c
+15
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -1053,10 +1053,24 @@ | ||
| 1053 | 1053 | } |
| 1054 | 1054 | static void db_sql_trace(void *notUsed, const char *zSql){ |
| 1055 | 1055 | int n = strlen(zSql); |
| 1056 | 1056 | fprintf(stderr, "%s%s\n", zSql, (n>0 && zSql[n-1]==';') ? "" : ";"); |
| 1057 | 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 | +} | |
| 1058 | 1072 | |
| 1059 | 1073 | /* |
| 1060 | 1074 | ** This is used by the [commit] command. |
| 1061 | 1075 | ** |
| 1062 | 1076 | ** Return true if either: |
| @@ -1150,10 +1164,11 @@ | ||
| 1150 | 1164 | */ |
| 1151 | 1165 | LOCAL void db_connection_init(void){ |
| 1152 | 1166 | static int once = 1; |
| 1153 | 1167 | if( once ){ |
| 1154 | 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); | |
| 1155 | 1170 | sqlite3_create_function(g.db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0); |
| 1156 | 1171 | sqlite3_create_function( |
| 1157 | 1172 | g.db, "file_is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0 |
| 1158 | 1173 | ); |
| 1159 | 1174 | if( g.fSqlTrace ){ |
| 1160 | 1175 |
| --- 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 |