Fossil SCM
Clarification of comments on the db_set_main_schemaname() routine.
Commit
81184a02a56d714225535b0fe6b1c41b6cbb1b3c
Parent
d858f3da52969aa…
1 file changed
+18
-15
M
src/db.c
+18
-15
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -963,35 +963,24 @@ | ||
| 963 | 963 | zDbName, zLabel, blob_str(&key)); |
| 964 | 964 | blob_reset(&key); |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | /* |
| 968 | -** Change the schema name of the main database to from "main" to zLabel. | |
| 968 | +** Change the schema name of the "main" database to zLabel. | |
| 969 | 969 | ** zLabel must be a static string that is unchanged for the life of |
| 970 | 970 | ** the database connection. |
| 971 | +** | |
| 972 | +** After calling this routine, db_database_slot(zLabel) should | |
| 973 | +** return 0. | |
| 971 | 974 | */ |
| 972 | 975 | void db_set_main_schemaname(sqlite3 *db, const char *zLabel){ |
| 973 | 976 | if( sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, zLabel) ){ |
| 974 | 977 | fossil_fatal("Fossil requires a version of SQLite that supports the " |
| 975 | 978 | "SQLITE_DBCONFIG_MAINDBNAME interface."); |
| 976 | 979 | } |
| 977 | 980 | } |
| 978 | 981 | |
| 979 | -/* | |
| 980 | -** zDbName is the name of a database file. If no other database | |
| 981 | -** file is open, then open this one. If another database file is | |
| 982 | -** already open, then attach zDbName using the name zLabel. | |
| 983 | -*/ | |
| 984 | -void db_open_or_attach(const char *zDbName, const char *zLabel){ | |
| 985 | - if( !g.db ){ | |
| 986 | - g.db = db_open(zDbName); | |
| 987 | - db_set_main_schemaname(g.db, zLabel); | |
| 988 | - }else{ | |
| 989 | - db_attach(zDbName, zLabel); | |
| 990 | - } | |
| 991 | -} | |
| 992 | - | |
| 993 | 982 | /* |
| 994 | 983 | ** Return the slot number for database zLabel. The first database |
| 995 | 984 | ** opened is slot 0. The "temp" database is slot 1. Attached databases |
| 996 | 985 | ** are slots 2 and higher. |
| 997 | 986 | ** |
| @@ -1008,10 +997,24 @@ | ||
| 1008 | 997 | } |
| 1009 | 998 | } |
| 1010 | 999 | db_finalize(&q); |
| 1011 | 1000 | return iSlot; |
| 1012 | 1001 | } |
| 1002 | + | |
| 1003 | +/* | |
| 1004 | +** zDbName is the name of a database file. If no other database | |
| 1005 | +** file is open, then open this one. If another database file is | |
| 1006 | +** already open, then attach zDbName using the name zLabel. | |
| 1007 | +*/ | |
| 1008 | +void db_open_or_attach(const char *zDbName, const char *zLabel){ | |
| 1009 | + if( !g.db ){ | |
| 1010 | + g.db = db_open(zDbName); | |
| 1011 | + db_set_main_schemaname(g.db, zLabel); | |
| 1012 | + }else{ | |
| 1013 | + db_attach(zDbName, zLabel); | |
| 1014 | + } | |
| 1015 | +} | |
| 1013 | 1016 | |
| 1014 | 1017 | /* |
| 1015 | 1018 | ** Close the per-user database file in ~/.fossil |
| 1016 | 1019 | */ |
| 1017 | 1020 | void db_close_config(){ |
| 1018 | 1021 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -963,35 +963,24 @@ | |
| 963 | zDbName, zLabel, blob_str(&key)); |
| 964 | blob_reset(&key); |
| 965 | } |
| 966 | |
| 967 | /* |
| 968 | ** Change the schema name of the main database to from "main" to zLabel. |
| 969 | ** zLabel must be a static string that is unchanged for the life of |
| 970 | ** the database connection. |
| 971 | */ |
| 972 | void db_set_main_schemaname(sqlite3 *db, const char *zLabel){ |
| 973 | if( sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, zLabel) ){ |
| 974 | fossil_fatal("Fossil requires a version of SQLite that supports the " |
| 975 | "SQLITE_DBCONFIG_MAINDBNAME interface."); |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | /* |
| 980 | ** zDbName is the name of a database file. If no other database |
| 981 | ** file is open, then open this one. If another database file is |
| 982 | ** already open, then attach zDbName using the name zLabel. |
| 983 | */ |
| 984 | void db_open_or_attach(const char *zDbName, const char *zLabel){ |
| 985 | if( !g.db ){ |
| 986 | g.db = db_open(zDbName); |
| 987 | db_set_main_schemaname(g.db, zLabel); |
| 988 | }else{ |
| 989 | db_attach(zDbName, zLabel); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | /* |
| 994 | ** Return the slot number for database zLabel. The first database |
| 995 | ** opened is slot 0. The "temp" database is slot 1. Attached databases |
| 996 | ** are slots 2 and higher. |
| 997 | ** |
| @@ -1008,10 +997,24 @@ | |
| 1008 | } |
| 1009 | } |
| 1010 | db_finalize(&q); |
| 1011 | return iSlot; |
| 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | ** Close the per-user database file in ~/.fossil |
| 1016 | */ |
| 1017 | void db_close_config(){ |
| 1018 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -963,35 +963,24 @@ | |
| 963 | zDbName, zLabel, blob_str(&key)); |
| 964 | blob_reset(&key); |
| 965 | } |
| 966 | |
| 967 | /* |
| 968 | ** Change the schema name of the "main" database to zLabel. |
| 969 | ** zLabel must be a static string that is unchanged for the life of |
| 970 | ** the database connection. |
| 971 | ** |
| 972 | ** After calling this routine, db_database_slot(zLabel) should |
| 973 | ** return 0. |
| 974 | */ |
| 975 | void db_set_main_schemaname(sqlite3 *db, const char *zLabel){ |
| 976 | if( sqlite3_db_config(db, SQLITE_DBCONFIG_MAINDBNAME, zLabel) ){ |
| 977 | fossil_fatal("Fossil requires a version of SQLite that supports the " |
| 978 | "SQLITE_DBCONFIG_MAINDBNAME interface."); |
| 979 | } |
| 980 | } |
| 981 | |
| 982 | /* |
| 983 | ** Return the slot number for database zLabel. The first database |
| 984 | ** opened is slot 0. The "temp" database is slot 1. Attached databases |
| 985 | ** are slots 2 and higher. |
| 986 | ** |
| @@ -1008,10 +997,24 @@ | |
| 997 | } |
| 998 | } |
| 999 | db_finalize(&q); |
| 1000 | return iSlot; |
| 1001 | } |
| 1002 | |
| 1003 | /* |
| 1004 | ** zDbName is the name of a database file. If no other database |
| 1005 | ** file is open, then open this one. If another database file is |
| 1006 | ** already open, then attach zDbName using the name zLabel. |
| 1007 | */ |
| 1008 | void db_open_or_attach(const char *zDbName, const char *zLabel){ |
| 1009 | if( !g.db ){ |
| 1010 | g.db = db_open(zDbName); |
| 1011 | db_set_main_schemaname(g.db, zLabel); |
| 1012 | }else{ |
| 1013 | db_attach(zDbName, zLabel); |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | /* |
| 1018 | ** Close the per-user database file in ~/.fossil |
| 1019 | */ |
| 1020 | void db_close_config(){ |
| 1021 |