-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfloat64.go
More file actions
69 lines (60 loc) · 1.39 KB
/
float64.go
File metadata and controls
69 lines (60 loc) · 1.39 KB
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
package odbc
import (
"database/sql/driver"
"github.com/ninthclowd/unixodbc/internal/api"
"reflect"
"unsafe"
)
func init() {
registerColumnFactoryForType(newFloat64Column,
api.SQL_DOUBLE,
api.SQL_FLOAT,
api.SQL_DECIMAL,
api.SQL_NUMERIC,
)
}
func newFloat64Column(info *columnInfo, hnd *handle) Column {
return &columnFloat64{hnd, info}
}
type columnFloat64 struct {
*handle
*columnInfo
}
func (c *columnFloat64) VariableLength() (length int64, ok bool) {
return
}
func (c *columnFloat64) ScanType() reflect.Type {
return reflect.TypeOf((*float64)(nil))
}
func (c *columnFloat64) Decimal() (precision int64, scale int64, ok bool) {
return int64(c.columnSize), int64(c.decimalDigits), true
}
func (c *columnFloat64) Value() (driver.Value, error) {
var value api.SQLDOUBLE
var valueLength api.SQLLEN
if _, err := c.result(api.SQLGetData((*api.SQLHSTMT)(c.hnd()),
c.columnNumber,
api.SQL_C_DOUBLE,
(*api.SQLPOINTER)(unsafe.Pointer(&value)),
0,
&valueLength)); err != nil {
return nil, err
}
if valueLength == api.SQL_NULL_DATA {
return nil, nil
}
return float64(value), nil
}
func (s *statement) bindFloat64(index int, value float64) error {
_, err := s.result(api.SQLBindParameter((*api.SQLHSTMT)(s.hnd()),
api.SQLUSMALLINT(index+1),
api.SQL_PARAM_INPUT,
api.SQL_C_DOUBLE,
api.SQL_DOUBLE,
0,
0,
(*api.SQLPOINTER)(unsafe.Pointer(&value)),
0,
nil))
return err
}