Fossil SCM

Remember which database was opened first (as the "main" database) in the g.zMainDbType global variable.

drh 2010-12-17 12:03 trunk
Commit 99f52f3806ead4cdbef4b1a05f0dc36119d48ae4
4 files changed +1 -2 +1 -1 +8 -5 +7 -5
+1 -2
--- src/db.c
+++ src/db.c
@@ -618,18 +618,17 @@
618618
** already open, then attach zDbName using the name zLabel.
619619
*/
620620
static void db_open_or_attach(const char *zDbName, const char *zLabel){
621621
if( !g.db ){
622622
g.db = openDatabase(zDbName);
623
- g.zRepoDb = "main";
623
+ g.zMainDbType = zLabel;
624624
db_connection_init();
625625
}else{
626626
#if defined(_WIN32)
627627
zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
628628
#endif
629629
db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
630
- g.zRepoDb = mprintf("%s", zLabel);
631630
}
632631
}
633632
634633
/*
635634
** Open the user database in "~/.fossil". Create the database anew if
636635
--- src/db.c
+++ src/db.c
@@ -618,18 +618,17 @@
618 ** already open, then attach zDbName using the name zLabel.
619 */
620 static void db_open_or_attach(const char *zDbName, const char *zLabel){
621 if( !g.db ){
622 g.db = openDatabase(zDbName);
623 g.zRepoDb = "main";
624 db_connection_init();
625 }else{
626 #if defined(_WIN32)
627 zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
628 #endif
629 db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
630 g.zRepoDb = mprintf("%s", zLabel);
631 }
632 }
633
634 /*
635 ** Open the user database in "~/.fossil". Create the database anew if
636
--- src/db.c
+++ src/db.c
@@ -618,18 +618,17 @@
618 ** already open, then attach zDbName using the name zLabel.
619 */
620 static void db_open_or_attach(const char *zDbName, const char *zLabel){
621 if( !g.db ){
622 g.db = openDatabase(zDbName);
623 g.zMainDbType = zLabel;
624 db_connection_init();
625 }else{
626 #if defined(_WIN32)
627 zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
628 #endif
629 db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
 
630 }
631 }
632
633 /*
634 ** Open the user database in "~/.fossil". Create the database anew if
635
+1 -1
--- src/main.c
+++ src/main.c
@@ -55,11 +55,11 @@
5555
int useAttach; /* True if global_config is attached to repository */
5656
int configOpen; /* True if the config database is open */
5757
long long int now; /* Seconds since 1970 */
5858
int repositoryOpen; /* True if the main repository database is open */
5959
char *zRepositoryName; /* Name of the repository database */
60
- char *zRepoDb; /* SQLite database name for the repository */
60
+ const char *zMainDbType;/* "configdb", "localdb", or "repository" */
6161
const char *zHome; /* Name of user home directory */
6262
int localOpen; /* True if the local database is open */
6363
char *zLocalRoot; /* The directory holding the local database */
6464
int minPrefix; /* Number of digits needed for a distinct UUID */
6565
int fSqlTrace; /* True if -sqltrace flag is present */
6666
--- src/main.c
+++ src/main.c
@@ -55,11 +55,11 @@
55 int useAttach; /* True if global_config is attached to repository */
56 int configOpen; /* True if the config database is open */
57 long long int now; /* Seconds since 1970 */
58 int repositoryOpen; /* True if the main repository database is open */
59 char *zRepositoryName; /* Name of the repository database */
60 char *zRepoDb; /* SQLite database name for the repository */
61 const char *zHome; /* Name of user home directory */
62 int localOpen; /* True if the local database is open */
63 char *zLocalRoot; /* The directory holding the local database */
64 int minPrefix; /* Number of digits needed for a distinct UUID */
65 int fSqlTrace; /* True if -sqltrace flag is present */
66
--- src/main.c
+++ src/main.c
@@ -55,11 +55,11 @@
55 int useAttach; /* True if global_config is attached to repository */
56 int configOpen; /* True if the config database is open */
57 long long int now; /* Seconds since 1970 */
58 int repositoryOpen; /* True if the main repository database is open */
59 char *zRepositoryName; /* Name of the repository database */
60 const char *zMainDbType;/* "configdb", "localdb", or "repository" */
61 const char *zHome; /* Name of user home directory */
62 int localOpen; /* True if the local database is open */
63 char *zLocalRoot; /* The directory holding the local database */
64 int minPrefix; /* Number of digits needed for a distinct UUID */
65 int fSqlTrace; /* True if -sqltrace flag is present */
66
+8 -5
--- src/stat.c
+++ src/stat.c
@@ -29,10 +29,11 @@
2929
*/
3030
void stat_page(void){
3131
i64 t, fsize;
3232
int n, m;
3333
int szMax, szAvg;
34
+ const char *zDb;
3435
char zBuf[100];
3536
3637
login_check_credentials();
3738
if( !g.okRead ){ login_needed(); return; }
3839
style_header("Repository Statistics");
@@ -108,18 +109,20 @@
108109
@ %h(MANIFEST_DATE) %h(MANIFEST_VERSION) (%h(COMPILER_NAME))
109110
@ </td></tr>
110111
@ <tr><th>SQLite&nbsp;Version:</th><td>
111112
sqlite3_snprintf(sizeof(zBuf), zBuf, "%.19s [%.10s] (%s)",
112113
SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION);
114
+ zDb = "repository";
115
+ if( strcmp(g.zMainDbType, zDb)==0 ) zDb = "main";
113116
@ %s(zBuf)
114117
@ </td></tr>
115118
@ <tr><th>Database&nbsp;Stats:</th><td>
116
- @ %d(db_int(0, "PRAGMA %s.page_count", g.zRepoDb)) pages,
117
- @ %d(db_int(0, "PRAGMA %s.page_size", g.zRepoDb)) bytes/page,
118
- @ %d(db_int(0, "PRAGMA %s.freelist_count", g.zRepoDb)) free pages,
119
- @ %s(db_text(0, "PRAGMA %s.encoding", g.zRepoDb)),
120
- @ %s(db_text(0, "PRAGMA %s.journal_mode", g.zRepoDb)) mode
119
+ @ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages,
120
+ @ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page,
121
+ @ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages,
122
+ @ %s(db_text(0, "PRAGMA %s.encoding", zDb)),
123
+ @ %s(db_text(0, "PRAGMA %s.journal_mode", zDb)) mode
121124
@ </td></tr>
122125
123126
@ </table>
124127
style_footer();
125128
}
126129
--- src/stat.c
+++ src/stat.c
@@ -29,10 +29,11 @@
29 */
30 void stat_page(void){
31 i64 t, fsize;
32 int n, m;
33 int szMax, szAvg;
 
34 char zBuf[100];
35
36 login_check_credentials();
37 if( !g.okRead ){ login_needed(); return; }
38 style_header("Repository Statistics");
@@ -108,18 +109,20 @@
108 @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION) (%h(COMPILER_NAME))
109 @ </td></tr>
110 @ <tr><th>SQLite&nbsp;Version:</th><td>
111 sqlite3_snprintf(sizeof(zBuf), zBuf, "%.19s [%.10s] (%s)",
112 SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION);
 
 
113 @ %s(zBuf)
114 @ </td></tr>
115 @ <tr><th>Database&nbsp;Stats:</th><td>
116 @ %d(db_int(0, "PRAGMA %s.page_count", g.zRepoDb)) pages,
117 @ %d(db_int(0, "PRAGMA %s.page_size", g.zRepoDb)) bytes/page,
118 @ %d(db_int(0, "PRAGMA %s.freelist_count", g.zRepoDb)) free pages,
119 @ %s(db_text(0, "PRAGMA %s.encoding", g.zRepoDb)),
120 @ %s(db_text(0, "PRAGMA %s.journal_mode", g.zRepoDb)) mode
121 @ </td></tr>
122
123 @ </table>
124 style_footer();
125 }
126
--- src/stat.c
+++ src/stat.c
@@ -29,10 +29,11 @@
29 */
30 void stat_page(void){
31 i64 t, fsize;
32 int n, m;
33 int szMax, szAvg;
34 const char *zDb;
35 char zBuf[100];
36
37 login_check_credentials();
38 if( !g.okRead ){ login_needed(); return; }
39 style_header("Repository Statistics");
@@ -108,18 +109,20 @@
109 @ %h(MANIFEST_DATE) %h(MANIFEST_VERSION) (%h(COMPILER_NAME))
110 @ </td></tr>
111 @ <tr><th>SQLite&nbsp;Version:</th><td>
112 sqlite3_snprintf(sizeof(zBuf), zBuf, "%.19s [%.10s] (%s)",
113 SQLITE_SOURCE_ID, &SQLITE_SOURCE_ID[20], SQLITE_VERSION);
114 zDb = "repository";
115 if( strcmp(g.zMainDbType, zDb)==0 ) zDb = "main";
116 @ %s(zBuf)
117 @ </td></tr>
118 @ <tr><th>Database&nbsp;Stats:</th><td>
119 @ %d(db_int(0, "PRAGMA %s.page_count", zDb)) pages,
120 @ %d(db_int(0, "PRAGMA %s.page_size", zDb)) bytes/page,
121 @ %d(db_int(0, "PRAGMA %s.freelist_count", zDb)) free pages,
122 @ %s(db_text(0, "PRAGMA %s.encoding", zDb)),
123 @ %s(db_text(0, "PRAGMA %s.journal_mode", zDb)) mode
124 @ </td></tr>
125
126 @ </table>
127 style_footer();
128 }
129
+7 -5
--- src/undo.c
+++ src/undo.c
@@ -151,23 +151,25 @@
151151
/*
152152
** Begin capturing a snapshot that can be undone.
153153
*/
154154
void undo_begin(void){
155155
int cid;
156
+ const char *zDb = "localdb";
156157
static const char zSql[] =
157
- @ CREATE TABLE undo(
158
+ @ CREATE TABLE %s.undo(
158159
@ pathname TEXT UNIQUE, -- Name of the file
159160
@ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
160161
@ existsflag BOOLEAN, -- True if the file exists
161162
@ content BLOB -- Saved content
162163
@ );
163
- @ CREATE TABLE undo_vfile AS SELECT * FROM vfile;
164
- @ CREATE TABLE undo_vmerge AS SELECT * FROM vmerge;
165
- @ CREATE TABLE undo_pending(undoId INTEGER PRIMARY KEY);
164
+ @ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile;
165
+ @ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
166
+ @ CREATE TABLE %s.undo_pending(undoId INTEGER PRIMARY KEY);
166167
;
167168
undo_reset();
168
- db_multi_exec(zSql);
169
+ if( strcmp(g.zMainDbType,zDb)==0 ) zDb = "main";
170
+ db_multi_exec(zSql, zDb, zDb, zDb, zDb);
169171
cid = db_lget_int("checkout", 0);
170172
db_lset_int("undo_checkout", cid);
171173
db_lset_int("undo_available", 1);
172174
undoActive = 1;
173175
}
174176
--- src/undo.c
+++ src/undo.c
@@ -151,23 +151,25 @@
151 /*
152 ** Begin capturing a snapshot that can be undone.
153 */
154 void undo_begin(void){
155 int cid;
 
156 static const char zSql[] =
157 @ CREATE TABLE undo(
158 @ pathname TEXT UNIQUE, -- Name of the file
159 @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
160 @ existsflag BOOLEAN, -- True if the file exists
161 @ content BLOB -- Saved content
162 @ );
163 @ CREATE TABLE undo_vfile AS SELECT * FROM vfile;
164 @ CREATE TABLE undo_vmerge AS SELECT * FROM vmerge;
165 @ CREATE TABLE undo_pending(undoId INTEGER PRIMARY KEY);
166 ;
167 undo_reset();
168 db_multi_exec(zSql);
 
169 cid = db_lget_int("checkout", 0);
170 db_lset_int("undo_checkout", cid);
171 db_lset_int("undo_available", 1);
172 undoActive = 1;
173 }
174
--- src/undo.c
+++ src/undo.c
@@ -151,23 +151,25 @@
151 /*
152 ** Begin capturing a snapshot that can be undone.
153 */
154 void undo_begin(void){
155 int cid;
156 const char *zDb = "localdb";
157 static const char zSql[] =
158 @ CREATE TABLE %s.undo(
159 @ pathname TEXT UNIQUE, -- Name of the file
160 @ redoflag BOOLEAN, -- 0 for undoable. 1 for redoable
161 @ existsflag BOOLEAN, -- True if the file exists
162 @ content BLOB -- Saved content
163 @ );
164 @ CREATE TABLE %s.undo_vfile AS SELECT * FROM vfile;
165 @ CREATE TABLE %s.undo_vmerge AS SELECT * FROM vmerge;
166 @ CREATE TABLE %s.undo_pending(undoId INTEGER PRIMARY KEY);
167 ;
168 undo_reset();
169 if( strcmp(g.zMainDbType,zDb)==0 ) zDb = "main";
170 db_multi_exec(zSql, zDb, zDb, zDb, zDb);
171 cid = db_lget_int("checkout", 0);
172 db_lset_int("undo_checkout", cid);
173 db_lset_int("undo_available", 1);
174 undoActive = 1;
175 }
176

Keyboard Shortcuts

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