本文整理汇总了Golang中github.com/pingcap/tidb/mysql.NewErr函数的典型用法代码示例。如果您正苦于以下问题:Golang NewErr函数的具体用法?Golang NewErr怎么用?Golang NewErr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewErr函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: readHandshakeResponse
func (cc *clientConn) readHandshakeResponse() error {
data, err := cc.readPacket()
if err != nil {
return errors.Trace(err)
}
pos := 0
// capability
cc.capability = binary.LittleEndian.Uint32(data[:4])
pos += 4
// skip max packet size
pos += 4
// charset, skip, if you want to use another charset, use set names
cc.collation = data[pos]
pos++
// skip reserved 23[00]
pos += 23
// user name
cc.user = string(data[pos : pos+bytes.IndexByte(data[pos:], 0)])
pos += len(cc.user) + 1
// auth length and auth
authLen := int(data[pos])
pos++
auth := data[pos : pos+authLen]
pos += authLen
if cc.capability&mysql.ClientConnectWithDB > 0 {
if len(data[pos:]) > 0 {
idx := bytes.IndexByte(data[pos:], 0)
cc.dbname = string(data[pos : pos+idx])
}
}
// Open session and do auth
cc.ctx, err = cc.server.driver.OpenCtx(cc.capability, uint8(cc.collation), cc.dbname)
if err != nil {
cc.Close()
return errors.Trace(err)
}
if !cc.server.skipAuth() {
// Do Auth
addr := cc.conn.RemoteAddr().String()
host, _, err1 := net.SplitHostPort(addr)
if err1 != nil {
return errors.Trace(mysql.NewErr(mysql.ErrAccessDenied, cc.user, addr, "Yes"))
}
user := fmt.Sprintf("%[email protected]%s", cc.user, host)
if !cc.ctx.Auth(user, auth, cc.salt) {
return errors.Trace(mysql.NewErr(mysql.ErrAccessDenied, cc.user, host, "Yes"))
}
}
return nil
}
开发者ID:netroby,项目名称:tidb,代码行数:51,代码来源:conn.go
示例2: getTable
func (s *ShowPlan) getTable(ctx context.Context) (table.Table, error) {
is := sessionctx.GetDomain(ctx).InfoSchema()
dbName := model.NewCIStr(s.DBName)
if !is.SchemaExists(dbName) {
// MySQL returns no such table here if database doesn't exist.
return nil, errors.Trace(mysql.NewErr(mysql.ErrNoSuchTable, s.DBName, s.TableName))
}
tbName := model.NewCIStr(s.TableName)
tb, err := is.TableByName(dbName, tbName)
if err != nil {
return nil, errors.Trace(mysql.NewErr(mysql.ErrNoSuchTable, s.DBName, s.TableName))
}
return tb, nil
}
开发者ID:netroby,项目名称:tidb,代码行数:14,代码来源:show.go
示例3: AppendParam
// AppendParam implements IStatement AppendParam method.
func (ts *TiDBStatement) AppendParam(paramID int, data []byte) error {
if paramID >= len(ts.boundParams) {
return mysql.NewErr(mysql.ErrWrongArguments, "stmt_send_longdata")
}
ts.boundParams[paramID] = append(ts.boundParams[paramID], data...)
return nil
}
开发者ID:yzl11,项目名称:vessel,代码行数:8,代码来源:driver_tidb.go
示例4: handleStmtReset
func (cc *clientConn) handleStmtReset(data []byte) (err error) {
if len(data) < 4 {
return mysql.ErrMalformPacket
}
stmtID := int(binary.LittleEndian.Uint32(data[0:4]))
stmt := cc.ctx.GetStatement(stmtID)
if stmt == nil {
return mysql.NewErr(mysql.ErrUnknownStmtHandler,
strconv.Itoa(stmtID), "stmt_reset")
}
stmt.Reset()
return cc.writeOK()
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:14,代码来源:conn_stmt.go
示例5: readHandshakeResponse
func (cc *clientConn) readHandshakeResponse() error {
data, err := cc.readPacket()
if err != nil {
return errors.Trace(err)
}
var p handshakeResponse41
if err = handshakeResponseFromData(&p, data); err != nil {
return errors.Trace(err)
}
cc.capability = p.Capability & defaultCapability
cc.user = p.User
cc.dbname = p.DBName
cc.collation = p.Collation
cc.attrs = p.Attrs
// Open session and do auth
cc.ctx, err = cc.server.driver.OpenCtx(uint64(cc.connectionID), cc.capability, uint8(cc.collation), cc.dbname)
if err != nil {
cc.Close()
return errors.Trace(err)
}
if !cc.server.skipAuth() {
// Do Auth
addr := cc.conn.RemoteAddr().String()
host, _, err1 := net.SplitHostPort(addr)
if err1 != nil {
return errors.Trace(mysql.NewErr(mysql.ErrAccessDenied, cc.user, addr, "Yes"))
}
user := fmt.Sprintf("%[email protected]%s", cc.user, host)
if !cc.ctx.Auth(user, p.Auth, cc.salt) {
return errors.Trace(mysql.NewErr(mysql.ErrAccessDenied, cc.user, host, "Yes"))
}
}
return nil
}
开发者ID:jmptrader,项目名称:tidb,代码行数:36,代码来源:conn.go
示例6: handleStmtSendLongData
func (cc *clientConn) handleStmtSendLongData(data []byte) (err error) {
if len(data) < 6 {
return mysql.ErrMalformPacket
}
stmtID := int(binary.LittleEndian.Uint32(data[0:4]))
stmt := cc.ctx.GetStatement(stmtID)
if stmt == nil {
return mysql.NewErr(mysql.ErrUnknownStmtHandler,
strconv.Itoa(stmtID), "stmt_send_longdata")
}
paramID := int(binary.LittleEndian.Uint16(data[4:6]))
return stmt.AppendParam(paramID, data[6:])
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:16,代码来源:conn_stmt.go
示例7: handleStmtExecute
func (cc *clientConn) handleStmtExecute(data []byte) (err error) {
if len(data) < 9 {
return mysql.ErrMalformPacket
}
pos := 0
stmtID := binary.LittleEndian.Uint32(data[0:4])
pos += 4
stmt := cc.ctx.GetStatement(int(stmtID))
if stmt == nil {
return mysql.NewErr(mysql.ErrUnknownStmtHandler,
strconv.FormatUint(uint64(stmtID), 10), "stmt_execute")
}
flag := data[pos]
pos++
//now we only support CURSOR_TYPE_NO_CURSOR flag
if flag != 0 {
return mysql.NewErrf(mysql.ErrUnknown, "unsupported flag %d", flag)
}
//skip iteration-count, always 1
pos += 4
var (
nullBitmaps []byte
paramTypes []byte
paramValues []byte
)
numParams := stmt.NumParams()
args := make([]interface{}, numParams)
if numParams > 0 {
nullBitmapLen := (numParams + 7) >> 3
if len(data) < (pos + nullBitmapLen + 1) {
return mysql.ErrMalformPacket
}
nullBitmaps = data[pos : pos+nullBitmapLen]
pos += nullBitmapLen
//new param bound flag
if data[pos] == 1 {
pos++
if len(data) < (pos + (numParams << 1)) {
return mysql.ErrMalformPacket
}
paramTypes = data[pos : pos+(numParams<<1)]
pos += (numParams << 1)
paramValues = data[pos:]
}
err = parseStmtArgs(args, stmt.BoundParams(), nullBitmaps, paramTypes, paramValues)
if err != nil {
return errors.Trace(err)
}
}
rs, err := stmt.Execute(args...)
if err != nil {
return errors.Trace(err)
}
if rs == nil {
return errors.Trace(cc.writeOK())
}
return errors.Trace(cc.writeResultset(rs, true))
}
开发者ID:XuHuaiyu,项目名称:tidb,代码行数:67,代码来源:conn_stmt.go
注:本文中的github.com/pingcap/tidb/mysql.NewErr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论