-
Notifications
You must be signed in to change notification settings - Fork 0
/
zb.go
307 lines (199 loc) · 5.13 KB
/
zb.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
package dm
const (
PARAM_COUNT_LIMIT int32 = 65536
IGNORE_TARGET_LENGTH int32 = -1
IGNORE_TARGET_SCALE int32 = -1
IGNORE_TARGET_TYPE = INT32_MIN
TYPE_FLAG_UNKNOWN byte = 0 // 未知类型
TYPE_FLAG_EXACT byte = 1 // 精确类型
TYPE_FLAG_RECOMMEND byte = 2 // 推荐类型
IO_TYPE_UNKNOWN int8 = -1
IO_TYPE_IN int8 = 0
IO_TYPE_OUT int8 = 1
IO_TYPE_INOUT int8 = 2
MASK_ORACLE_DATE int32 = 1
MASK_ORACLE_FLOAT int32 = 2
MASK_BFILE int32 = 3
MASK_LOCAL_DATETIME int32 = 4
)
type execRetInfo struct {
// param
outParamDatas [][]byte
// rs
hasResultSet bool
rsDatas [][][]byte
rsSizeof int // 结果集数据占用多少空间,(消息中结果集起始位置到 rsCacheOffset
// 的空间大小,这和实际的rsDatas占用空间大小有一定出入,这里粗略估算,用于结果集缓存时的空间管理)
rsCacheOffset int32 // 缓存信息,在响应消息体中的偏移,0表示不存在,仅结果集缓存中可以用
rsBdta bool
rsUpdatable bool
rsRowIds []int64
// rs cache
tbIds []int32
tbTss []int64
// print
printLen int32
printMsg string
// explain
explain string
// 影响行数
updateCount int64 // Insert/Update/Delet影响行数, select结果集的总行数
updateCounts []int64 // 批量影响行数
// 键
rowid int64
lastInsertId int64
// other
retSqlType int16 // 执行返回的语句类型
execId int32
}
type column struct {
typeName string
colType int32
prec int32
scale int32
name string
tableName string
schemaName string
nullable bool
identity bool
readonly bool // 是否只读
baseName string
// lob info
lob bool
lobTabId int32
lobColId int16
// 用于描述ARRAY、STRUCT类型的特有描述信息
typeDescriptor *TypeDescriptor
isBdta bool
mask int32
}
type parameter struct {
column
typeFlag byte
ioType int8
outJType int32
outScale int32
outObjectName string
cursorStmt *DmStatement
hasDefault bool
}
func (column *column) InitColumn() *column {
column.typeName = ""
column.colType = 0
column.prec = 0
column.scale = 0
column.name = ""
column.tableName = ""
column.schemaName = ""
column.nullable = false
column.identity = false
column.readonly = false
column.baseName = ""
// lob info
column.lob = false
column.lobTabId = 0
column.lobColId = 0
// 用于描述ARRAY、STRUCT类型的特有描述信息
column.typeDescriptor = nil
column.isBdta = false
return column
}
func (parameter *parameter) InitParameter() *parameter {
parameter.InitColumn()
parameter.typeFlag = TYPE_FLAG_UNKNOWN
parameter.ioType = IO_TYPE_UNKNOWN
parameter.outJType = IGNORE_TARGET_TYPE
parameter.outScale = IGNORE_TARGET_SCALE
parameter.outObjectName = ""
parameter.cursorStmt = nil
return parameter
}
func (parameter *parameter) resetType(colType int32) {
parameter.colType = colType
parameter.scale = 0
switch colType {
case BIT, BOOLEAN:
parameter.prec = BIT_PREC
case TINYINT:
parameter.prec = TINYINT_PREC
case SMALLINT:
parameter.prec = SMALLINT_PREC
case INT:
parameter.prec = INT_PREC
case BIGINT:
parameter.prec = BIGINT_PREC
case CHAR, VARCHAR, VARCHAR2:
parameter.prec = VARCHAR_PREC
case CLOB:
parameter.prec = CLOB_PREC
case BINARY, VARBINARY:
parameter.prec = VARBINARY_PREC
case BLOB:
parameter.prec = BLOB_PREC
case DATE:
parameter.prec = DATE_PREC
case TIME:
parameter.prec = TIME_PREC
parameter.scale = 6
case TIME_TZ:
parameter.prec = TIME_TZ_PREC
parameter.scale = 6
case DATETIME:
parameter.prec = DATETIME_PREC
parameter.scale = 6
case DATETIME_TZ:
parameter.prec = DATETIME_TZ_PREC
parameter.scale = 6
case DATETIME2:
parameter.prec = DATETIME2_PREC
parameter.scale = 9
case DATETIME2_TZ:
parameter.prec = DATETIME2_TZ_PREC
parameter.scale = 9
case REAL,DOUBLE,DECIMAL,INTERVAL_YM,INTERVAL_DT,ARRAY,CLASS,PLTYPE_RECORD,SARRAY:
parameter.prec = 0
case UNKNOWN, NULL:
// UNKNOWN 导致服务器断言 // setNull导致服务器报错“字符转换失败”
parameter.colType = VARCHAR
parameter.prec = VARCHAR_PREC
default:
}
}
func (execInfo *execRetInfo) union(other *execRetInfo, startRow int, count int) {
if count == 1 {
execInfo.updateCounts[startRow] = other.updateCount
} else if execInfo.updateCounts != nil {
copy(execInfo.updateCounts[startRow:startRow+count], other.updateCounts[0:count])
}
if execInfo.outParamDatas != nil {
execInfo.outParamDatas = append(execInfo.outParamDatas, other.outParamDatas...)
}
}
func NewExceInfo() *execRetInfo {
execInfo := execRetInfo{}
execInfo.outParamDatas = nil
execInfo.hasResultSet = false
execInfo.rsDatas = nil
execInfo.rsSizeof = 0
execInfo.rsCacheOffset = 0
execInfo.rsBdta = false
execInfo.rsUpdatable = false
execInfo.rsRowIds = nil
execInfo.tbIds = nil
execInfo.tbTss = nil
execInfo.printLen = 0
execInfo.printMsg = ""
execInfo.explain = ""
execInfo.updateCount = 0
execInfo.updateCounts = nil
execInfo.rowid = -1
execInfo.lastInsertId = 0
// other
execInfo.retSqlType = -1 // 执行返回的语句类型
execInfo.execId = 0
return &execInfo
}