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()
if err != nil {
log.Print("err2: ", err)
return err
}
err = afterDBInit()

View File

@ -4,7 +4,7 @@ package qgen
import (
"database/sql"
"errors"
"fmt"
"os"
"runtime"
"strconv"
"strings"
@ -41,13 +41,6 @@ func (adapter *MysqlAdapter) GetStmts() map[string]DBStmt {
// TODO: Add an option to disable unix pipes
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"]
if !ok {
return nil, ErrNoCollation
@ -64,14 +57,15 @@ func (adapter *MysqlAdapter) BuildConn(config map[string]string) (*sql.DB, error
dbsocket = config["socket"]
}
// 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 {
db, err := sql.Open("mysql", config["username"]+dbpassword+"@unix("+dbsocket+")/"+config["name"]+"?collation="+dbCollation+"&parseTime=true")
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