Git with a cup of tea, painless self-hosted git service Mirror for internal git.with.parts use https://git.with.parts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/vendor/gopkg.in/testfixtures.v2/mysql.go

46 lines
784 B

package testfixtures
import (
"database/sql"
"fmt"
)
// MySQL is the MySQL helper for this package
type MySQL struct {
baseHelper
}
func (*MySQL) paramType() int {
return paramTypeQuestion
}
func (*MySQL) quoteKeyword(str string) string {
return fmt.Sprintf("`%s`", str)
}
func (*MySQL) databaseName(db *sql.DB) (dbName string) {
db.QueryRow("SELECT DATABASE()").Scan(&dbName)
return
}
func (h *MySQL) disableReferentialIntegrity(db *sql.DB, loadFn loadFunction) error {
// re-enable after load
defer db.Exec("SET FOREIGN_KEY_CHECKS = 1")
tx, err := db.Begin()
if err != nil {
return err
}
if _, err = tx.Exec("SET FOREIGN_KEY_CHECKS = 0"); err != nil {
return err
}
if err = loadFn(tx); err != nil {
tx.Rollback()
return err
}
return tx.Commit()
}