Fossil SCM
Automatically delete the _FOSSIL_ file after a failed open. Ticket [d299fb9842d6bc]
Commit
0aee050f320050b1f47487deb9f476681038e816
Parent
be467e93287897e…
1 file changed
+25
-26
M
src/db.c
+25
-26
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -81,19 +81,29 @@ | ||
| 81 | 81 | db_force_rollback(); |
| 82 | 82 | fossil_exit(1); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | static int nBegin = 0; /* Nesting depth of BEGIN */ |
| 86 | -static int isNewRepo = 0; /* True if the repository is newly created */ | |
| 87 | 86 | static int doRollback = 0; /* True to force a rollback */ |
| 88 | 87 | static int nCommitHook = 0; /* Number of commit hooks */ |
| 89 | 88 | static struct sCommitHook { |
| 90 | 89 | int (*xHook)(void); /* Functions to call at db_end_transaction() */ |
| 91 | 90 | int sequence; /* Call functions in sequence order */ |
| 92 | 91 | } aHook[5]; |
| 93 | 92 | static Stmt *pAllStmt = 0; /* List of all unfinalized statements */ |
| 94 | 93 | static int nPrepare = 0; /* Number of calls to sqlite3_prepare() */ |
| 94 | +static int nDeleteOnFail = 0; /* Number of entries in azDeleteOnFail[] */ | |
| 95 | +static char *azDeleteOnFail[3]; /* Files to delete on a failure */ | |
| 96 | + | |
| 97 | + | |
| 98 | +/* | |
| 99 | +** Arrange for the given file to be deleted on a failure. | |
| 100 | +*/ | |
| 101 | +void db_delete_on_failure(const char *zFilename){ | |
| 102 | + assert( nDeleteOnFail<count(azDeleteOnFail) ); | |
| 103 | + azDeleteOnFail[nDeleteOnFail++] = fossil_strdup(zFilename); | |
| 104 | +} | |
| 95 | 105 | |
| 96 | 106 | /* |
| 97 | 107 | ** This routine is called by the SQLite commit-hook mechanism |
| 98 | 108 | ** just prior to each commit. All this routine does is verify |
| 99 | 109 | ** that nBegin really is zero. That insures that transactions |
| @@ -141,10 +151,11 @@ | ||
| 141 | 151 | |
| 142 | 152 | /* |
| 143 | 153 | ** Force a rollback and shutdown the database |
| 144 | 154 | */ |
| 145 | 155 | void db_force_rollback(void){ |
| 156 | + int i; | |
| 146 | 157 | static int busy = 0; |
| 147 | 158 | if( busy || g.db==0 ) return; |
| 148 | 159 | busy = 1; |
| 149 | 160 | undo_rollback(); |
| 150 | 161 | while( pAllStmt ){ |
| @@ -151,17 +162,16 @@ | ||
| 151 | 162 | db_finalize(pAllStmt); |
| 152 | 163 | } |
| 153 | 164 | if( nBegin ){ |
| 154 | 165 | sqlite3_exec(g.db, "ROLLBACK", 0, 0, 0); |
| 155 | 166 | nBegin = 0; |
| 156 | - if( isNewRepo ){ | |
| 157 | - db_close(0); | |
| 158 | - unlink(g.zRepositoryName); | |
| 159 | - } | |
| 160 | 167 | } |
| 161 | 168 | busy = 0; |
| 162 | 169 | db_close(0); |
| 170 | + for(i=0; i<nDeleteOnFail; i++){ | |
| 171 | + unlink(azDeleteOnFail[i]); | |
| 172 | + } | |
| 163 | 173 | } |
| 164 | 174 | |
| 165 | 175 | /* |
| 166 | 176 | ** Install a commit hook. Hooks are installed in sequence order. |
| 167 | 177 | ** It is an error to install the same commit hook more than once. |
| @@ -565,14 +575,10 @@ | ||
| 565 | 575 | } |
| 566 | 576 | db_finalize(&s); |
| 567 | 577 | return z; |
| 568 | 578 | } |
| 569 | 579 | |
| 570 | -#if defined(_WIN32) | |
| 571 | -extern char *sqlite3_win32_mbcs_to_utf8(const char*); | |
| 572 | -#endif | |
| 573 | - | |
| 574 | 580 | /* |
| 575 | 581 | ** Initialize a new database file with the given schema. If anything |
| 576 | 582 | ** goes wrong, call db_err() to exit. |
| 577 | 583 | */ |
| 578 | 584 | void db_init_database( |
| @@ -583,13 +589,10 @@ | ||
| 583 | 589 | sqlite3 *db; |
| 584 | 590 | int rc; |
| 585 | 591 | const char *zSql; |
| 586 | 592 | va_list ap; |
| 587 | 593 | |
| 588 | -#if defined(_WIN32) | |
| 589 | - zFileName = sqlite3_win32_mbcs_to_utf8(zFileName); | |
| 590 | -#endif | |
| 591 | 594 | rc = sqlite3_open(zFileName, &db); |
| 592 | 595 | if( rc!=SQLITE_OK ){ |
| 593 | 596 | db_err(sqlite3_errmsg(db)); |
| 594 | 597 | } |
| 595 | 598 | sqlite3_busy_timeout(db, 5000); |
| @@ -631,13 +634,10 @@ | ||
| 631 | 634 | int rc; |
| 632 | 635 | const char *zVfs; |
| 633 | 636 | sqlite3 *db; |
| 634 | 637 | |
| 635 | 638 | zVfs = getenv("FOSSIL_VFS"); |
| 636 | -#if defined(_WIN32) | |
| 637 | - zDbName = sqlite3_win32_mbcs_to_utf8(zDbName); | |
| 638 | -#endif | |
| 639 | 639 | rc = sqlite3_open_v2( |
| 640 | 640 | zDbName, &db, |
| 641 | 641 | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, |
| 642 | 642 | zVfs |
| 643 | 643 | ); |
| @@ -660,13 +660,10 @@ | ||
| 660 | 660 | if( !g.db ){ |
| 661 | 661 | g.db = openDatabase(zDbName); |
| 662 | 662 | g.zMainDbType = zLabel; |
| 663 | 663 | db_connection_init(); |
| 664 | 664 | }else{ |
| 665 | -#if defined(_WIN32) | |
| 666 | - zDbName = sqlite3_win32_mbcs_to_utf8(zDbName); | |
| 667 | -#endif | |
| 668 | 665 | db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel); |
| 669 | 666 | } |
| 670 | 667 | } |
| 671 | 668 | |
| 672 | 669 | /* |
| @@ -1056,11 +1053,11 @@ | ||
| 1056 | 1053 | zFilename, |
| 1057 | 1054 | zRepositorySchema1, |
| 1058 | 1055 | zRepositorySchema2, |
| 1059 | 1056 | (char*)0 |
| 1060 | 1057 | ); |
| 1061 | - isNewRepo = 1; | |
| 1058 | + db_delete_on_failure(zFilename); | |
| 1062 | 1059 | } |
| 1063 | 1060 | |
| 1064 | 1061 | /* |
| 1065 | 1062 | ** Create the default user accounts in the USER table. |
| 1066 | 1063 | */ |
| @@ -1189,14 +1186,15 @@ | ||
| 1189 | 1186 | db_open_repository(g.argv[2]); |
| 1190 | 1187 | db_open_config(0); |
| 1191 | 1188 | db_begin_transaction(); |
| 1192 | 1189 | db_initial_setup(zDate, zDefaultUser, 1); |
| 1193 | 1190 | db_end_transaction(0); |
| 1194 | - printf("project-id: %s\n", db_get("project-code", 0)); | |
| 1195 | - printf("server-id: %s\n", db_get("server-code", 0)); | |
| 1191 | + fossil_print("project-id: %s\n", db_get("project-code", 0)); | |
| 1192 | + fossil_print("server-id: %s\n", db_get("server-code", 0)); | |
| 1196 | 1193 | zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin); |
| 1197 | - printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword); | |
| 1194 | + fossil_print("admin-user: %s (initial password is \"%s\")\n", | |
| 1195 | + g.zLogin, zPassword); | |
| 1198 | 1196 | } |
| 1199 | 1197 | |
| 1200 | 1198 | /* |
| 1201 | 1199 | ** SQL functions for debugging. |
| 1202 | 1200 | ** |
| @@ -1210,11 +1208,11 @@ | ||
| 1210 | 1208 | ){ |
| 1211 | 1209 | int i; |
| 1212 | 1210 | if( g.fSqlPrint ){ |
| 1213 | 1211 | for(i=0; i<argc; i++){ |
| 1214 | 1212 | char c = i==argc-1 ? '\n' : ' '; |
| 1215 | - printf("%s%c", sqlite3_value_text(argv[i]), c); | |
| 1213 | + fossil_print("%s%c", sqlite3_value_text(argv[i]), c); | |
| 1216 | 1214 | } |
| 1217 | 1215 | } |
| 1218 | 1216 | } |
| 1219 | 1217 | static void db_sql_trace(void *notUsed, const char *zSql){ |
| 1220 | 1218 | int n = strlen(zSql); |
| @@ -1566,10 +1564,11 @@ | ||
| 1566 | 1564 | fossil_panic("already within an open tree rooted at %s", g.zLocalRoot); |
| 1567 | 1565 | } |
| 1568 | 1566 | file_canonical_name(g.argv[2], &path); |
| 1569 | 1567 | db_open_repository(blob_str(&path)); |
| 1570 | 1568 | db_init_database("./_FOSSIL_", zLocalSchema, (char*)0); |
| 1569 | + db_delete_on_failure("./_FOSSIL_"); | |
| 1571 | 1570 | db_open_local(); |
| 1572 | 1571 | db_lset("repository", blob_str(&path)); |
| 1573 | 1572 | db_record_repository_filename(blob_str(&path)); |
| 1574 | 1573 | vid = db_int(0, "SELECT pid FROM plink y" |
| 1575 | 1574 | " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)"); |
| @@ -1613,14 +1612,14 @@ | ||
| 1613 | 1612 | "SELECT '(global)', value FROM global_config WHERE name=%Q", |
| 1614 | 1613 | zName |
| 1615 | 1614 | ); |
| 1616 | 1615 | } |
| 1617 | 1616 | if( db_step(&q)==SQLITE_ROW ){ |
| 1618 | - printf("%-20s %-8s %s\n", zName, db_column_text(&q, 0), | |
| 1617 | + fossil_print("%-20s %-8s %s\n", zName, db_column_text(&q, 0), | |
| 1619 | 1618 | db_column_text(&q, 1)); |
| 1620 | 1619 | }else{ |
| 1621 | - printf("%-20s\n", zName); | |
| 1620 | + fossil_print("%-20s\n", zName); | |
| 1622 | 1621 | } |
| 1623 | 1622 | db_finalize(&q); |
| 1624 | 1623 | } |
| 1625 | 1624 | |
| 1626 | 1625 | |
| @@ -1869,9 +1868,9 @@ | ||
| 1869 | 1868 | void test_timespan_cmd(void){ |
| 1870 | 1869 | double rDiff; |
| 1871 | 1870 | if( g.argc!=3 ) usage("TIMESTAMP"); |
| 1872 | 1871 | sqlite3_open(":memory:", &g.db); |
| 1873 | 1872 | rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]); |
| 1874 | - printf("Time differences: %s\n", db_timespan_name(rDiff)); | |
| 1873 | + fossil_print("Time differences: %s\n", db_timespan_name(rDiff)); | |
| 1875 | 1874 | sqlite3_close(g.db); |
| 1876 | 1875 | g.db = 0; |
| 1877 | 1876 | } |
| 1878 | 1877 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -81,19 +81,29 @@ | |
| 81 | db_force_rollback(); |
| 82 | fossil_exit(1); |
| 83 | } |
| 84 | |
| 85 | static int nBegin = 0; /* Nesting depth of BEGIN */ |
| 86 | static int isNewRepo = 0; /* True if the repository is newly created */ |
| 87 | static int doRollback = 0; /* True to force a rollback */ |
| 88 | static int nCommitHook = 0; /* Number of commit hooks */ |
| 89 | static struct sCommitHook { |
| 90 | int (*xHook)(void); /* Functions to call at db_end_transaction() */ |
| 91 | int sequence; /* Call functions in sequence order */ |
| 92 | } aHook[5]; |
| 93 | static Stmt *pAllStmt = 0; /* List of all unfinalized statements */ |
| 94 | static int nPrepare = 0; /* Number of calls to sqlite3_prepare() */ |
| 95 | |
| 96 | /* |
| 97 | ** This routine is called by the SQLite commit-hook mechanism |
| 98 | ** just prior to each commit. All this routine does is verify |
| 99 | ** that nBegin really is zero. That insures that transactions |
| @@ -141,10 +151,11 @@ | |
| 141 | |
| 142 | /* |
| 143 | ** Force a rollback and shutdown the database |
| 144 | */ |
| 145 | void db_force_rollback(void){ |
| 146 | static int busy = 0; |
| 147 | if( busy || g.db==0 ) return; |
| 148 | busy = 1; |
| 149 | undo_rollback(); |
| 150 | while( pAllStmt ){ |
| @@ -151,17 +162,16 @@ | |
| 151 | db_finalize(pAllStmt); |
| 152 | } |
| 153 | if( nBegin ){ |
| 154 | sqlite3_exec(g.db, "ROLLBACK", 0, 0, 0); |
| 155 | nBegin = 0; |
| 156 | if( isNewRepo ){ |
| 157 | db_close(0); |
| 158 | unlink(g.zRepositoryName); |
| 159 | } |
| 160 | } |
| 161 | busy = 0; |
| 162 | db_close(0); |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | ** Install a commit hook. Hooks are installed in sequence order. |
| 167 | ** It is an error to install the same commit hook more than once. |
| @@ -565,14 +575,10 @@ | |
| 565 | } |
| 566 | db_finalize(&s); |
| 567 | return z; |
| 568 | } |
| 569 | |
| 570 | #if defined(_WIN32) |
| 571 | extern char *sqlite3_win32_mbcs_to_utf8(const char*); |
| 572 | #endif |
| 573 | |
| 574 | /* |
| 575 | ** Initialize a new database file with the given schema. If anything |
| 576 | ** goes wrong, call db_err() to exit. |
| 577 | */ |
| 578 | void db_init_database( |
| @@ -583,13 +589,10 @@ | |
| 583 | sqlite3 *db; |
| 584 | int rc; |
| 585 | const char *zSql; |
| 586 | va_list ap; |
| 587 | |
| 588 | #if defined(_WIN32) |
| 589 | zFileName = sqlite3_win32_mbcs_to_utf8(zFileName); |
| 590 | #endif |
| 591 | rc = sqlite3_open(zFileName, &db); |
| 592 | if( rc!=SQLITE_OK ){ |
| 593 | db_err(sqlite3_errmsg(db)); |
| 594 | } |
| 595 | sqlite3_busy_timeout(db, 5000); |
| @@ -631,13 +634,10 @@ | |
| 631 | int rc; |
| 632 | const char *zVfs; |
| 633 | sqlite3 *db; |
| 634 | |
| 635 | zVfs = getenv("FOSSIL_VFS"); |
| 636 | #if defined(_WIN32) |
| 637 | zDbName = sqlite3_win32_mbcs_to_utf8(zDbName); |
| 638 | #endif |
| 639 | rc = sqlite3_open_v2( |
| 640 | zDbName, &db, |
| 641 | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, |
| 642 | zVfs |
| 643 | ); |
| @@ -660,13 +660,10 @@ | |
| 660 | if( !g.db ){ |
| 661 | g.db = openDatabase(zDbName); |
| 662 | g.zMainDbType = zLabel; |
| 663 | db_connection_init(); |
| 664 | }else{ |
| 665 | #if defined(_WIN32) |
| 666 | zDbName = sqlite3_win32_mbcs_to_utf8(zDbName); |
| 667 | #endif |
| 668 | db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | /* |
| @@ -1056,11 +1053,11 @@ | |
| 1056 | zFilename, |
| 1057 | zRepositorySchema1, |
| 1058 | zRepositorySchema2, |
| 1059 | (char*)0 |
| 1060 | ); |
| 1061 | isNewRepo = 1; |
| 1062 | } |
| 1063 | |
| 1064 | /* |
| 1065 | ** Create the default user accounts in the USER table. |
| 1066 | */ |
| @@ -1189,14 +1186,15 @@ | |
| 1189 | db_open_repository(g.argv[2]); |
| 1190 | db_open_config(0); |
| 1191 | db_begin_transaction(); |
| 1192 | db_initial_setup(zDate, zDefaultUser, 1); |
| 1193 | db_end_transaction(0); |
| 1194 | printf("project-id: %s\n", db_get("project-code", 0)); |
| 1195 | printf("server-id: %s\n", db_get("server-code", 0)); |
| 1196 | zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin); |
| 1197 | printf("admin-user: %s (initial password is \"%s\")\n", g.zLogin, zPassword); |
| 1198 | } |
| 1199 | |
| 1200 | /* |
| 1201 | ** SQL functions for debugging. |
| 1202 | ** |
| @@ -1210,11 +1208,11 @@ | |
| 1210 | ){ |
| 1211 | int i; |
| 1212 | if( g.fSqlPrint ){ |
| 1213 | for(i=0; i<argc; i++){ |
| 1214 | char c = i==argc-1 ? '\n' : ' '; |
| 1215 | printf("%s%c", sqlite3_value_text(argv[i]), c); |
| 1216 | } |
| 1217 | } |
| 1218 | } |
| 1219 | static void db_sql_trace(void *notUsed, const char *zSql){ |
| 1220 | int n = strlen(zSql); |
| @@ -1566,10 +1564,11 @@ | |
| 1566 | fossil_panic("already within an open tree rooted at %s", g.zLocalRoot); |
| 1567 | } |
| 1568 | file_canonical_name(g.argv[2], &path); |
| 1569 | db_open_repository(blob_str(&path)); |
| 1570 | db_init_database("./_FOSSIL_", zLocalSchema, (char*)0); |
| 1571 | db_open_local(); |
| 1572 | db_lset("repository", blob_str(&path)); |
| 1573 | db_record_repository_filename(blob_str(&path)); |
| 1574 | vid = db_int(0, "SELECT pid FROM plink y" |
| 1575 | " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)"); |
| @@ -1613,14 +1612,14 @@ | |
| 1613 | "SELECT '(global)', value FROM global_config WHERE name=%Q", |
| 1614 | zName |
| 1615 | ); |
| 1616 | } |
| 1617 | if( db_step(&q)==SQLITE_ROW ){ |
| 1618 | printf("%-20s %-8s %s\n", zName, db_column_text(&q, 0), |
| 1619 | db_column_text(&q, 1)); |
| 1620 | }else{ |
| 1621 | printf("%-20s\n", zName); |
| 1622 | } |
| 1623 | db_finalize(&q); |
| 1624 | } |
| 1625 | |
| 1626 | |
| @@ -1869,9 +1868,9 @@ | |
| 1869 | void test_timespan_cmd(void){ |
| 1870 | double rDiff; |
| 1871 | if( g.argc!=3 ) usage("TIMESTAMP"); |
| 1872 | sqlite3_open(":memory:", &g.db); |
| 1873 | rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]); |
| 1874 | printf("Time differences: %s\n", db_timespan_name(rDiff)); |
| 1875 | sqlite3_close(g.db); |
| 1876 | g.db = 0; |
| 1877 | } |
| 1878 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -81,19 +81,29 @@ | |
| 81 | db_force_rollback(); |
| 82 | fossil_exit(1); |
| 83 | } |
| 84 | |
| 85 | static int nBegin = 0; /* Nesting depth of BEGIN */ |
| 86 | static int doRollback = 0; /* True to force a rollback */ |
| 87 | static int nCommitHook = 0; /* Number of commit hooks */ |
| 88 | static struct sCommitHook { |
| 89 | int (*xHook)(void); /* Functions to call at db_end_transaction() */ |
| 90 | int sequence; /* Call functions in sequence order */ |
| 91 | } aHook[5]; |
| 92 | static Stmt *pAllStmt = 0; /* List of all unfinalized statements */ |
| 93 | static int nPrepare = 0; /* Number of calls to sqlite3_prepare() */ |
| 94 | static int nDeleteOnFail = 0; /* Number of entries in azDeleteOnFail[] */ |
| 95 | static char *azDeleteOnFail[3]; /* Files to delete on a failure */ |
| 96 | |
| 97 | |
| 98 | /* |
| 99 | ** Arrange for the given file to be deleted on a failure. |
| 100 | */ |
| 101 | void db_delete_on_failure(const char *zFilename){ |
| 102 | assert( nDeleteOnFail<count(azDeleteOnFail) ); |
| 103 | azDeleteOnFail[nDeleteOnFail++] = fossil_strdup(zFilename); |
| 104 | } |
| 105 | |
| 106 | /* |
| 107 | ** This routine is called by the SQLite commit-hook mechanism |
| 108 | ** just prior to each commit. All this routine does is verify |
| 109 | ** that nBegin really is zero. That insures that transactions |
| @@ -141,10 +151,11 @@ | |
| 151 | |
| 152 | /* |
| 153 | ** Force a rollback and shutdown the database |
| 154 | */ |
| 155 | void db_force_rollback(void){ |
| 156 | int i; |
| 157 | static int busy = 0; |
| 158 | if( busy || g.db==0 ) return; |
| 159 | busy = 1; |
| 160 | undo_rollback(); |
| 161 | while( pAllStmt ){ |
| @@ -151,17 +162,16 @@ | |
| 162 | db_finalize(pAllStmt); |
| 163 | } |
| 164 | if( nBegin ){ |
| 165 | sqlite3_exec(g.db, "ROLLBACK", 0, 0, 0); |
| 166 | nBegin = 0; |
| 167 | } |
| 168 | busy = 0; |
| 169 | db_close(0); |
| 170 | for(i=0; i<nDeleteOnFail; i++){ |
| 171 | unlink(azDeleteOnFail[i]); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | /* |
| 176 | ** Install a commit hook. Hooks are installed in sequence order. |
| 177 | ** It is an error to install the same commit hook more than once. |
| @@ -565,14 +575,10 @@ | |
| 575 | } |
| 576 | db_finalize(&s); |
| 577 | return z; |
| 578 | } |
| 579 | |
| 580 | /* |
| 581 | ** Initialize a new database file with the given schema. If anything |
| 582 | ** goes wrong, call db_err() to exit. |
| 583 | */ |
| 584 | void db_init_database( |
| @@ -583,13 +589,10 @@ | |
| 589 | sqlite3 *db; |
| 590 | int rc; |
| 591 | const char *zSql; |
| 592 | va_list ap; |
| 593 | |
| 594 | rc = sqlite3_open(zFileName, &db); |
| 595 | if( rc!=SQLITE_OK ){ |
| 596 | db_err(sqlite3_errmsg(db)); |
| 597 | } |
| 598 | sqlite3_busy_timeout(db, 5000); |
| @@ -631,13 +634,10 @@ | |
| 634 | int rc; |
| 635 | const char *zVfs; |
| 636 | sqlite3 *db; |
| 637 | |
| 638 | zVfs = getenv("FOSSIL_VFS"); |
| 639 | rc = sqlite3_open_v2( |
| 640 | zDbName, &db, |
| 641 | SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, |
| 642 | zVfs |
| 643 | ); |
| @@ -660,13 +660,10 @@ | |
| 660 | if( !g.db ){ |
| 661 | g.db = openDatabase(zDbName); |
| 662 | g.zMainDbType = zLabel; |
| 663 | db_connection_init(); |
| 664 | }else{ |
| 665 | db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel); |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | /* |
| @@ -1056,11 +1053,11 @@ | |
| 1053 | zFilename, |
| 1054 | zRepositorySchema1, |
| 1055 | zRepositorySchema2, |
| 1056 | (char*)0 |
| 1057 | ); |
| 1058 | db_delete_on_failure(zFilename); |
| 1059 | } |
| 1060 | |
| 1061 | /* |
| 1062 | ** Create the default user accounts in the USER table. |
| 1063 | */ |
| @@ -1189,14 +1186,15 @@ | |
| 1186 | db_open_repository(g.argv[2]); |
| 1187 | db_open_config(0); |
| 1188 | db_begin_transaction(); |
| 1189 | db_initial_setup(zDate, zDefaultUser, 1); |
| 1190 | db_end_transaction(0); |
| 1191 | fossil_print("project-id: %s\n", db_get("project-code", 0)); |
| 1192 | fossil_print("server-id: %s\n", db_get("server-code", 0)); |
| 1193 | zPassword = db_text(0, "SELECT pw FROM user WHERE login=%Q", g.zLogin); |
| 1194 | fossil_print("admin-user: %s (initial password is \"%s\")\n", |
| 1195 | g.zLogin, zPassword); |
| 1196 | } |
| 1197 | |
| 1198 | /* |
| 1199 | ** SQL functions for debugging. |
| 1200 | ** |
| @@ -1210,11 +1208,11 @@ | |
| 1208 | ){ |
| 1209 | int i; |
| 1210 | if( g.fSqlPrint ){ |
| 1211 | for(i=0; i<argc; i++){ |
| 1212 | char c = i==argc-1 ? '\n' : ' '; |
| 1213 | fossil_print("%s%c", sqlite3_value_text(argv[i]), c); |
| 1214 | } |
| 1215 | } |
| 1216 | } |
| 1217 | static void db_sql_trace(void *notUsed, const char *zSql){ |
| 1218 | int n = strlen(zSql); |
| @@ -1566,10 +1564,11 @@ | |
| 1564 | fossil_panic("already within an open tree rooted at %s", g.zLocalRoot); |
| 1565 | } |
| 1566 | file_canonical_name(g.argv[2], &path); |
| 1567 | db_open_repository(blob_str(&path)); |
| 1568 | db_init_database("./_FOSSIL_", zLocalSchema, (char*)0); |
| 1569 | db_delete_on_failure("./_FOSSIL_"); |
| 1570 | db_open_local(); |
| 1571 | db_lset("repository", blob_str(&path)); |
| 1572 | db_record_repository_filename(blob_str(&path)); |
| 1573 | vid = db_int(0, "SELECT pid FROM plink y" |
| 1574 | " WHERE NOT EXISTS(SELECT 1 FROM plink x WHERE x.cid=y.pid)"); |
| @@ -1613,14 +1612,14 @@ | |
| 1612 | "SELECT '(global)', value FROM global_config WHERE name=%Q", |
| 1613 | zName |
| 1614 | ); |
| 1615 | } |
| 1616 | if( db_step(&q)==SQLITE_ROW ){ |
| 1617 | fossil_print("%-20s %-8s %s\n", zName, db_column_text(&q, 0), |
| 1618 | db_column_text(&q, 1)); |
| 1619 | }else{ |
| 1620 | fossil_print("%-20s\n", zName); |
| 1621 | } |
| 1622 | db_finalize(&q); |
| 1623 | } |
| 1624 | |
| 1625 | |
| @@ -1869,9 +1868,9 @@ | |
| 1868 | void test_timespan_cmd(void){ |
| 1869 | double rDiff; |
| 1870 | if( g.argc!=3 ) usage("TIMESTAMP"); |
| 1871 | sqlite3_open(":memory:", &g.db); |
| 1872 | rDiff = db_double(0.0, "SELECT julianday('now') - julianday(%Q)", g.argv[2]); |
| 1873 | fossil_print("Time differences: %s\n", db_timespan_name(rDiff)); |
| 1874 | sqlite3_close(g.db); |
| 1875 | g.db = 0; |
| 1876 | } |
| 1877 |