| ︙ | | | ︙ | |
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
** (2) The "repository" database
**
** (3) A local checkout database named "_FOSSIL_" or ".fos"
** and located at the root of the local copy of the source tree.
**
*/
#include "config.h"
#include <sqlite3.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "db.h"
#if INTERFACE
|
>
>
>
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
** (2) The "repository" database
**
** (3) A local checkout database named "_FOSSIL_" or ".fos"
** and located at the root of the local copy of the source tree.
**
*/
#include "config.h"
#if ! defined(_WIN32)
# include <pwd.h>
#endif
#include <sqlite3.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "db.h"
#if INTERFACE
|
| ︙ | | | ︙ | |
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
|
}else{
z = 0;
}
db_finalize(&s);
return z;
}
#ifdef __MINGW32__
extern char *sqlite3_win32_mbcs_to_utf8(const char*);
#endif
/*
** 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 */
const char *zSchema, /* First part of schema */
... /* Additional SQL to run. Terminate with NULL. */
){
sqlite3 *db;
int rc;
const char *zSql;
va_list ap;
#ifdef __MINGW32__
zFileName = sqlite3_win32_mbcs_to_utf8(zFileName);
#endif
rc = sqlite3_open(zFileName, &db);
if( rc!=SQLITE_OK ){
db_err(sqlite3_errmsg(db));
}
sqlite3_busy_timeout(db, 5000);
|
|
|
|
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
|
}else{
z = 0;
}
db_finalize(&s);
return z;
}
#if defined(_WIN32)
extern char *sqlite3_win32_mbcs_to_utf8(const char*);
#endif
/*
** 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 */
const char *zSchema, /* First part of schema */
... /* Additional SQL to run. Terminate with NULL. */
){
sqlite3 *db;
int rc;
const char *zSql;
va_list ap;
#if defined(_WIN32)
zFileName = sqlite3_win32_mbcs_to_utf8(zFileName);
#endif
rc = sqlite3_open(zFileName, &db);
if( rc!=SQLITE_OK ){
db_err(sqlite3_errmsg(db));
}
sqlite3_busy_timeout(db, 5000);
|
| ︙ | | | ︙ | |
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
|
*/
static sqlite3 *openDatabase(const char *zDbName){
int rc;
const char *zVfs;
sqlite3 *db;
zVfs = getenv("FOSSIL_VFS");
#ifdef __MINGW32__
zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
#endif
rc = sqlite3_open_v2(
zDbName, &db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
zVfs
);
|
|
|
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
|
*/
static sqlite3 *openDatabase(const char *zDbName){
int rc;
const char *zVfs;
sqlite3 *db;
zVfs = getenv("FOSSIL_VFS");
#if defined(_WIN32)
zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
#endif
rc = sqlite3_open_v2(
zDbName, &db,
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
zVfs
);
|
| ︙ | | | ︙ | |
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
|
*/
void db_open_or_attach(const char *zDbName, const char *zLabel){
if( !g.db ){
g.db = openDatabase(zDbName);
g.zRepoDb = "main";
db_connection_init();
}else{
#ifdef __MINGW32__
zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
#endif
db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
g.zRepoDb = mprintf("%s", zLabel);
}
}
|
|
|
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
|
*/
void db_open_or_attach(const char *zDbName, const char *zLabel){
if( !g.db ){
g.db = openDatabase(zDbName);
g.zRepoDb = "main";
db_connection_init();
}else{
#if defined(_WIN32)
zDbName = sqlite3_win32_mbcs_to_utf8(zDbName);
#endif
db_multi_exec("ATTACH DATABASE %Q AS %s", zDbName, zLabel);
g.zRepoDb = mprintf("%s", zLabel);
}
}
|
| ︙ | | | ︙ | |
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
** connection so that we can join between the various databases. In that
** case, invoke this routine with useAttach as 1.
*/
void db_open_config(int useAttach){
char *zDbName;
const char *zHome;
if( g.configOpen ) return;
#ifdef __MINGW32__
zHome = getenv("LOCALAPPDATA");
if( zHome==0 ){
zHome = getenv("APPDATA");
if( zHome==0 ){
zHome = getenv("HOMEPATH");
}
}
|
|
|
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
|
** connection so that we can join between the various databases. In that
** case, invoke this routine with useAttach as 1.
*/
void db_open_config(int useAttach){
char *zDbName;
const char *zHome;
if( g.configOpen ) return;
#if defined(_WIN32)
zHome = getenv("LOCALAPPDATA");
if( zHome==0 ){
zHome = getenv("APPDATA");
if( zHome==0 ){
zHome = getenv("HOMEPATH");
}
}
|
| ︙ | | | ︙ | |
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
|
}
#ifndef __MINGW32__
if( access(zHome, W_OK) ){
fossil_fatal("home directory %s must be writeable", zHome);
}
#endif
g.zHome = mprintf("%/", zHome);
#ifdef __MINGW32__
/* . filenames give some window systems problems and many apps problems */
zDbName = mprintf("%//_fossil", zHome);
#else
zDbName = mprintf("%s/.fossil", zHome);
#endif
if( file_size(zDbName)<1024*3 ){
db_init_database(zDbName, zConfigSchema, (char*)0);
|
|
|
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
|
}
#ifndef __MINGW32__
if( access(zHome, W_OK) ){
fossil_fatal("home directory %s must be writeable", zHome);
}
#endif
g.zHome = mprintf("%/", zHome);
#if defined(_WIN32)
/* . filenames give some window systems problems and many apps problems */
zDbName = mprintf("%//_fossil", zHome);
#else
zDbName = mprintf("%s/.fossil", zHome);
#endif
if( file_size(zDbName)<1024*3 ){
db_init_database(zDbName, zConfigSchema, (char*)0);
|
| ︙ | | | ︙ | |
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
|
void db_create_default_users(int setupUserOnly, const char *zDefaultUser){
const char *zUser;
zUser = db_get("default-user", 0);
if( zUser==0 ){
zUser = zDefaultUser;
}
if( zUser==0 ){
#ifdef __MINGW32__
zUser = getenv("USERNAME");
#else
zUser = getenv("USER");
#endif
}
if( zUser==0 ){
zUser = "root";
|
|
|
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
|
void db_create_default_users(int setupUserOnly, const char *zDefaultUser){
const char *zUser;
zUser = db_get("default-user", 0);
if( zUser==0 ){
zUser = zDefaultUser;
}
if( zUser==0 ){
#if defined(_WIN32)
zUser = getenv("USERNAME");
#else
zUser = getenv("USER");
#endif
}
if( zUser==0 ){
zUser = "root";
|
| ︙ | | | ︙ | |