| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
- //
- // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved.
- //
- // 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/.
- package mysql
- import (
- "database/sql/driver"
- "io"
- )
- type mysqlField struct {
- name string
- length uint32 // length as string: DATETIME(4) => 24
- flags fieldFlag
- fieldType byte
- decimals byte // numeric precision: DATETIME(4) => 4, also for DECIMAL etc.
- }
- type mysqlRows struct {
- mc *mysqlConn
- columns []mysqlField
- }
- type binaryRows struct {
- mysqlRows
- }
- type textRows struct {
- mysqlRows
- }
- func (rows *mysqlRows) Columns() []string {
- columns := make([]string, len(rows.columns))
- for i := range columns {
- columns[i] = rows.columns[i].name
- }
- return columns
- }
- func (rows *mysqlRows) Close() error {
- mc := rows.mc
- if mc == nil {
- return nil
- }
- if mc.netConn == nil {
- return ErrInvalidConn
- }
- // Remove unread packets from stream
- err := mc.readUntilEOF()
- rows.mc = nil
- return err
- }
- func (rows *binaryRows) Next(dest []driver.Value) error {
- if mc := rows.mc; mc != nil {
- if mc.netConn == nil {
- return ErrInvalidConn
- }
- // Fetch next row from stream
- if err := rows.readRow(dest); err != io.EOF {
- return err
- }
- rows.mc = nil
- }
- return io.EOF
- }
- func (rows *textRows) Next(dest []driver.Value) error {
- if mc := rows.mc; mc != nil {
- if mc.netConn == nil {
- return ErrInvalidConn
- }
- // Fetch next row from stream
- if err := rows.readRow(dest); err != io.EOF {
- return err
- }
- rows.mc = nil
- }
- return io.EOF
- }
|