-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathint8.go
More file actions
69 lines (59 loc) · 1.32 KB
/
Copy pathint8.go
File metadata and controls
69 lines (59 loc) · 1.32 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"
"reflect"
"unsafe"
"github.com/ninthclowd/unixodbc/internal/api"
)
func init() {
registerColumnFactoryForType(newInt8Column, api.SQL_TINYINT)
}
func newInt8Column(info *columnInfo, hnd *handle) Column {
return &columnInt8{hnd, info}
}
type columnInt8 struct {
*handle
*columnInfo
}
func (c *columnInt8) VariableLength() (length int64, ok bool) {
return
}
func (c *columnInt8) ScanType() reflect.Type {
return reflect.TypeOf((*int8)(nil))
}
func (c *columnInt8) Decimal() (precision int64, scale int64, ok bool) {
return
}
func (c *columnInt8) Value() (driver.Value, error) {
var value api.SQLSCHAR
var valueLength api.SQLLEN
if _, err := c.result(api.SQLGetData((*api.SQLHSTMT)(c.hnd()),
c.columnNumber,
api.SQL_C_STINYINT,
(*api.SQLPOINTER)(unsafe.Pointer(&value)),
0,
&valueLength)); err != nil {
return nil, err
}
if valueLength == api.SQL_NULL_DATA {
return nil, nil
}
return int8(value), nil
}
func (s *statement) bindInt8(index int, value int8) (free func(), err error) {
ptr, free, err := api.MallocScalar(value)
if err != nil {
return
}
_, err = s.result(api.SQLBindParameter((*api.SQLHSTMT)(s.hnd()),
api.SQLUSMALLINT(index+1),
api.SQL_PARAM_INPUT,
api.SQL_C_STINYINT,
api.SQL_TINYINT,
0,
0,
(*api.SQLPOINTER)(ptr),
0,
nil))
return
}