• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang mysql.Conn类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ziutek/mymysql/mysql.Conn的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Conn类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:sfreiberg,项目名称:shepherd,代码行数:28,代码来源:mysql.go


示例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
}
开发者ID:supercaracal,项目名称:mackerel-agent-plugins,代码行数:27,代码来源:mysql.go


示例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
}
开发者ID:supercaracal,项目名称:mackerel-agent-plugins,代码行数:27,代码来源:mysql.go


示例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
}
开发者ID:vassilux,项目名称:vorimport,代码行数:7,代码来源:mysql.go


示例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
}
开发者ID:Originate,项目名称:terraform,代码行数:33,代码来源:provider.go


示例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))
}
开发者ID:sirishkumar,项目名称:mysqlsuperdump,代码行数:10,代码来源:mysqlsuperdump.go


示例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)
}
开发者ID:ZhuoRoger,项目名称:mymon,代码行数:9,代码来源:innodbStatus.go


示例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
}
开发者ID:sfreiberg,项目名称:shepherd,代码行数:10,代码来源:mysql.go


示例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)
}
开发者ID:bonly,项目名称:exercise,代码行数:11,代码来源:20100812_del_paladin.go


示例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))
}
开发者ID:partamonov,项目名称:terraform,代码行数:11,代码来源:provider.go


示例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
}
开发者ID:sirishkumar,项目名称:mysqlsuperdump,代码行数:12,代码来源:mysqlsuperdump.go


示例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
}
开发者ID:zkbcoder,项目名称:gosrc,代码行数:12,代码来源:main.go


示例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
}
开发者ID:onlymellb,项目名称:mysql-monitor,代码行数:12,代码来源:process.go


示例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()
	}
}
开发者ID:hxangel,项目名称:golang,代码行数:13,代码来源:scan.go


示例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
}
开发者ID:supercaracal,项目名称:mackerel-agent-plugins,代码行数:14,代码来源:mysql.go


示例16: fetchShowSlaveStatus

func (m MySQLPlugin) fetchShowSlaveStatus(db mysql.Conn, stat map[string]float64) error {
	rows, res, err := db.Query("show slave status")
	if err != nil {
		log.Fatalln("FetchMetrics (Slave Status): ", err)
		return err
	}

	for _, row := range rows {
		idx := res.Map("Seconds_Behind_Master")
		Value := row.Int(idx)
		stat["Seconds_Behind_Master"] = float64(Value)
	}
	return nil
}
开发者ID:naokibtn,项目名称:mackerel-agent-plugins,代码行数:14,代码来源:mysql.go


示例17: getColumnListForSelect

// Get the column list for the SELECT, applying the select map
// from config file.
func getColumnListForSelect(db mysql.Conn, table string) string {
	columns := make([]string, 0)
	rows, res, err := db.Query("SHOW COLUMNS FROM `%s`", table)
	checkError(err)
	for _, row := range rows {
		column := row.Str(res.Map("Field"))
		replacement, ok := selectMap[table][column]
		if ok {
			column = fmt.Sprintf("%s AS `%s`", replacement, column)
		}
		columns = append(columns, column)
	}
	return strings.Join(columns, ", ")
}
开发者ID:sirishkumar,项目名称:mysqlsuperdump,代码行数:16,代码来源:mysqlsuperdump.go


示例18: deleteMySqlCelRecord

func deleteMySqlCelRecord(db mysql.Conn, uniqueid string) (err error) {

	if config.PurgeCelEvents == false {
		return nil
	}

	var query = fmt.Sprintf("DELETE FROM cel WHERE uniqueid = '%s' OR linkedid = '%s'", uniqueid, uniqueid)
	_, _, err = db.Query(query)

	log.Debugf("getMySqlCallDetails execute : [%s] .\n", query)

	if err != nil {
		log.Errorf("deleteMySqlCelRecord Failed delete record into cel table for uniqueid [%s].\n", uniqueid)
	}
	return err
}
开发者ID:vassilux,项目名称:vorimport,代码行数:16,代码来源:mysql.go


示例19: executeCustomRequests

//Execute customize requests provisted by configuration file
func executeCustomRequests(db mysql.Conn) (err error) {
	for i := range config.CleanupRequests {
		var query = config.CleanupRequests[i]

		if strings.Contains(strings.ToLower(query), "delete") == true {
			return errors.New("Using delete keyword is forbiden. Please check your configuration file(config.json)")
		}
		_, _, err = db.Query(query)

		if err != nil {
			return err
		}

	}
	return nil
}
开发者ID:vassilux,项目名称:vorimport,代码行数:17,代码来源:mysql.go


示例20: DatabaseExists

func (mydb *MysqlDatabase) DatabaseExists(db mysql.Conn) (bool, error) {
	rows, _, err := db.Query(
		"SELECT count(*) AS dbs FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '%v'",
		mydb.Name,
	)
	if err != nil {
		return false, err
	}

	if len(rows) != 1 {
		return false, errors.New("Unexpected number of rows in DatabaseExists()")
	}

	if rows[0].Int(0) > 0 {
		return true, nil
	}
	return false, nil
}
开发者ID:sfreiberg,项目名称:shepherd,代码行数:18,代码来源:mysql.go



注:本文中的github.com/ziutek/mymysql/mysql.Conn类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang mysql.Date类代码示例发布时间:2022-05-28
下一篇:
Golang mysql.New函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap