Fossil SCM

Make the symbolic_name_to_rid() and checkin_mtime() SQL functions available in the "fossil sql" command. Improve the documentation for the files_in_checkin virtual table.

drh 2015-01-17 14:53 trunk
Commit ba1429cef87c9cb1e27c9281651c7fbbc5f70839
3 files changed +26 -13 +20 +30 -1
+26 -13
--- src/db.c
+++ src/db.c
@@ -757,10 +757,18 @@
757757
if( rc==0 ){
758758
sqlite3_result_int64(context, mtime);
759759
}
760760
}
761761
762
+/*
763
+** SQL wrapper around the symbolic_name_to_rid() C-language API.
764
+** Examples:
765
+**
766
+** symbolic_name_to_rid('trunk');
767
+** symbolic_name_to_rid('trunk','w');
768
+**
769
+*/
762770
void db_sym2rid_function(
763771
sqlite3_context *context,
764772
int argc,
765773
sqlite3_value **argv
766774
){
@@ -786,10 +794,23 @@
786794
sqlite3_result_int64(context, rid);
787795
}
788796
}
789797
}
790798
799
+/*
800
+** Register the SQL functions that are useful both to the internal
801
+** representation and to the "fossil sql" command.
802
+*/
803
+void db_add_aux_functions(sqlite3 *db){
804
+ sqlite3_create_function(db, "checkin_mtime", 2, SQLITE_UTF8, 0,
805
+ db_checkin_mtime_function, 0, 0);
806
+ sqlite3_create_function(db, "symbolic_name_to_rid", 1, SQLITE_UTF8, 0,
807
+ db_sym2rid_function, 0, 0);
808
+ sqlite3_create_function(db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0,
809
+ db_sym2rid_function, 0, 0);
810
+}
811
+
791812
792813
/*
793814
** Open a database file. Return a pointer to the new database
794815
** connection. An error results in process abort.
795816
*/
@@ -806,13 +827,12 @@
806827
if( rc!=SQLITE_OK ){
807828
db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
808829
}
809830
sqlite3_busy_timeout(db, 5000);
810831
sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
811
- sqlite3_create_function(db, "now", 0, SQLITE_UTF8, 0, db_now_function, 0, 0);
812
- sqlite3_create_function(db, "checkin_mtime", 2, SQLITE_UTF8, 0,
813
- db_checkin_mtime_function, 0, 0);
832
+ sqlite3_create_function(db, "now", 0, SQLITE_UTF8, 0,
833
+ db_now_function, 0, 0);
814834
sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
815835
sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
816836
sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
817837
sqlite3_create_function(db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
818838
sqlite3_create_function(
@@ -819,21 +839,14 @@
819839
db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
820840
);
821841
sqlite3_create_function(
822842
db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
823843
);
824
- sqlite3_create_function(
825
- db, "symbolic_name_to_rid", 1, SQLITE_UTF8, 0, db_sym2rid_function,
826
- 0, 0
827
- );
828
- sqlite3_create_function(
829
- db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
830
- 0, 0
831
- );
832844
if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
833
- re_add_sql_func(db);
834
- foci_register(db);
845
+ db_add_aux_functions(db);
846
+ re_add_sql_func(db); /* The REGEXP operator */
847
+ foci_register(db); /* The "files_of_checkin" virtual table */
835848
sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
836849
return db;
837850
}
838851
839852
840853
--- src/db.c
+++ src/db.c
@@ -757,10 +757,18 @@
757 if( rc==0 ){
758 sqlite3_result_int64(context, mtime);
759 }
760 }
761
 
 
 
 
 
 
 
 
762 void db_sym2rid_function(
763 sqlite3_context *context,
764 int argc,
765 sqlite3_value **argv
766 ){
@@ -786,10 +794,23 @@
786 sqlite3_result_int64(context, rid);
787 }
788 }
789 }
790
 
 
 
 
 
 
 
 
 
 
 
 
 
791
792 /*
793 ** Open a database file. Return a pointer to the new database
794 ** connection. An error results in process abort.
795 */
@@ -806,13 +827,12 @@
806 if( rc!=SQLITE_OK ){
807 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
808 }
809 sqlite3_busy_timeout(db, 5000);
810 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
811 sqlite3_create_function(db, "now", 0, SQLITE_UTF8, 0, db_now_function, 0, 0);
812 sqlite3_create_function(db, "checkin_mtime", 2, SQLITE_UTF8, 0,
813 db_checkin_mtime_function, 0, 0);
814 sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
815 sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
816 sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
817 sqlite3_create_function(db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
818 sqlite3_create_function(
@@ -819,21 +839,14 @@
819 db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
820 );
821 sqlite3_create_function(
822 db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
823 );
824 sqlite3_create_function(
825 db, "symbolic_name_to_rid", 1, SQLITE_UTF8, 0, db_sym2rid_function,
826 0, 0
827 );
828 sqlite3_create_function(
829 db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
830 0, 0
831 );
832 if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
833 re_add_sql_func(db);
834 foci_register(db);
 
835 sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
836 return db;
837 }
838
839
840
--- src/db.c
+++ src/db.c
@@ -757,10 +757,18 @@
757 if( rc==0 ){
758 sqlite3_result_int64(context, mtime);
759 }
760 }
761
762 /*
763 ** SQL wrapper around the symbolic_name_to_rid() C-language API.
764 ** Examples:
765 **
766 ** symbolic_name_to_rid('trunk');
767 ** symbolic_name_to_rid('trunk','w');
768 **
769 */
770 void db_sym2rid_function(
771 sqlite3_context *context,
772 int argc,
773 sqlite3_value **argv
774 ){
@@ -786,10 +794,23 @@
794 sqlite3_result_int64(context, rid);
795 }
796 }
797 }
798
799 /*
800 ** Register the SQL functions that are useful both to the internal
801 ** representation and to the "fossil sql" command.
802 */
803 void db_add_aux_functions(sqlite3 *db){
804 sqlite3_create_function(db, "checkin_mtime", 2, SQLITE_UTF8, 0,
805 db_checkin_mtime_function, 0, 0);
806 sqlite3_create_function(db, "symbolic_name_to_rid", 1, SQLITE_UTF8, 0,
807 db_sym2rid_function, 0, 0);
808 sqlite3_create_function(db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0,
809 db_sym2rid_function, 0, 0);
810 }
811
812
813 /*
814 ** Open a database file. Return a pointer to the new database
815 ** connection. An error results in process abort.
816 */
@@ -806,13 +827,12 @@
827 if( rc!=SQLITE_OK ){
828 db_err("[%s]: %s", zDbName, sqlite3_errmsg(db));
829 }
830 sqlite3_busy_timeout(db, 5000);
831 sqlite3_wal_autocheckpoint(db, 1); /* Set to checkpoint frequently */
832 sqlite3_create_function(db, "now", 0, SQLITE_UTF8, 0,
833 db_now_function, 0, 0);
 
834 sqlite3_create_function(db, "user", 0, SQLITE_UTF8, 0, db_sql_user, 0, 0);
835 sqlite3_create_function(db, "cgi", 1, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
836 sqlite3_create_function(db, "cgi", 2, SQLITE_UTF8, 0, db_sql_cgi, 0, 0);
837 sqlite3_create_function(db, "print", -1, SQLITE_UTF8, 0,db_sql_print,0,0);
838 sqlite3_create_function(
@@ -819,21 +839,14 @@
839 db, "is_selected", 1, SQLITE_UTF8, 0, file_is_selected,0,0
840 );
841 sqlite3_create_function(
842 db, "if_selected", 3, SQLITE_UTF8, 0, file_is_selected,0,0
843 );
 
 
 
 
 
 
 
 
844 if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
845 db_add_aux_functions(db);
846 re_add_sql_func(db); /* The REGEXP operator */
847 foci_register(db); /* The "files_of_checkin" virtual table */
848 sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
849 return db;
850 }
851
852
853
+20
--- src/foci.c
+++ src/foci.c
@@ -17,10 +17,30 @@
1717
**
1818
** This routine implements an SQLite virtual table that gives all of the
1919
** files associated with a single checkin.
2020
**
2121
** The filename "foci" is short for "Files Of CheckIn".
22
+**
23
+** Usage example:
24
+**
25
+** CREATE VIRTUAL TABLE temp.foci USING files_of_checkin;
26
+** -- ^^^^--- important!
27
+** SELECT * FROM foci WHERE checkinID=symbolic_name_to_rid('trunk');
28
+**
29
+** The symbolic_name_to_rid('trunk') function finds the BLOB.RID value
30
+** corresponding to the 'trunk' tag. Then the files_of_checkin virtual table
31
+** decodes the manifest defined by that BLOB and returns all files described
32
+** by that manifest. The "schema" for the temp.foci table is:
33
+**
34
+** CREATE TABLE files_of_checkin(
35
+** checkinID INTEGER, -- RID for the checkin manifest
36
+** filename TEXT, -- Name of a file
37
+** uuid TEXT, -- SHA1 hash of the file
38
+** previousName TEXT, -- Name of the file in previous checkin
39
+** perm TEXT -- Permissions on the file
40
+** );
41
+**
2242
*/
2343
#include "config.h"
2444
#include "foci.h"
2545
#include <assert.h>
2646
2747
--- src/foci.c
+++ src/foci.c
@@ -17,10 +17,30 @@
17 **
18 ** This routine implements an SQLite virtual table that gives all of the
19 ** files associated with a single checkin.
20 **
21 ** The filename "foci" is short for "Files Of CheckIn".
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22 */
23 #include "config.h"
24 #include "foci.h"
25 #include <assert.h>
26
27
--- src/foci.c
+++ src/foci.c
@@ -17,10 +17,30 @@
17 **
18 ** This routine implements an SQLite virtual table that gives all of the
19 ** files associated with a single checkin.
20 **
21 ** The filename "foci" is short for "Files Of CheckIn".
22 **
23 ** Usage example:
24 **
25 ** CREATE VIRTUAL TABLE temp.foci USING files_of_checkin;
26 ** -- ^^^^--- important!
27 ** SELECT * FROM foci WHERE checkinID=symbolic_name_to_rid('trunk');
28 **
29 ** The symbolic_name_to_rid('trunk') function finds the BLOB.RID value
30 ** corresponding to the 'trunk' tag. Then the files_of_checkin virtual table
31 ** decodes the manifest defined by that BLOB and returns all files described
32 ** by that manifest. The "schema" for the temp.foci table is:
33 **
34 ** CREATE TABLE files_of_checkin(
35 ** checkinID INTEGER, -- RID for the checkin manifest
36 ** filename TEXT, -- Name of a file
37 ** uuid TEXT, -- SHA1 hash of the file
38 ** previousName TEXT, -- Name of the file in previous checkin
39 ** perm TEXT -- Permissions on the file
40 ** );
41 **
42 */
43 #include "config.h"
44 #include "foci.h"
45 #include <assert.h>
46
47
+30 -1
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -132,10 +132,11 @@
132132
sqlite3 *db,
133133
const char **pzErrMsg,
134134
const void *notUsed
135135
){
136136
add_content_sql_commands(db);
137
+ db_add_aux_functions(db);
137138
re_add_sql_func(db);
138139
g.zMainDbType = "repository";
139140
foci_register(db);
140141
g.repositoryOpen = 1;
141142
g.db = db;
@@ -147,15 +148,43 @@
147148
**
148149
** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
149150
**
150151
** Run the standalone sqlite3 command-line shell on DATABASE with OPTIONS.
151152
** If DATABASE is omitted, then the repository that serves the working
152
-** directory is opened.
153
+** directory is opened. See https://www.sqlite.org/cli.html for additional
154
+** information.
153155
**
154156
** WARNING: Careless use of this command can corrupt a Fossil repository
155157
** in ways that are unrecoverable. Be sure you know what you are doing before
156158
** running any SQL commands that modifies the repository database.
159
+**
160
+** The following extensions to the usual SQLite commands are provided:
161
+**
162
+** content(X) Return the contenxt of artifact X. X can be a
163
+** SHA1 hash or prefix or a tag.
164
+**
165
+** compress(X) Compress text X.
166
+**
167
+** decompress(X) Decompress text X. Undoes the work of
168
+** compress(X).
169
+**
170
+** checkin_mtime(X,Y) Return the mtime for the file Y (a BLOB.RID)
171
+** found in check-in X (another BLOB.RID value).
172
+**
173
+** symbolic_name_to_rid(X) Return a the BLOB.RID corresponding to symbolic
174
+** name X.
175
+**
176
+** REGEXP The REGEXP operator works, unlike in
177
+** standard SQLite.
178
+**
179
+** files_of_checkin The "files_of_check" virtual table is
180
+** available for decoding manifests.
181
+**
182
+** Usage example for files_of_checkin:
183
+**
184
+** CREATE VIRTUAL TABLE temp.foci USING files_of_checkin;
185
+** SELECT * FROM foci WHERE checkinID=symbolic_name_to_rid('trunk');
157186
*/
158187
void cmd_sqlite3(void){
159188
extern int sqlite3_shell(int, char**);
160189
db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
161190
db_close(1);
162191
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -132,10 +132,11 @@
132 sqlite3 *db,
133 const char **pzErrMsg,
134 const void *notUsed
135 ){
136 add_content_sql_commands(db);
 
137 re_add_sql_func(db);
138 g.zMainDbType = "repository";
139 foci_register(db);
140 g.repositoryOpen = 1;
141 g.db = db;
@@ -147,15 +148,43 @@
147 **
148 ** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
149 **
150 ** Run the standalone sqlite3 command-line shell on DATABASE with OPTIONS.
151 ** If DATABASE is omitted, then the repository that serves the working
152 ** directory is opened.
 
153 **
154 ** WARNING: Careless use of this command can corrupt a Fossil repository
155 ** in ways that are unrecoverable. Be sure you know what you are doing before
156 ** running any SQL commands that modifies the repository database.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157 */
158 void cmd_sqlite3(void){
159 extern int sqlite3_shell(int, char**);
160 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
161 db_close(1);
162
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -132,10 +132,11 @@
132 sqlite3 *db,
133 const char **pzErrMsg,
134 const void *notUsed
135 ){
136 add_content_sql_commands(db);
137 db_add_aux_functions(db);
138 re_add_sql_func(db);
139 g.zMainDbType = "repository";
140 foci_register(db);
141 g.repositoryOpen = 1;
142 g.db = db;
@@ -147,15 +148,43 @@
148 **
149 ** Usage: %fossil sqlite3 ?DATABASE? ?OPTIONS?
150 **
151 ** Run the standalone sqlite3 command-line shell on DATABASE with OPTIONS.
152 ** If DATABASE is omitted, then the repository that serves the working
153 ** directory is opened. See https://www.sqlite.org/cli.html for additional
154 ** information.
155 **
156 ** WARNING: Careless use of this command can corrupt a Fossil repository
157 ** in ways that are unrecoverable. Be sure you know what you are doing before
158 ** running any SQL commands that modifies the repository database.
159 **
160 ** The following extensions to the usual SQLite commands are provided:
161 **
162 ** content(X) Return the contenxt of artifact X. X can be a
163 ** SHA1 hash or prefix or a tag.
164 **
165 ** compress(X) Compress text X.
166 **
167 ** decompress(X) Decompress text X. Undoes the work of
168 ** compress(X).
169 **
170 ** checkin_mtime(X,Y) Return the mtime for the file Y (a BLOB.RID)
171 ** found in check-in X (another BLOB.RID value).
172 **
173 ** symbolic_name_to_rid(X) Return a the BLOB.RID corresponding to symbolic
174 ** name X.
175 **
176 ** REGEXP The REGEXP operator works, unlike in
177 ** standard SQLite.
178 **
179 ** files_of_checkin The "files_of_check" virtual table is
180 ** available for decoding manifests.
181 **
182 ** Usage example for files_of_checkin:
183 **
184 ** CREATE VIRTUAL TABLE temp.foci USING files_of_checkin;
185 ** SELECT * FROM foci WHERE checkinID=symbolic_name_to_rid('trunk');
186 */
187 void cmd_sqlite3(void){
188 extern int sqlite3_shell(int, char**);
189 db_find_and_open_repository(OPEN_ANY_SCHEMA, 0);
190 db_close(1);
191

Keyboard Shortcuts

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