-
Notifications
You must be signed in to change notification settings - Fork 0
/
j.go
191 lines (150 loc) · 4.42 KB
/
j.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
/*
* Copyright (c) 2000-2018, 达梦数据库有限公司.
* All rights reserved.
*/
package dm
type DmArray struct {
TypeData
m_arrDesc *ArrayDescriptor // 数组的描述信息
m_arrData []TypeData // 数组中各行数据值
m_objArray interface{} // 从服务端获取的
m_itemCount int // 本次获取的行数
m_itemSize int // 数组中一个数组项的大小,单位bytes
m_objCount int // 一个数组项中存在对象类型的个数(class、动态数组)
m_strCount int // 一个数组项中存在字符串类型的个数
m_objStrOffs []int // 对象在前,字符串在后
typeName string
elements []interface{}
}
func (da *DmArray) init() *DmArray {
da.initTypeData()
da.m_itemCount = 0
da.m_itemSize = 0
da.m_objCount = 0
da.m_strCount = 0
da.m_objStrOffs = nil
da.m_dumyData = nil
da.m_offset = 0
da.m_objArray = nil
return da
}
func NewDmArray(typeName string, elements []interface{}) *DmArray {
da := new(DmArray)
da.typeName = typeName
da.elements = elements
return da
}
func (da *DmArray) create(dc *Connection) (*DmArray, error) {
desc, err := newArrayDescriptor(da.typeName, dc)
if err != nil {
return nil, err
}
return da.createByArrayDescriptor(desc, dc)
}
func (da *DmArray) createByArrayDescriptor(arrDesc *ArrayDescriptor, conn *Connection) (*DmArray, error) {
if nil == arrDesc {
return nil, ECGO_INVALID_PARAMETER_VALUE.throw()
}
da.init()
da.m_arrDesc = arrDesc
if nil == da.elements {
da.m_arrData = make([]TypeData, 0)
} else {
// 若为静态数组,判断给定数组长度是否超过静态数组的上限
if arrDesc.getMDesc() == nil || (arrDesc.getMDesc().getDType() == SARRAY && len(da.elements) > arrDesc.getMDesc().getStaticArrayLength()) {
return nil, ECGO_INVALID_ARRAY_LEN.throw()
}
var err error
da.m_arrData, err = TypeDataSV.toArray(da.elements, da.m_arrDesc.getMDesc())
if err != nil {
return nil, err
}
}
da.m_itemCount = len(da.m_arrData)
return da, nil
}
func newDmArrayByTypeData(atData []TypeData, desc *TypeDescriptor) *DmArray {
da := new(DmArray)
da.init()
da.m_arrDesc = newArrayDescriptorByTypeDescriptor(desc)
da.m_arrData = atData
return da
}
func (da *DmArray) checkIndex(index int64) error {
if index < 1 || index > int64(len(da.m_arrData)) {
return ECGO_INVALID_LENGTH_OR_OFFSET.throw()
}
return nil
}
func (da *DmArray) checkIndexAndCount(index int64, count int) error {
err := da.checkIndex(index)
if err != nil {
return err
}
if count <= 0 || index-int64(1)+int64(count) > int64(len(da.m_arrData)) {
return ECGO_INVALID_LENGTH_OR_OFFSET.throw()
}
return nil
}
func (da *DmArray) GetBaseTypeName() (string, error) {
return da.m_arrDesc.m_typeDesc.getFulName()
}
func (da *DmArray) GetObjArray(index int64, count int) (interface{}, error) {
da.checkIndexAndCount(index, count)
return TypeDataSV.toJavaArray(da, index, count, da.m_arrDesc.getItemDesc().getDType())
}
func (da *DmArray) GetIntArray(index int64, count int) ([]int, error) {
da.checkIndexAndCount(index, count)
tmp, err := TypeDataSV.toNumericArray(da, index, count, ARRAY_TYPE_INTEGER)
if err != nil {
return nil, err
}
return tmp.([]int), nil
}
func (da *DmArray) GetInt16Array(index int64, count int) ([]int16, error) {
da.checkIndexAndCount(index, count)
tmp, err := TypeDataSV.toNumericArray(da, index, count, ARRAY_TYPE_SHORT)
if err != nil {
return nil, err
}
return tmp.([]int16), nil
}
func (da *DmArray) GetInt64Array(index int64, count int) ([]int64, error) {
da.checkIndexAndCount(index, count)
tmp, err := TypeDataSV.toNumericArray(da, index, count, ARRAY_TYPE_LONG)
if err != nil {
return nil, err
}
return tmp.([]int64), nil
}
func (da *DmArray) GetFloatArray(index int64, count int) ([]float32, error) {
da.checkIndexAndCount(index, count)
tmp, err := TypeDataSV.toNumericArray(da, index, count, ARRAY_TYPE_FLOAT)
if err != nil {
return nil, err
}
return tmp.([]float32), nil
}
func (da *DmArray) GetDoubleArray(index int64, count int) ([]float64, error) {
da.checkIndexAndCount(index, count)
tmp, err := TypeDataSV.toNumericArray(da, index, count, ARRAY_TYPE_DOUBLE)
if err != nil {
return nil, err
}
return tmp.([]float64), nil
}
func (dest *DmArray) Scan(src interface{}) error {
if dest == nil {
return ECGO_STORE_IN_NIL_POINTER.throw()
}
switch src := src.(type) {
case nil:
*dest = *new(DmArray)
return nil
case *DmArray:
*dest = *src
return nil
default:
return UNSUPPORTED_SCAN
}
}