show sql query on sql error
This commit is contained in:
parent
96484eba5a
commit
e39d4c3a13
3
db.go
3
db.go
@ -2,6 +2,7 @@ package advsql
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
@ -53,7 +54,7 @@ func (db *Database) stmt(query string) *sql.Stmt {
|
|||||||
|
|
||||||
stmt, err := db.db.Prepare(query)
|
stmt, err := db.db.Prepare(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(fmt.Errorf("compilation failed for query '%s' reason: %w", query, err))
|
||||||
}
|
}
|
||||||
db.stmts[query] = stmt
|
db.stmts[query] = stmt
|
||||||
return stmt
|
return stmt
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
)
|
)
|
||||||
|
|
||||||
var TestDatabase *Database //= new(Database)
|
var TestDatabase = new(Database)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Name string
|
Name string
|
||||||
@ -28,11 +28,12 @@ func ScanUserPkLast(u *User, encode ScanFunc) error {
|
|||||||
var (
|
var (
|
||||||
InsertUser = Insert(TestDatabase, "INSERT INTO users VALUES (?, ?, ?)", ScanUserPkFirst)
|
InsertUser = Insert(TestDatabase, "INSERT INTO users VALUES (?, ?, ?)", ScanUserPkFirst)
|
||||||
UpdateUser = Update(TestDatabase, "UPDATE users SET hash = ?, salt = ? WHERE name = ?", ScanUserPkLast)
|
UpdateUser = Update(TestDatabase, "UPDATE users SET hash = ?, salt = ? WHERE name = ?", ScanUserPkLast)
|
||||||
GetUserByName = QueryOne(TestDatabase, "SELECT * FROM users WHERE name = ?", ScanUserPkFirst)
|
GetUserByName = QueryOne(TestDatabase, "SELECT * FROM users WHERE namea = ?", ScanUserPkFirst)
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDB(t *testing.T) {
|
func TestDB(t *testing.T) {
|
||||||
InitMysqlDatabase(TestDatabase, "ip", 3306, "username", "password", "database")
|
InitMysqlDatabase(TestDatabase, "192.168.178.2", 3306, "root", "6MvtRA4iZJtbenR537otFnoHpzt9vYN7", "users")
|
||||||
|
//InitMysqlDatabase(TestDatabase, "ip", 3306, "username", "password", "database")
|
||||||
defer TestDatabase.Close()
|
defer TestDatabase.Close()
|
||||||
|
|
||||||
pw := sha512.Sum512([]byte("weiter"))
|
pw := sha512.Sum512([]byte("weiter"))
|
||||||
|
Loading…
Reference in New Issue
Block a user