github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/database/mysql/rows.go (about) 1 // Go MySQL Driver - A MySQL-Driver for Go's database/sql package 2 // 3 // Copyright 2012 The Go-MySQL-Driver Authors. All rights reserved. 4 // 5 // This Source Code Form is subject to the terms of the Mozilla Public 6 // License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 // You can obtain one at http://mozilla.org/MPL/2.0/. 8 9 package mysql 10 11 import ( 12 "database/sql/driver" 13 "io" 14 ) 15 16 type mysqlField struct { 17 fieldType byte 18 flags fieldFlag 19 name string 20 } 21 22 type mysqlRows struct { 23 mc *mysqlConn 24 columns []mysqlField 25 } 26 27 type binaryRows struct { 28 mysqlRows 29 } 30 31 type textRows struct { 32 mysqlRows 33 } 34 35 func (rows *mysqlRows) Columns() []string { 36 columns := make([]string, len(rows.columns)) 37 for i := range columns { 38 columns[i] = rows.columns[i].name 39 } 40 return columns 41 } 42 43 func (rows *mysqlRows) Close() error { 44 mc := rows.mc 45 if mc == nil { 46 return nil 47 } 48 if mc.netConn == nil { 49 return ErrInvalidConn 50 } 51 52 // Remove unread packets from stream 53 err := mc.readUntilEOF() 54 rows.mc = nil 55 return err 56 } 57 58 func (rows *binaryRows) Next(dest []driver.Value) error { 59 if mc := rows.mc; mc != nil { 60 if mc.netConn == nil { 61 return ErrInvalidConn 62 } 63 64 // Fetch next row from stream 65 if err := rows.readRow(dest); err != io.EOF { 66 return err 67 } 68 rows.mc = nil 69 } 70 return io.EOF 71 } 72 73 func (rows *textRows) Next(dest []driver.Value) error { 74 if mc := rows.mc; mc != nil { 75 if mc.netConn == nil { 76 return ErrInvalidConn 77 } 78 79 // Fetch next row from stream 80 if err := rows.readRow(dest); err != io.EOF { 81 return err 82 } 83 rows.mc = nil 84 } 85 return io.EOF 86 }