-
Notifications
You must be signed in to change notification settings - Fork 0
/
ref_cursor.go
147 lines (142 loc) · 3.05 KB
/
ref_cursor.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package go_ora_v1
import (
"github.com/illacloud/go-ora-v1/network"
)
type RefCursor struct {
defaultStmt
len uint8
MaxRowSize int
parent *defaultStmt
//ID int
//scnFromExe []int
//connection *Connection
//noOfRowsToFetch int
//hasMoreRows bool
}
func (cursor *RefCursor) load(session *network.Session) error {
// initialize ref cursor object
cursor.text = ""
cursor._hasLONG = false
cursor._hasBLOB = false
cursor._hasReturnClause = false
cursor.disableCompression = true
cursor.arrayBindCount = 1
cursor.scnFromExe = make([]int, 2)
cursor.stmtType = SELECT
var err error
cursor.len, err = session.GetByte()
if err != nil {
return err
}
cursor.MaxRowSize, err = session.GetInt(4, true, true)
if err != nil {
return err
}
columnCount, err := session.GetInt(4, true, true)
if err != nil {
return err
}
if columnCount > 0 {
cursor.columns = make([]ParameterInfo, columnCount)
_, err = session.GetByte()
if err != nil {
return err
}
for x := 0; x < len(cursor.columns); x++ {
err = cursor.columns[x].load(session)
if err != nil {
return err
}
}
//for _, col := range cursor.Cols {
// err = col.load(session)
// fmt.Println(col)
// if err != nil {
// return err
// }
//}
}
_, err = session.GetDlc()
if err != nil {
return err
}
if session.TTCVersion >= 3 {
_, err = session.GetInt(4, true, true)
if err != nil {
return err
}
_, err = session.GetInt(4, true, true)
if err != nil {
return err
}
}
if session.TTCVersion >= 4 {
_, err = session.GetInt(4, true, true)
if err != nil {
return err
}
_, err = session.GetInt(4, true, true)
if err != nil {
return err
}
}
if session.TTCVersion >= 5 {
_, err = session.GetDlc()
if err != nil {
return err
}
}
cursor.cursorID, err = session.GetInt(4, true, true)
if err != nil {
return err
}
_, err = session.GetInt(2, true, true)
if err != nil {
return err
}
return nil
}
func (cursor *RefCursor) getExeOptions() int {
return 0x8040
}
func (cursor *RefCursor) Query() (*DataSet, error) {
cursor.connection.connOption.Tracer.Printf("Query RefCursor: %d", cursor.cursorID)
cursor._noOfRowsToFetch = cursor.connection.connOption.PrefetchRows
cursor._hasMoreRows = true
if len(cursor.parent.scnFromExe) > 0 {
copy(cursor.scnFromExe, cursor.parent.scnFromExe)
}
session := cursor.connection.session
session.ResetBuffer()
err := cursor.write()
if err != nil {
return nil, err
}
dataSet := new(DataSet)
err = cursor.read(dataSet)
if err != nil {
return nil, err
}
return dataSet, nil
}
func (cursor *RefCursor) write() error {
err := cursor.basicWrite(cursor.getExeOptions(), false, false)
if err != nil {
return err
}
return cursor.connection.session.Write()
}
func (cursor *RefCursor) Close() error {
return nil
}
//func (cursor *RefCursor) Exec(args []driver.Value) (driver.Result, error) {
// return nil, nil
//}
//
//func (cursor *RefCursor) NumInput() int {
// return -1;
//}
//func (cursor *RefCursor) readQ() (*DataSet, error) {
// dataSet := new(DataSet)
// return dataSet, nil
//}