/
JSONSQL30A.SQL-Call-stored-procedure.rpgle
executable file
·373 lines (310 loc) · 10.7 KB
/
JSONSQL30A.SQL-Call-stored-procedure.rpgle
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
**FREE
// ------------------------------------------------------------- *
// noxDB - Not only XML. JSON, SQL and XML made easy for RPG
// Company . . . : System & Method A/S - Sitemule
// Design . . . : Niels Liisberg
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// Look at the header source file "QRPGLEREF" member "NOXDB"
// for a complete description of the functionality
// When using noxDB you need two things:
// A: Bind you program with "NOXDB" Bind directory
// B: Include the noxDB prototypes from QRPGLEREF member NOXDB
// ------------------------------------------------------------- *
// ------------------------------------------------------------- *
Ctl-Opt BndDir('NOXDB') dftactgrp(*NO) ACTGRP('QILE') ;
/include qrpgleRef,noxdb
Dcl-S err Ind;
Dcl-S pIn Pointer;
Dcl-S pOut Pointer;
Dcl-s msg char(50);
Dcl-s i int(10);
// Call stored procedures
add();
inc();
commonTypes();
commonTypesNegative();
commonTypesNull();
performance();
// That's it..
*inlr = *on;
// ------------------------------------------------------------------------------------
// Use case of in, in and out parameter
// Create the procedure from ACS. Maybe change the schema location
//
// create or replace procedure noxdbdemo.add (
// in a int,
// in b int,
// out c dec(5,2)
// )
// begin
// set c = (a + b) / 100.0;
// end;
// call add (a=>123, b=>456 , c=>?);
// ------------------------------------------------------------------------------------
dcl-proc add;
// Build input parameter object
pIn = json_newObject();
json_SetInt(pIn: 'a': 123);
json_SetInt(pIn: 'b': 456);
// Call the procedure
pOut = json_sqlCall ('noxdbdemo.add' : pIn);
If json_Error(pOut) ;
msg = json_Message(pOut);
dsply msg;
EndIf;
// Dump the result
json_joblog(pOut);
json_delete(pIn);
json_delete(pOut);
end-proc;
// ------------------------------------------------------------------------------------
// inc - inout parameter usecase
//
// Create the procedure from ACS. Maybe change the schema location
//
// create or replace procedure noxdbdemo.inc (
// inout a int
// )
// begin
// set a = a + 1;
// end;
// call inc (a=>123);
// ------------------------------------------------------------------------------------
dcl-proc inc;
// Build input parameter object
pIn = json_newObject();
json_SetInt(pIn: 'a': 123);
// Call the procedure
pOut = json_sqlCall ('noxdbdemo.inc' : pIn);
If json_Error(pOut) ;
msg = json_Message(pOut);
dsply msg;
EndIf;
// Dump the result
json_joblog(pOut);
json_delete(pIn);
json_delete(pOut);
end-proc;
// ------------------------------------------------------------------------------------
// commonTypes
// ------------------------------------------------------------------------------------
// Using all supported types by noxDB -
// Notice: CLOB, BLOB and GRAPHIC is not supported yet in call to stored procedure in noxDB
//
// Create the procedure from ACS. Maybe change the schema location
//
// drop procedure noxdbdemo.common_types;
// create or replace procedure noxdbdemo.common_types (
// in ismallint smallint default null,
// in iinteger integer default null,
// in ibigint bigint default null,
// in idecimal decimal (30, 10) default null,
// in inumeric numeric (30, 10) default null,
// in ifloat float default null,
// in ireal real default null,
// in idouble double default null,
// in ichar char (256) default null,
// in ivarchar varchar (256) default null,
// in idate date default null,
// in itime time default null,
// in itimestamp timestamp default null,
// out osmallint smallint,
// out ointeger integer ,
// out obigint bigint ,
// out odecimal decimal (30, 10) ,
// out onumeric numeric (30, 10) ,
// out ofloat float ,
// out oreal real ,
// out odouble double ,
// out ochar char (256) ,
// out ovarchar varchar (256) ,
// out odate date ,
// out otime time ,
// out otimestamp timestamp ,
// inout iosmallint smallint default null,
// inout iointeger integer default null,
// inout iobigint bigint default null,
// inout iodecimal decimal (30, 10) default null,
// inout ionumeric numeric (30, 10) default null,
// inout iofloat float default null,
// inout ioreal real default null,
// inout iodouble double default null,
// inout iochar char (256) default null,
// inout iovarchar varchar (256) default null,
// inout iodate date default null,
// inout iotime time default null,
// inout iotimestamp timestamp default null
// )
// set option output=*print, commit=*none, dbgview = *list
// begin
// set iinteger = ismallint;
// set ibigint = ismallint;
// set idecimal = ismallint;
// set inumeric = ismallint;
// set ifloat = ismallint;
// set ireal = ismallint;
// set idouble = ismallint;
// set ichar = ismallint;
// set ivarchar = ismallint;
// set idate = now();
// set itime = now();
// set itimestamp = now();
// set osmallint = ismallint;
// set ointeger = ismallint;
// set obigint = ismallint;
// set odecimal = ismallint;
// set onumeric = ismallint;
// set ofloat = ismallint;
// set oreal = ismallint;
// set odouble = ismallint;
// set ochar = ismallint;
// set ovarchar = ismallint;
// set odate = now();
// set otime = now();
// set otimestamp = now();
// set iosmallint = ismallint;
// set iointeger = ismallint;
// set iobigint = ismallint;
// set iodecimal = ismallint;
// set ionumeric = ismallint;
// set iofloat = ismallint;
// set ioreal = ismallint;
// set iodouble = ismallint;
// set iochar = ismallint;
// set iovarchar = ismallint;
// set iodate = now();
// set iotime = now();
// set iotimestamp = now();
// end;
// call noxdbdemo.common_types (
// ismallint => 123,
// osmallint =>?,
// ointeger =>?,
// obigint =>?,
// odecimal =>?,
// onumeric =>?,
// ofloat =>?,
// oreal =>?,
// odouble =>?,
// ochar =>?,
// ovarchar =>?,
// odate =>?,
// otime =>?,
// otimestamp =>?
// );
// ------------------------------------------------------------------------------------
dcl-proc commonTypes;
// Build input parameter object
pIn = json_newObject();
json_SetInt(pIn: 'ismallint' : 1);
json_SetInt(pIn: 'iinteger' : 1);
json_SetInt(pIn: 'ibigint' : 1);
json_SetInt(pIn: 'idecimal' : 1);
json_SetInt(pIn: 'inumeric' : 1);
json_SetInt(pIn: 'ifloat' : 1);
json_SetInt(pIn: 'ireal' : 1);
json_SetInt(pIn: 'idouble' : 1);
json_SetInt(pIn: 'ichar' : 1);
json_SetInt(pIn: 'ivarchar' : 1);
json_SetStr(pIn: 'idate' : %char(%date()));
json_SetStr(pIn: 'itime' : %char(%time()));
json_SetStr(pIn: 'itimestamp' : %char(%timestamp()));
json_SetInt(pIn: 'iosmallint' : 1);
json_SetInt(pIn: 'iointeger' : 1);
json_SetInt(pIn: 'iobigint' : 1);
json_SetInt(pIn: 'iodecimal' : 1);
json_SetInt(pIn: 'ionumeric' : 1);
json_SetInt(pIn: 'iofloat' : 1);
json_SetInt(pIn: 'ioreal' : 1);
json_SetInt(pIn: 'iodouble' : 1);
json_SetInt(pIn: 'iochar' : 1);
json_SetInt(pIn: 'iovarchar' : 1);
json_SetStr(pIn: 'iodate' : %char(%date()));
json_SetStr(pIn: 'iotime' : %char(%time()));
json_SetStr(pIn: 'iotimestamp' : %char(%timestamp()));
// Call the procedure
pOut = json_sqlCall ('noxdbdemo.common_types' : pIn);
If json_Error(pOut) ;
msg = json_Message(pOut);
dsply msg;
EndIf;
// Dump the result
json_joblog(pOut);
json_WriteJsonStmf(pOut:'/prj/noxdb/testout/procparms.json':1208:*OFF);
json_delete(pIn);
json_delete(pOut);
end-proc;
dcl-proc commonTypesNegative;
// Build input parameter object
pIn = json_newObject();
json_SetInt(pIn: 'ismallint' : -1);
// Call the procedure
pOut = json_sqlCall ('noxdbdemo.common_types' : pIn);
If json_Error(pOut) ;
msg = json_Message(pOut);
dsply msg;
EndIf;
// Dump the result
json_joblog(pOut);
json_WriteJsonStmf(pOut:'/prj/noxdb/testout/procparms.json':1208:*OFF);
json_delete(pIn);
json_delete(pOut);
end-proc;
dcl-proc commonTypesNull;
// Build input parameter object
pIn = json_newObject();
json_SetNull(pIn: 'ismallint' );
// Call the procedure
pOut = json_sqlCall ('noxdbdemo.common_types' : pIn);
If json_Error(pOut) ;
msg = json_Message(pOut);
dsply msg;
EndIf;
// Dump the result
json_joblog(pOut);
json_WriteJsonStmf(pOut:'/prj/noxdb/testout/procparms.json':1208:*OFF);
json_delete(pIn);
json_delete(pOut);
end-proc;
// ------------------------------------------------------------------------------------
// performance - inout parameter usecase
//
// Create the procedure from ACS. Maybe change the schema location
//
// create or replace procedure noxdbdemo.inc (
// inout a int
// )
// begin
// set a = a + 1;
// end;
// call inc (a=>123);
// ------------------------------------------------------------------------------------
dcl-proc performance;
dcl-s i int(10);
dcl-s iterations int(10);
dcl-s elapsed int(20);
dcl-s before timestamp;
// Build input parameter object
pIn = json_newObject();
json_SetInt(pIn: 'a': 1);
// Call the procedure a numer of times
before = %timestamp();
iterations = 1000;
for i = 1 to iterations;
pOut = json_sqlCall ('noxdbdemo.inc' : pIn);
If json_Error(pOut) ;
msg = json_Message(pOut);
dsply msg;
leave;
EndIf;
// json_joblog(pOut);
json_copyvalue (pIn : 'a' : pOut : 'a');
// Always delte the output object, it will produce a new in next iteration
json_delete(pOut);
endfor;
elapsed = %diff (%timestamp() : before : *MSECONDS );
json_joblog(%char (iterations) + ' iteratinons in ' + %char(elapsed / 1000.0) + ' milliseconds');
json_delete(pIn);
end-proc;