本文整理汇总了Golang中github.com/ziutek/mymysql/mysql.Conn.QueryFirst方法的典型用法代码示例。如果您正苦于以下问题:Golang Conn.QueryFirst方法的具体用法?Golang Conn.QueryFirst怎么用?Golang Conn.QueryFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ziutek/mymysql/mysql.Conn
的用法示例。
在下文中一共展示了Conn.QueryFirst方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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))
}
示例2: 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)
}
示例3: 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
}
示例4: dumpTableData
// Get the table data
func dumpTableData(w io.Writer, db mysql.Conn, table string) {
fmt.Fprintf(w, "\n--\n-- Dumping data for table `%s`\n--\n\n", table)
rowCnt, _, err := db.QueryFirst(getSelectCountQueryFor(db, table))
checkError(err)
if rowCnt.Int(0) == 0 {
fmt.Fprintf(w, "--\n-- Empty table\n--\n\n")
return
} else {
fmt.Fprintf(w, "--\n-- %d rows\n--\n\n", rowCnt.Int(0))
}
fmt.Fprintf(w, "LOCK TABLES `%s` WRITE;\n", table)
query := fmt.Sprintf("INSERT INTO `%s` VALUES", table)
rows := make([]string, 0)
res, err := db.Start(getSelectQueryFor(db, table))
checkError(err)
row := res.MakeRow()
for {
err = res.ScanRow(row)
if err == io.EOF {
break
}
checkError(err)
vals := make([]string, 0)
for k, col := range row {
val := "NULL"
if col != nil {
val = fmt.Sprintf("'%s'", db.EscapeString(row.Str(k)))
}
vals = append(vals, val)
}
rows = append(rows, fmt.Sprintf("( %s )", strings.Join(vals, ", ")))
if len(rows) >= 100 {
fmt.Fprintf(w, "%s\n%s;\n", query, strings.Join(rows, ",\n"))
rows = make([]string, 0)
}
}
if len(rows) > 0 {
fmt.Fprintf(w, "%s\n%s;\n", query, strings.Join(rows, ",\n"))
}
fmt.Fprintf(w, "\nUNLOCK TABLES;\n")
}
示例5: slaveStatus
func slaveStatus(m *MysqlIns, db mysql.Conn) ([]*MetaData, error) {
isSlave := NewMetric("Is_slave")
row, res, err := db.QueryFirst("SHOW SLAVE STATUS")
if err != nil {
return nil, err
}
// be master
if row == nil {
isSlave.SetValue(0)
return []*MetaData{isSlave}, nil
}
// be slave
isSlave.SetValue(1)
data := make([]*MetaData, len(SlaveStatusToSend))
for i, s := range SlaveStatusToSend {
data[i] = NewMetric(s)
switch s {
case "Slave_SQL_Running", "Slave_IO_Running":
data[i].SetValue(0)
v := row.Str(res.Map(s))
if v == "Yes" {
data[i].SetValue(1)
}
default:
v, err := row.Int64Err(res.Map(s))
if err != nil {
data[i].SetValue(-1)
} else {
data[i].SetValue(v)
}
}
}
return append(data, isSlave), nil
}
示例6: SlaveStatus
func SlaveStatus(db mysql.Conn, cfg *base.Cfg) ([]*model.MetaData, error) {
isSlave := model.NewMetric("Is_slave", cfg)
row, res, err := db.QueryFirst("SHOW SLAVE STATUS")
if err != nil {
return nil, err
}
// be master
if row == nil {
isSlave.SetValue(0)
isSlave.Tags = fmt.Sprintf("%s,role=%s", isSlave.Tags, "master")
return []*model.MetaData{isSlave}, nil
}
// be slave
isSlave.SetValue(1)
isSlave.Tags = fmt.Sprintf("%s,role=%s", isSlave.Tags, "slaver")
data := make([]*model.MetaData, len(SlaveStatusToSend))
for i, s := range SlaveStatusToSend {
data[i] = model.NewMetric(s, cfg)
switch s {
case "Slave_SQL_Running", "Slave_IO_Running":
data[i].SetValue(0)
v := row.Str(res.Map(s))
if v == "Yes" {
data[i].SetValue(1)
}
default:
v, err := row.Int64Err(res.Map(s))
if err != nil {
data[i].SetValue(-1)
} else {
data[i].SetValue(v)
}
}
}
return append(data, isSlave), nil
}