rows.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
  2. //
  3. // Copyright 2012 Julien Schmidt. All rights reserved.
  4. // http://www.julienschmidt.com
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla Public
  7. // License, v. 2.0. If a copy of the MPL was not distributed with this file,
  8. // You can obtain one at http://mozilla.org/MPL/2.0/.
  9. package mysql
  10. import (
  11. "database/sql/driver"
  12. "io"
  13. )
  14. type mysqlField struct {
  15. name string
  16. fieldType FieldType
  17. flags FieldFlag
  18. }
  19. type rowsContent struct {
  20. columns []mysqlField
  21. rows []*[][]byte
  22. }
  23. type mysqlRows struct {
  24. content *rowsContent
  25. }
  26. func (rows mysqlRows) Columns() (columns []string) {
  27. columns = make([]string, len(rows.content.columns))
  28. for i := 0; i < cap(columns); i++ {
  29. columns[i] = rows.content.columns[i].name
  30. }
  31. return
  32. }
  33. func (rows mysqlRows) Close() error {
  34. rows.content = nil
  35. return nil
  36. }
  37. // Next returns []driver.Value filled with either nil values for NULL entries
  38. // or []byte's for all other entries. Type conversion is done on rows.scan(),
  39. // when the dest. type is know, which makes type conversion easier and avoids
  40. // unnecessary conversions.
  41. func (rows mysqlRows) Next(dest []driver.Value) error {
  42. if len(rows.content.rows) > 0 {
  43. for i := 0; i < cap(dest); i++ {
  44. dest[i] = (*rows.content.rows[0])[i]
  45. }
  46. rows.content.rows = rows.content.rows[1:]
  47. } else {
  48. return io.EOF
  49. }
  50. return nil
  51. }