This should fix it x.x

This commit is contained in:
Azareal 2018-08-29 13:46:27 +10:00
parent f84f11a1eb
commit 91c81b96e0
2 changed files with 8 additions and 15 deletions

View File

@ -85,7 +85,6 @@ func gloinit() (err error) {
} }
err = InitDatabase() err = InitDatabase()
if err != nil { if err != nil {
log.Print("err2: ", err)
return err return err
} }
err = afterDBInit() err = afterDBInit()

View File

@ -4,7 +4,7 @@ package qgen
import ( import (
"database/sql" "database/sql"
"errors" "errors"
"fmt" "os"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
@ -41,13 +41,6 @@ func (adapter *MysqlAdapter) GetStmts() map[string]DBStmt {
// TODO: Add an option to disable unix pipes // TODO: Add an option to disable unix pipes
func (adapter *MysqlAdapter) BuildConn(config map[string]string) (*sql.DB, error) { func (adapter *MysqlAdapter) BuildConn(config map[string]string) (*sql.DB, error) {
// The adapter seems to be panicking when encountering a recoverable error x.x
defer func() {
if r := recover(); r != nil {
fmt.Println("Recovered in f", r)
}
}()
dbCollation, ok := config["collation"] dbCollation, ok := config["collation"]
if !ok { if !ok {
return nil, ErrNoCollation return nil, ErrNoCollation
@ -64,14 +57,15 @@ func (adapter *MysqlAdapter) BuildConn(config map[string]string) (*sql.DB, error
dbsocket = config["socket"] dbsocket = config["socket"]
} }
db, err := sql.Open("mysql", config["username"]+dbpassword+"@unix("+dbsocket+")/"+config["name"]+"?collation="+dbCollation+"&parseTime=true") // The MySQL adapter refuses to open any other connections, if the unix socket doesn't exist, so check for it first
_, err := os.Stat(dbsocket)
if err == nil { if err == nil {
// Make sure that the connection is alive db, err := sql.Open("mysql", config["username"]+dbpassword+"@unix("+dbsocket+")/"+config["name"]+"?collation="+dbCollation+"&parseTime=true")
return db, db.Ping() if err == nil {
// Make sure that the connection is alive
return db, db.Ping()
}
} }
// Am I supposed to do this? o.O
db, err = nil, nil
} }
// Open the database connection // Open the database connection