Skip to content

Commit 15093d2

Browse files
author
c9845
committed
Clean up some logging output when connecting to a db. It was a bit messy in real-world use.
Turned func into method for getting PRAGMAs as a string. This is a bit better for usage and was needed to log out PRAGMAs during Connect().
1 parent f2be271 commit 15093d2

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

changlog.txt

+13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
v2.3.1
2+
----------
3+
- Clean up and organize debug logging output.
4+
5+
v2.3.0
6+
----------
7+
- Remove functionality for skipping INSERT INTO statements when deploying db.
8+
- This only worked for DeployQueries, not for DeployFuncs, and this led to confusion.
9+
10+
v2.2.0
11+
----------
12+
- Add support for translating CREATE TABLE queries when updating a database.
13+
114
v2.1.0
215
----------
316
- Support for UpdateFuncs.

sqldb-sqlite.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ func GetSQLiteLibrary() string {
9999
return sqliteLibrary
100100
}
101101

102-
// buildPragmaString builds the string of pragmas that should be appended to the filename
103-
// when connecting to a SQLite database. This is needed to set pragmas reliably since
104-
// pragmas must be set upon initially connecting to the database. The difficulty in
105-
// setting pragmas is that each SQLite library (mattn vs modernc) has a slighly different
106-
// format for setting pragmas. This takes the list of pragmas in SQLite query format (
107-
// PRAGMA busy_timeout = 5000) and translates them to the correct format for the SQLite
108-
// library in use.
109-
func buildPragmaString(pragmas []string) (filenamePragmaString string) {
102+
// SQLitePragmasAsString builds the string of pragmas that should be appended to the
103+
// filename when connecting to a SQLite database. This is needed to set pragmas reliably
104+
// since pragmas must be set upon initially connecting to the database. The difficulty
105+
// in setting pragmas is that each SQLite library (mattn vs modernc) has a slighly
106+
// different format for setting pragmas. This takes the list of pragmas in SQLite query
107+
// format (PRAGMA busy_timeout = 5000) and translates them to the correct format for
108+
// the SQLite library in use.
109+
func (cfg *Config) SQLitePragmasAsString() (filenamePragmaString string) {
110110
v := url.Values{}
111111

112-
for _, p := range pragmas {
113-
//Sanitize, make replace/stripping of "PRAGMA" keyword easier.
112+
for _, p := range cfg.SQLitePragmas {
113+
//Sanitize, to make replace/stripping of "PRAGMA" keyword easier.
114114
p = strings.ToLower(p)
115115

116116
//Strip out the PRAGMA keyword.
@@ -144,7 +144,7 @@ func buildPragmaString(pragmas []string) (filenamePragmaString string) {
144144
//add
145145
v.Add(key, value)
146146
default:
147-
//this can never happen since we hardcode libraries.
147+
//this can never happen since we hardcode the supported sqlite libraries.
148148
}
149149
}
150150

sqldb.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,11 @@ func (cfg *Config) buildConnectionString(deployingDB bool) (connString string) {
409409
//For SQLite, the connection string is simply a path to a file. However, we
410410
//need to append pragmas as needed.
411411
if len(cfg.SQLitePragmas) != 0 {
412-
pragmasToAdd := buildPragmaString(cfg.SQLitePragmas)
412+
pragmasToAdd := cfg.SQLitePragmasAsString()
413413
connString += pragmasToAdd
414414

415-
cfg.debugPrintln("sqldb.buildConnectionString", "PRAGMA String:", pragmasToAdd)
415+
//Logging for development debugging.
416+
// cfg.debugPrintln("sqldb.buildConnectionString", "PRAGMA String:", pragmasToAdd)
416417
// cfg.debugPrintln("sqldb.buildConnectionString", "Path With PRAGMAS:", connString)
417418
}
418419

@@ -527,7 +528,10 @@ func (cfg *Config) Connect() (err error) {
527528
cfg.debugPrintln("sqldb.Connect", "Connecting to database "+cfg.Name+" on "+cfg.Host+" with user "+cfg.User)
528529
case DBTypeSQLite:
529530
cfg.debugPrintln("sqldb.Connect", "Connecting to database "+cfg.SQLitePath+".")
530-
cfg.debugPrintln("sqldb.Connect", "Using SQLite Library "+GetSQLiteLibrary()+".")
531+
cfg.debugPrintln("sqldb.Connect", "SQLite Library: "+GetSQLiteLibrary()+".")
532+
cfg.debugPrintln("sqldb.Connect", "PRAGMAS: "+cfg.SQLitePragmasAsString()+".")
533+
default:
534+
//this can never happen since we hardcode the supported sqlite libraries.
531535
}
532536

533537
return

sqldb_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,15 @@ func TestString(t *testing.T) {
974974
}
975975
}
976976

977-
func TestBuildPragmaString(t *testing.T) {
977+
func TestSQLitePragmasAsString(t *testing.T) {
978978
p := []string{
979979
"PRAGMA journal_mode = WAL",
980980
"PRAGMA busy_timeout = 5000",
981981
}
982+
cfg := NewSQLiteConfig("")
983+
cfg.SQLitePragmas = p
982984

983-
built := buildPragmaString(p)
985+
built := cfg.SQLitePragmasAsString()
984986

985987
u, err := url.ParseQuery(built)
986988
if err != nil {

0 commit comments

Comments
 (0)