func (sei *session) limitSelectResult(r *mysql.Resultset, count, offset int64) { // rewrite count, remove bad index range 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] }
func (sei *session) 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, mysql.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 { // column define if i == 0 { if ExistFields { r.Fields[j] = fields[j] } else { field := &mysql.Field{} r.Fields[j] = field field.Name = []byte(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 }