@@ -121,18 +121,21 @@ describe('execute', () => {
121
121
const mockResponse = {
122
122
session : mockSession ,
123
123
result : {
124
- fields : [ { name : ':vtg1' , type : 'INT32' } ] ,
125
- rows : [ { lengths : [ '1' ] , values : 'MQ==' } ]
124
+ fields : [ { name : ':vtg1' , type : 'INT32' } , { name : 'null' } ] ,
125
+ rows : [ { lengths : [ '1' , '-1' ] , values : 'MQ==' } ]
126
126
}
127
127
}
128
128
129
129
const want : ExecutedQuery = {
130
- headers : [ ':vtg1' ] ,
131
- types : { ':vtg1' : 'INT32' } ,
132
- fields : [ { name : ':vtg1' , type : 'INT32' } ] ,
133
- rows : [ { ':vtg1' : 1 } ] ,
130
+ headers : [ ':vtg1' , 'null' ] ,
131
+ types : { ':vtg1' : 'INT32' , null : 'NULL' } ,
132
+ fields : [
133
+ { name : ':vtg1' , type : 'INT32' } ,
134
+ { name : 'null' , type : 'NULL' }
135
+ ] ,
136
+ rows : [ { ':vtg1' : 1 , null : null } ] ,
134
137
size : 1 ,
135
- statement : 'SELECT 1 from dual;' ,
138
+ statement : 'SELECT 1, null from dual;' ,
136
139
time : 1 ,
137
140
rowsAffected : null ,
138
141
insertId : null
@@ -146,7 +149,54 @@ describe('execute', () => {
146
149
} )
147
150
148
151
const connection = connect ( config )
149
- const got = await connection . execute ( 'SELECT 1 from dual;' )
152
+ const got = await connection . execute ( 'SELECT 1, null from dual;' )
153
+ got . time = 1
154
+
155
+ expect ( got ) . toEqual ( want )
156
+
157
+ mockPool . intercept ( { path : EXECUTE_PATH , method : 'POST' } ) . reply ( 200 , ( opts ) => {
158
+ expect ( opts . headers [ 'authorization' ] ) . toMatch ( / B a s i c / )
159
+ const bodyObj = JSON . parse ( opts . body . toString ( ) )
160
+ expect ( bodyObj . session ) . toEqual ( mockSession )
161
+ return mockResponse
162
+ } )
163
+
164
+ const got2 = await connection . execute ( 'SELECT 1, null from dual;' )
165
+ got2 . time = 1
166
+
167
+ expect ( got2 ) . toEqual ( want )
168
+ } )
169
+
170
+ test ( 'it properly returns and decodes a select query (select null)' , async ( ) => {
171
+ const mockResponse = {
172
+ session : mockSession ,
173
+ result : {
174
+ fields : [ { name : 'null' } ] ,
175
+ rows : [ { lengths : [ '-1' ] } ]
176
+ }
177
+ }
178
+
179
+ const want : ExecutedQuery = {
180
+ headers : [ 'null' ] ,
181
+ types : { null : 'NULL' } ,
182
+ fields : [ { name : 'null' , type : 'NULL' } ] ,
183
+ rows : [ { null : null } ] ,
184
+ size : 1 ,
185
+ statement : 'SELECT null' ,
186
+ time : 1 ,
187
+ rowsAffected : null ,
188
+ insertId : null
189
+ }
190
+
191
+ mockPool . intercept ( { path : EXECUTE_PATH , method : 'POST' } ) . reply ( 200 , ( opts ) => {
192
+ expect ( opts . headers [ 'authorization' ] ) . toMatch ( / B a s i c / )
193
+ const bodyObj = JSON . parse ( opts . body . toString ( ) )
194
+ expect ( bodyObj . session ) . toEqual ( null )
195
+ return mockResponse
196
+ } )
197
+
198
+ const connection = connect ( config )
199
+ const got = await connection . execute ( 'SELECT null' )
150
200
got . time = 1
151
201
152
202
expect ( got ) . toEqual ( want )
@@ -158,7 +208,7 @@ describe('execute', () => {
158
208
return mockResponse
159
209
} )
160
210
161
- const got2 = await connection . execute ( 'SELECT 1 from dual; ' )
211
+ const got2 = await connection . execute ( 'SELECT null ' )
162
212
got2 . time = 1
163
213
164
214
expect ( got2 ) . toEqual ( want )
0 commit comments