| ︙ | | | ︙ | |
686
687
688
689
690
691
692
693
694
695
696
697
698
699
|
z = mprintf("%s", zDefault);
}else{
z = 0;
}
db_finalize(&s);
return z;
}
/*
** Initialize a new database file with the given schema. If anything
** goes wrong, call db_err() to exit.
*/
void db_init_database(
const char *zFileName, /* Name of database file to create */
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
|
z = mprintf("%s", zDefault);
}else{
z = 0;
}
db_finalize(&s);
return z;
}
/*
** Invoke sqlite3_close() but also check its return code and if the
** return code is SQLITE_BUSY, report errors.
*/
static void db_close_with_checks(sqlite3 *db, int reportErrors){
int rc = sqlite3_close(db);
if( rc==SQLITE_BUSY && reportErrors ){
sqlite3_stmt *pStmt;
while( (pStmt = sqlite3_next_stmt(g.db, pStmt))!=0 ){
fossil_warning("unfinalized SQL statement: [%s]", sqlite3_sql(pStmt));
}
}
}
/*
** Initialize a new database file with the given schema. If anything
** goes wrong, call db_err() to exit.
*/
void db_init_database(
const char *zFileName, /* Name of database file to create */
|
| ︙ | | | ︙ | |
820
821
822
823
824
825
826
827
828
829
830
831
832
833
|
sqlite3_create_function(
db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
0, 0
);
if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
re_add_sql_func(db);
foci_register(db);
sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
return db;
}
/*
** Detaches the zLabel database.
|
>
|
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
|
sqlite3_create_function(
db, "symbolic_name_to_rid", 2, SQLITE_UTF8, 0, db_sym2rid_function,
0, 0
);
if( g.fSqlTrace ) sqlite3_trace(db, db_sql_trace, 0);
re_add_sql_func(db);
foci_register(db);
ftsearch_add_sql_func(db);
sqlite3_exec(db, "PRAGMA foreign_keys=OFF;", 0, 0, 0);
return db;
}
/*
** Detaches the zLabel database.
|
| ︙ | | | ︙ | |
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
|
if( pWasAttached ) *pWasAttached = 1;
}
}
/*
** Close the user database.
*/
void db_close_config(){
if( g.useAttach ){
db_detach("configdb");
g.useAttach = 0;
g.zConfigDbName = 0;
}else if( g.dbConfig ){
sqlite3_wal_checkpoint(g.dbConfig, 0);
sqlite3_close(g.dbConfig);
g.dbConfig = 0;
g.zConfigDbType = 0;
g.zConfigDbName = 0;
}else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
sqlite3_wal_checkpoint(g.db, 0);
sqlite3_close(g.db);
g.db = 0;
g.zMainDbType = 0;
g.zConfigDbName = 0;
}
}
/*
|
|
|
|
|
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
|
if( pWasAttached ) *pWasAttached = 1;
}
}
/*
** Close the user database.
*/
void db_close_config(int reportErrors){
if( g.useAttach ){
db_detach("configdb");
g.useAttach = 0;
g.zConfigDbName = 0;
}else if( g.dbConfig ){
sqlite3_wal_checkpoint(g.dbConfig, 0);
db_close_with_checks(g.dbConfig, reportErrors);
g.dbConfig = 0;
g.zConfigDbType = 0;
g.zConfigDbName = 0;
}else if( g.db && fossil_strcmp(g.zMainDbType, "configdb")==0 ){
sqlite3_wal_checkpoint(g.db, 0);
db_close_with_checks(g.db, reportErrors);
g.db = 0;
g.zMainDbType = 0;
g.zConfigDbName = 0;
}
}
/*
|
| ︙ | | | ︙ | |
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
|
** case, invoke this routine with useAttach as 1.
*/
void db_open_config(int useAttach){
char *zDbName;
char *zHome;
if( g.zConfigDbName ){
if( useAttach==g.useAttach ) return;
db_close_config();
}
#if defined(_WIN32) || defined(__CYGWIN__)
zHome = fossil_getenv("LOCALAPPDATA");
if( zHome==0 ){
zHome = fossil_getenv("APPDATA");
if( zHome==0 ){
char *zDrive = fossil_getenv("HOMEDRIVE");
|
|
|
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
|
** case, invoke this routine with useAttach as 1.
*/
void db_open_config(int useAttach){
char *zDbName;
char *zHome;
if( g.zConfigDbName ){
if( useAttach==g.useAttach ) return;
db_close_config(1);
}
#if defined(_WIN32) || defined(__CYGWIN__)
zHome = fossil_getenv("LOCALAPPDATA");
if( zHome==0 ){
zHome = fossil_getenv("APPDATA");
if( zHome==0 ){
char *zDrive = fossil_getenv("HOMEDRIVE");
|
| ︙ | | | ︙ | |
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
|
/*
** Close the database connection.
**
** Check for unfinalized statements and report errors if the reportErrors
** argument is true. Ignore unfinalized statements when false.
*/
void db_close(int reportErrors){
sqlite3_stmt *pStmt;
if( g.db==0 ) return;
if( g.fSqlStats ){
int cur, hiwtr;
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &cur, &hiwtr, 0);
fprintf(stderr, "-- LOOKASIDE_USED %10d %10d\n", cur, hiwtr);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &cur, &hiwtr, 0);
fprintf(stderr, "-- LOOKASIDE_HIT %10d\n", hiwtr);
|
<
|
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
|
/*
** Close the database connection.
**
** Check for unfinalized statements and report errors if the reportErrors
** argument is true. Ignore unfinalized statements when false.
*/
void db_close(int reportErrors){
if( g.db==0 ) return;
if( g.fSqlStats ){
int cur, hiwtr;
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_USED, &cur, &hiwtr, 0);
fprintf(stderr, "-- LOOKASIDE_USED %10d %10d\n", cur, hiwtr);
sqlite3_db_status(g.db, SQLITE_DBSTATUS_LOOKASIDE_HIT, &cur, &hiwtr, 0);
fprintf(stderr, "-- LOOKASIDE_HIT %10d\n", hiwtr);
|
| ︙ | | | ︙ | |
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
|
fprintf(stderr, "-- PCACHE_OVFLOW %10d %10d\n", cur, hiwtr);
fprintf(stderr, "-- prepared statements %10d\n", db.nPrepare);
}
while( db.pAllStmt ){
db_finalize(db.pAllStmt);
}
db_end_transaction(1);
pStmt = 0;
if( reportErrors ){
while( (pStmt = sqlite3_next_stmt(g.db, pStmt))!=0 ){
fossil_warning("unfinalized SQL statement: [%s]", sqlite3_sql(pStmt));
}
}
db_close_config();
if( g.db ){
sqlite3_wal_checkpoint(g.db, 0);
sqlite3_close(g.db);
g.db = 0;
g.zMainDbType = 0;
}
g.repositoryOpen = 0;
g.localOpen = 0;
assert( g.dbConfig==0 );
assert( g.useAttach==0 );
|
<
<
<
<
<
<
|
|
|
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
|
fprintf(stderr, "-- PCACHE_OVFLOW %10d %10d\n", cur, hiwtr);
fprintf(stderr, "-- prepared statements %10d\n", db.nPrepare);
}
while( db.pAllStmt ){
db_finalize(db.pAllStmt);
}
db_end_transaction(1);
db_close_config(reportErrors);
if( g.db ){
sqlite3_wal_checkpoint(g.db, 0);
db_close_with_checks(g.db, reportErrors);
g.db = 0;
g.zMainDbType = 0;
}
g.repositoryOpen = 0;
g.localOpen = 0;
assert( g.dbConfig==0 );
assert( g.useAttach==0 );
|
| ︙ | | | ︙ | |