1 Star 0 Fork 0

zhoujin826/tidb

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
driver.go 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
Jack Yu 提交于 2017-10-11 00:28 . add mysqlx driver (#4748)
// Go driver for MySQL X Protocol
//
// Copyright 2016 Simon J Mudd.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at http://mozilla.org/MPL/2.0/.
//
// MySQL X protocol authentication using MYSQL41 method
package mysql
import (
"database/sql"
"database/sql/driver"
"net"
)
// This struct is exported to make the driver directly accessible.
// In general the driver is used via the database/sql package.
type XDriver struct{}
// DialFunc is a function which can be used to establish the network connection.
// Custom dial functions must be registered with RegisterDial
type DialFunc func(addr string) (net.Conn, error)
var dials map[string]DialFunc
// RegisterDial registers a custom dial function. It can then be used by the
// network address mynet(addr), where mynet is the registered new network.
// addr is passed as a parameter to the dial function.
func RegisterDial(net string, dial DialFunc) {
if dials == nil {
dials = make(map[string]DialFunc)
}
dials[net] = dial
}
func (d XDriver) Open(dsn string) (driver.Conn, error) {
var err error
cfg, err := parseDSN(dsn)
if err != nil {
return nil, err
}
cfg.useXProtocol = true // force X protocol as this driver was called explicitly
// New mysqlConn
mc := &mysqlXConn{
capabilities: NewServerCapabilities(),
cfg: NewXconfigFromConfig(cfg),
maxPacketAllowed: maxPacketSize,
maxWriteSize: maxPacketSize - 1,
}
return mc.Open2()
}
func init() {
sql.Register("mysql/xprotocol", &XDriver{})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhoujin826/tidb.git
git@gitee.com:zhoujin826/tidb.git
zhoujin826
tidb
tidb
v1.0.4

搜索帮助