本文整理汇总了Golang中github.com/ziutek/mymysql/mysql.Conn类的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GrantExists
func (mu *MysqlUser) GrantExists(db mysql.Conn) (bool, error) {
rows, _, err := db.Query(
"SHOW GRANTS FOR '%v'@'%v'",
mu.Username,
mu.Hostname,
)
if err != nil {
return false, err
}
if len(rows) == 0 {
return false, nil
}
for _, row := range rows {
grant := row.Str(0)
// This regex hasn't been extensively tested but works in my local tests
regex := fmt.Sprintf("GRANT ALL (.+) ON .%v.(.+) TO .%[email protected]%v.", mu.Database, mu.Username, mu.Hostname)
matched, err := regexp.MatchString(regex, grant)
if err != nil {
return false, err
}
if matched {
return true, nil
}
}
return false, nil
}
示例2: fetchShowStatus
func (m MySQLPlugin) fetchShowStatus(db mysql.Conn, stat map[string]float64) error {
rows, _, err := db.Query("show /*!50002 global */ status")
if err != nil {
log.Fatalln("FetchMetrics (Status): ", err)
return err
}
for _, row := range rows {
if len(row) > 1 {
variableName := string(row[0].([]byte))
if err != nil {
log.Fatalln("FetchMetrics (Status Fetch): ", err)
return err
}
stat[variableName], _ = atof(string(row[1].([]byte)))
} else {
log.Fatalln("FetchMetrics (Status): row length is too small: ", len(row))
}
}
if m.EnableExtended {
err = fetchShowStatusBackwardCompatibile(stat)
if err != nil {
log.Fatalln("FetchExtendedMetrics (Status Fetch): ", err)
}
}
return nil
}
示例3: fetchProcesslist
func (m MySQLPlugin) fetchProcesslist(db mysql.Conn, stat map[string]float64) error {
rows, _, err := db.Query("SHOW PROCESSLIST")
if err != nil {
log.Fatalln("FetchMetrics (Processlist): ", err)
return err
}
for k := range processState {
stat[k] = 0
}
for _, row := range rows {
if len(row) > 1 {
var state string
if row[6] == nil {
state = "NULL"
} else {
state = string(row[6].([]byte))
}
parseProcesslist(state, &stat)
} else {
log.Fatalln("FetchMetrics (Processlist): row length is too small: ", len(row))
}
}
return nil
}
示例4: udpateMySqlCdrImportStatus
func udpateMySqlCdrImportStatus(db mysql.Conn, uniqueid string, status int) (err error) {
var query = fmt.Sprintf("UPDATE cdr SET import = %d WHERE uniqueid = '%s'", status, uniqueid)
log.Tracef("update cdr status [%s].\n", query)
_, _, err = db.Query(query)
//
return err
}
示例5: mysqlVersion
func mysqlVersion(conn mysqlc.Conn) (uint, uint, uint, error) {
rows, _, err := conn.Query("SELECT VERSION()")
if err != nil {
return 0, 0, 0, err
}
if len(rows) == 0 {
return 0, 0, 0, fmt.Errorf("SELECT VERSION() returned an empty set")
}
versionString := rows[0].Str(0)
version := strings.Split(versionString, ".")
invalidVersionErr := fmt.Errorf("Invalid major.minor.patch in %q", versionString)
if len(version) != 3 {
return 0, 0, 0, invalidVersionErr
}
major, err := strconv.ParseUint(version[0], 10, 32)
if err != nil {
return 0, 0, 0, invalidVersionErr
}
minor, err := strconv.ParseUint(version[1], 10, 32)
if err != nil {
return 0, 0, 0, invalidVersionErr
}
patch, err := strconv.ParseUint(version[2], 10, 32)
if err != nil {
return 0, 0, 0, invalidVersionErr
}
return uint(major), uint(minor), uint(patch), nil
}
示例6: dumpCreateTable
// Dump the script to create the table
func dumpCreateTable(w io.Writer, db mysql.Conn, table string) {
fmt.Fprintf(w, "\n--\n")
fmt.Fprintf(w, "-- Table structure for table `%s`\n", table)
fmt.Fprintf(w, "--\n\n")
fmt.Fprintf(w, "DROP TABLE IF EXISTS `%s`;\n", table)
row, _, err := db.QueryFirst("SHOW CREATE TABLE `%s`", table)
checkError(err)
fmt.Fprintf(w, "%s;\n", row.Str(1))
}
示例7: innodbStatus
func innodbStatus(m *MysqlIns, db mysql.Conn) ([]*MetaData, error) {
status, _, err := db.QueryFirst("SHOW /*!50000 ENGINE */ INNODB STATUS")
if err != nil {
return nil, err
}
ctn := status.Str(2)
rows := strings.Split(ctn, "\n")
return parseInnodbStatus(m, rows)
}
示例8: CreateDatabase
func (mydb *MysqlDatabase) CreateDatabase(db mysql.Conn) error {
// IF NOT EXISTS isn't strictly necessary since we are checking
// to make sure it doesn't exist first but it doesn't hurt.
_, _, err := db.Query("CREATE DATABASE IF NOT EXISTS %v", mydb.Name)
if err != nil {
return err
}
mydb.Result.Changed = true
return nil
}
示例9: del
func del(db mysql.Conn, bag_id int, stuff_id int) {
_, _, err := db.Query("delete from player_bag where bag_id=%d", bag_id)
if err != nil {
panic(err)
}
_, _, err = db.Query("delete from paladin where paladin_id=%d", stuff_id)
if err != nil {
panic(err)
}
fmt.Printf("delete %d, %d\n", bag_id, stuff_id)
}
示例10: serverVersion
func serverVersion(conn mysqlc.Conn) (*version.Version, error) {
rows, _, err := conn.Query("SELECT VERSION()")
if err != nil {
return nil, err
}
if len(rows) == 0 {
return nil, fmt.Errorf("SELECT VERSION() returned an empty set")
}
return version.NewVersion(rows[0].Str(0))
}
示例11: getTables
// Get list of existing tables in database
func getTables(db mysql.Conn) (tables []string) {
tables = make([]string, 0)
rows, _, err := db.Query("SHOW TABLES")
checkError(err)
for _, row := range rows {
for k, _ := range row {
tables = append(tables, row.Str(k))
}
}
return
}
示例12: QueryCheck
func QueryCheck(db mysql.Conn, sql string, params ...interface{}) ([]mysql.Row, mysql.Result) {
rows, res, err := db.Query(sql)
if err != nil {
errlog.Error("QueryCheck =%s", sql)
errlog.Error("QueryCheck err=%s", err.Error())
fmt.Println(sql)
fmt.Println(err)
os.Exit(1)
}
return rows, res
}
示例13: ProcessNum
func ProcessNum(db mysql.Conn, cfg *base.Cfg) (*model.MetaData, error) {
sql := "SHOW PROCESSLIST"
rows, _, err := db.Query(sql)
if err != nil {
return nil, err
}
monitorName := "process_nums"
threadNum := len(rows) - 1
data := model.NewMetric(monitorName, cfg)
data.SetValue(threadNum)
return data, nil
}
示例14: queryByPath
func queryByPath(w http.ResponseWriter, db mysql.Conn, pt string) {
rows, res := checkedResult(db.Query("select full_result from risks_check_history where apk='%s' ORDER BY id DESC Limit 1", pt))
full_result := res.Map("full_result")
for _, row := range rows {
//fmt.Ffmt.Printlnf(w,
fmt.Fprintf(w,
"------[ %s 包含以下风险]---------\n%s\n",
pt,
row.Str(full_result),
)
RightLine()
}
}
示例15: fetchShowInnodbStatus
func (m MySQLPlugin) fetchShowInnodbStatus(db mysql.Conn, stat map[string]float64) error {
row, _, err := db.QueryFirst("SHOW /*!50000 ENGINE*/ INNODB STATUS")
if err != nil {
log.Fatalln("FetchMetrics (InnoDB Status): ", err)
return err
}
if len(row) > 0 {
parseInnodbStatus(string(row[len(row)-1].([]byte)), &stat)
} else {
log.Fatalln("FetchMetrics (InnoDB Status): row length is too small: ", len(row))
}
return nil
}