/
time.go
48 lines (40 loc) · 1.05 KB
/
time.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
package odbc
import (
"database/sql/driver"
"github.com/ninthclowd/unixodbc/internal/api"
"reflect"
"time"
)
func init() {
registerColumnFactoryForType(newTimeColumn,
api.SQL_TYPE_TIME,
-154, //mssql time type
)
}
func newTimeColumn(info *columnInfo, hnd handle) Column {
return &columnTime{hnd, info}
}
type columnTime struct {
handle
*columnInfo
}
func (c *columnTime) VariableLength() (length int64, ok bool) {
return
}
func (c *columnTime) ScanType() reflect.Type {
return reflect.TypeOf((*time.Time)(nil))
}
func (c *columnTime) Decimal() (precision int64, scale int64, ok bool) {
return
}
func (c *columnTime) Value() (driver.Value, error) {
var value api.SQL_TIME_STRUCT
var valueLength api.SQLLEN
if _, err := c.result(c.api().SQLGetData(api.SQLHSTMT(c.hnd()), c.columnNumber, api.SQL_C_TIME, api.SQLPOINTER(&value), 0, &valueLength)); err != nil {
return nil, err
}
if valueLength == api.SQL_NULL_DATA {
return nil, nil
}
return time.Date(1, time.January, 1, int(value.Hour), int(value.Minute), int(value.Second), 0, time.UTC), nil
}