-
Notifications
You must be signed in to change notification settings - Fork 0
/
rows.go
80 lines (68 loc) · 1.78 KB
/
rows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package odbc
import (
"database/sql/driver"
"io"
"github.com/nehanio/odbc/api"
)
type Rows struct {
os *ODBCStmt
}
func (r *Rows) Columns() []string {
names := make([]string, len(r.os.Cols))
for i := 0; i < len(names); i++ {
names[i] = r.os.Cols[i].Name()
}
return names
}
func (r *Rows) Next(dest []driver.Value) error {
ret := api.SQLFetch(r.os.h)
if ret == api.SQL_NO_DATA {
return io.EOF
}
if IsError(ret) {
return NewError("SQLFetch", r.os.h)
}
for i := range dest {
v, err := r.os.Cols[i].Value(r.os.h, i)
if err != nil {
return err
}
dest[i] = v
}
return nil
}
func (r *Rows) Close() error {
return r.os.closeByRows()
}
func (r *Rows) HasNextResultSet() bool {
return true
}
func (r *Rows) NextResultSet() error {
ret := api.SQLMoreResults(r.os.h)
if ret == api.SQL_NO_DATA {
return io.EOF
}
if IsError(ret) {
return NewError("SQLMoreResults", r.os.h)
}
err := r.os.BindColumns()
if err != nil {
return err
}
return nil
}
// Implement RowsColumnTypeDatabaseTypeName interface in order to return column types.
// https://github.com/golang/go/blob/e22a14b7eb1e4a172d0c20d14a0d2433fdf20e5c/src/database/sql/driver/driver.go#L469-L477
//
// From the docs:
// RowsColumnTypeDatabaseTypeName may be implemented by Rows. It should return the
// database system type name without the length. Type names should be uppercase.
// Examples of returned types: "VARCHAR", "NVARCHAR", "VARCHAR2", "CHAR", "TEXT",
// "DECIMAL", "SMALLINT", "INT", "BIGINT", "BOOL", "[]BIGINT", "JSONB", "XML",
// "TIMESTAMP".
func (rs *Rows) ColumnTypeDatabaseTypeName(i int) string {
return rs.os.Cols[i].DatabaseTypeName()
}