本文整理匯總了Golang中github.com/flike/kingshard/mysql.Resultset.RowDatas方法的典型用法代碼示例。如果您正苦於以下問題:Golang Resultset.RowDatas方法的具體用法?Golang Resultset.RowDatas怎麽用?Golang Resultset.RowDatas使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/flike/kingshard/mysql.Resultset
的用法示例。
在下文中一共展示了Resultset.RowDatas方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: newEmptyResultset
func (c *ClientConn) newEmptyResultset(stmt *sqlparser.Select) *mysql.Resultset {
r := new(mysql.Resultset)
r.Fields = make([]*mysql.Field, len(stmt.SelectExprs))
for i, expr := range stmt.SelectExprs {
r.Fields[i] = &mysql.Field{}
switch e := expr.(type) {
case *sqlparser.StarExpr:
r.Fields[i].Name = []byte("*")
case *sqlparser.NonStarExpr:
if e.As != nil {
r.Fields[i].Name = e.As
r.Fields[i].OrgName = hack.Slice(nstring(e.Expr))
} else {
r.Fields[i].Name = hack.Slice(nstring(e.Expr))
}
default:
r.Fields[i].Name = hack.Slice(nstring(e))
}
}
r.Values = make([][]interface{}, 0)
r.RowDatas = make([]mysql.RowData, 0)
return r
}
示例2: buildSimpleShowResultset
func (c *ClientConn) buildSimpleShowResultset(values []interface{}, name string) (*mysql.Resultset, error) {
r := new(mysql.Resultset)
field := &mysql.Field{}
field.Name = hack.Slice(name)
field.Charset = 33
field.Type = mysql.MYSQL_TYPE_VAR_STRING
r.Fields = []*mysql.Field{field}
var row []byte
var err error
for _, value := range values {
row, err = formatValue(value)
if err != nil {
return nil, err
}
r.RowDatas = append(r.RowDatas,
mysql.PutLengthEncodedString(row))
}
return r, nil
}
示例3: limitSelectResult
func (c *ClientConn) limitSelectResult(r *mysql.Resultset, stmt *sqlparser.Select) error {
if stmt.Limit == nil {
return nil
}
var offset, count int64
var err error
if stmt.Limit.Offset == nil {
offset = 0
} else {
if o, ok := stmt.Limit.Offset.(sqlparser.NumVal); !ok {
return fmt.Errorf("invalid select limit %s", nstring(stmt.Limit))
} else {
if offset, err = strconv.ParseInt(hack.String([]byte(o)), 10, 64); err != nil {
return err
}
}
}
if o, ok := stmt.Limit.Rowcount.(sqlparser.NumVal); !ok {
return fmt.Errorf("invalid limit %s", nstring(stmt.Limit))
} else {
if count, err = strconv.ParseInt(hack.String([]byte(o)), 10, 64); err != nil {
return err
} else if count < 0 {
return fmt.Errorf("invalid limit %s", nstring(stmt.Limit))
}
}
if offset > int64(len(r.Values)) {
r.Values = nil
r.RowDatas = nil
return nil
}
if offset+count > int64(len(r.Values)) {
count = int64(len(r.Values)) - offset
}
r.Values = r.Values[offset : offset+count]
r.RowDatas = r.RowDatas[offset : offset+count]
return nil
}
示例4: buildResultset
func (c *ClientConn) buildResultset(fields []*mysql.Field, names []string, values [][]interface{}) (*mysql.Resultset, error) {
var ExistFields bool
r := new(mysql.Resultset)
r.Fields = make([]*mysql.Field, len(names))
//use the field def that get from true database
if len(fields) != 0 {
if len(r.Fields) == len(fields) {
ExistFields = true
} else {
return nil, errors.ErrInvalidArgument
}
}
var b []byte
var err error
for i, vs := range values {
if len(vs) != len(r.Fields) {
return nil, fmt.Errorf("row %d has %d column not equal %d", i, len(vs), len(r.Fields))
}
var row []byte
for j, value := range vs {
//列的定義
if i == 0 {
if ExistFields {
r.Fields[j] = fields[j]
} else {
field := &mysql.Field{}
r.Fields[j] = field
field.Name = hack.Slice(names[j])
if err = formatField(field, value); err != nil {
return nil, err
}
}
}
b, err = formatValue(value)
if err != nil {
return nil, err
}
row = append(row, mysql.PutLengthEncodedString(b)...)
}
r.RowDatas = append(r.RowDatas, row)
}
//assign the values to the result
r.Values = values
return r, nil
}
示例5: buildResultset
func (c *ClientConn) buildResultset(names []string, values [][]interface{}) (*mysql.Resultset, error) {
r := new(mysql.Resultset)
r.Fields = make([]*mysql.Field, len(names))
var b []byte
var err error
for i, vs := range values {
if len(vs) != len(r.Fields) {
return nil, fmt.Errorf("row %d has %d column not equal %d", i, len(vs), len(r.Fields))
}
var row []byte
for j, value := range vs {
//列的定義
if i == 0 {
field := &mysql.Field{}
r.Fields[j] = field
field.Name = hack.Slice(names[j])
if err = formatField(field, value); err != nil {
return nil, err
}
}
b, err = formatValue(value)
if err != nil {
return nil, err
}
row = append(row, mysql.PutLengthEncodedString(b)...)
}
r.RowDatas = append(r.RowDatas, row)
}
return r, nil
}