-
Notifications
You must be signed in to change notification settings - Fork 2
/
assert.sql
695 lines (627 loc) · 26.8 KB
/
assert.sql
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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
-------------------------------------------------------------------------------
-- ASSERTION FRAMEWORK
-------------------------------------------------------------------------------
-- Copyright (c) 2013 Dave Hughes <dave@waveform.org.uk>
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to
-- deal in the Software without restriction, including without limitation the
-- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-- sell copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
--
-- The above copyright notice and this permission notice shall be included in
-- all copies or substantial portions of the Software.
--
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-- IN THE SOFTWARE.
-------------------------------------------------------------------------------
-- ROLES
-------------------------------------------------------------------------------
-- The following roles grant usage and administrative rights to the objects
-- created by this module.
-------------------------------------------------------------------------------
CREATE ROLE UTILS_ASSERT_USER!
CREATE ROLE UTILS_ASSERT_ADMIN!
GRANT ROLE UTILS_ASSERT_USER TO ROLE UTILS_USER!
GRANT ROLE UTILS_ASSERT_USER TO ROLE UTILS_ASSERT_ADMIN WITH ADMIN OPTION!
GRANT ROLE UTILS_ASSERT_ADMIN TO ROLE UTILS_ADMIN WITH ADMIN OPTION!
-- SQLSTATES
-------------------------------------------------------------------------------
-- The following variables define the set of SQLSTATEs raised by the procedures
-- and functions in this module.
-------------------------------------------------------------------------------
CREATE VARIABLE ASSERT_FAILED_STATE CHAR(5) CONSTANT '90001'!
GRANT READ ON VARIABLE ASSERT_FAILED_STATE TO ROLE UTILS_ASSERT_USER!
GRANT ALL ON VARIABLE ASSERT_FAILED_STATE TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON VARIABLE ASSERT_FAILED_STATE
IS 'The SQLSTATE raised by all ASSERT_* procedures and functions in the case the assertion fails'!
-- SIGNAL_STATE(STATE, MESSAGE)
-------------------------------------------------------------------------------
-- SIGNAL seems to be quite broken in DB2. It can't be called from a trigger
-- with a variable for the state at all. It can be called from a procedure with
-- a local variable for the state, but not an SQL variable, despite this being
-- explicitly described in the docs. However, wrap it in a procedure and
-- everything is suddenly fine...
-------------------------------------------------------------------------------
CREATE PROCEDURE SIGNAL_STATE(STATE CHAR(5), MESSAGE VARCHAR(70))
SPECIFIC SIGNAL_STATE1
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
BEGIN
SIGNAL SQLSTATE STATE SET MESSAGE_TEXT = MESSAGE;
END!
GRANT EXECUTE ON SPECIFIC PROCEDURE SIGNAL_STATE1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE SIGNAL_STATE1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC PROCEDURE SIGNAL_STATE1
IS 'Simply wraps SIGNAL so that it can be used in triggers, EXECUTE IMMEDIATE statements, etc.'!
-- ASSERT_SIGNALS(STATE, SQL)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if executing SQL does NOT raise SQLSTATE
-- STATE. SQL must be capable of being executed by EXECUTE IMMEDIATE, i.e. no
-- queries or SIGNAL calls. In order to permit simple testing of ASSERT_SIGNALS
-- an additional procedure is defined below which simply calls SIGNAL; EXECUTE
-- IMMEDIATE can execute a SIGNAL within a CALL, but not a SIGNAL directly...
-------------------------------------------------------------------------------
CREATE PROCEDURE ASSERT_SIGNALS(STATE CHAR(5), SQL CLOB(2M))
SPECIFIC ASSERT_SIGNALS1
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
DECLARE SQLSTATE CHAR(5);
DECLARE EXIT HANDLER FOR SQLEXCEPTION
IF SQLSTATE <> STATE THEN
CALL SIGNAL_STATE(ASSERT_FAILED_STATE,
SUBSTR(SQL, 1, 20)
|| CASE WHEN LENGTH(SQL) > 20 THEN '...' ELSE '' END
|| ' signalled SQLSTATE ' || SQLSTATE
|| ' instead of ' || STATE);
END IF;
EXECUTE IMMEDIATE SQL;
CALL SIGNAL_STATE(ASSERT_FAILED_STATE,
SUBSTR(SQL, 1, 20)
|| CASE WHEN LENGTH(SQL) > 20 THEN '...' ELSE '' END
|| ' did not signal SQLSTATE ' || STATE);
END!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_SIGNALS1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_SIGNALS1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC PROCEDURE ASSERT_SIGNALS1
IS 'Signals ASSERT_FAILED_STATE if the execution of SQL doesn''t signal SQLSTATE STATE, or signals a different SQLSTATE'!
-- ASSERT_TABLE_EXISTS(ASCHEMA, ATABLE)
-- ASSERT_TABLE_EXISTS(ATABLE)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if ASCHEMA.ATABLE does not exist, or is not a
-- table/view. If not specified, ASCHEMA defaults to the value of the CURRENT
-- SCHEMA special register. Note that the procedure doesn't check that an
-- existing table is currently marked invalid or inoperative, merely for
-- existence.
-------------------------------------------------------------------------------
CREATE PROCEDURE ASSERT_TABLE_EXISTS(ASCHEMA VARCHAR(128), ATABLE VARCHAR(128))
SPECIFIC ASSERT_TABLE_EXISTS1
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
IF (
SELECT COUNT(*)
FROM SYSCAT.TABLES
WHERE TABSCHEMA = ASCHEMA
AND TABNAME = ATABLE
) = 0 THEN
CALL SIGNAL_STATE(ASSERT_FAILED_STATE, SUBSTR(ASCHEMA || '.' || ATABLE, 1, 50)
|| CASE WHEN LENGTH(ASCHEMA) + 1 + LENGTH(ATABLE) > 50 THEN '...' ELSE '' END
|| ' does not exist');
END IF;
END!
CREATE PROCEDURE ASSERT_TABLE_EXISTS(ATABLE VARCHAR(128))
SPECIFIC ASSERT_TABLE_EXISTS2
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
CALL ASSERT_TABLE_EXISTS(CURRENT SCHEMA, ATABLE);
END!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_TABLE_EXISTS1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_TABLE_EXISTS2 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_TABLE_EXISTS1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_TABLE_EXISTS2 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC PROCEDURE ASSERT_TABLE_EXISTS1
IS 'Signals ASSERT_FAILED_STATE if the specified table does not exist'!
COMMENT ON SPECIFIC PROCEDURE ASSERT_TABLE_EXISTS2
IS 'Signals ASSERT_FAILED_STATE if the specified table does not exist'!
-- ASSERT_COLUMN_EXISTS(ASCHEMA, ATABLE, ACOLNAME)
-- ASSERT_COLUMN_EXISTS(ATABLE, ACOLNAME)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if ACOLNAME does not exist within the
-- ASCHEMA.ATABLE. If not specified, ASCHEMA defaults to the value of the
-- CURRENT SCHEMA special register.
-------------------------------------------------------------------------------
CREATE PROCEDURE ASSERT_COLUMN_EXISTS(
ASCHEMA VARCHAR(128),
ATABLE VARCHAR(128),
ACOLNAME VARCHAR(128)
)
SPECIFIC ASSERT_COLUMN_EXISTS1
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
IF (
SELECT COUNT(*)
FROM SYSCAT.COLUMNS
WHERE TABSCHEMA = ASCHEMA
AND TABNAME = ATABLE
AND COLNAME = ACOLNAME
) = 0 THEN
CALL SIGNAL_STATE(ASSERT_FAILED_STATE, SUBSTR(ACOLNAME, 1, 20)
|| CASE WHEN LENGTH(ACOLNAME) > 20 THEN '...' ELSE '' END
|| ' does not exist in '
|| SUBSTR(ASCHEMA || '.' || ATABLE, 1, 30)
|| CASE WHEN LENGTH(ASCHEMA) + 1 + LENGTH(ATABLE) > 30 THEN '...' ELSE '' END);
END IF;
END!
CREATE PROCEDURE ASSERT_COLUMN_EXISTS(ATABLE VARCHAR(128), ACOLNAME VARCHAR(128))
SPECIFIC ASSERT_COLUMN_EXISTS2
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
CALL ASSERT_COLUMN_EXISTS(CURRENT SCHEMA, ATABLE, ACOLNAME);
END!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_COLUMN_EXISTS1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_COLUMN_EXISTS2 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_COLUMN_EXISTS1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_COLUMN_EXISTS2 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC PROCEDURE ASSERT_COLUMN_EXISTS1
IS 'Signals ASSERT_FAILED_STATE if the specified column does not exist'!
COMMENT ON SPECIFIC PROCEDURE ASSERT_COLUMN_EXISTS2
IS 'Signals ASSERT_FAILED_STATE if the specified column does not exist'!
-- ASSERT_TRIGGER_EXISTS(ASCHEMA, ATRIGGER)
-- ASSERT_TRIGGER_EXISTS(ATRIGGER)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if ASCHEMA.ATRIGGER does not exist, or is not
-- a trigger. If not specified, ASCHEMA defaults to the value of the CURRENT
-- SCHEMA special register. Note that the function doesn't check whether an
-- existing trigger is currently marked inoperative, merely for existence.
-------------------------------------------------------------------------------
CREATE PROCEDURE ASSERT_TRIGGER_EXISTS(ASCHEMA VARCHAR(128), ATRIGGER VARCHAR(128))
SPECIFIC ASSERT_TRIGGER_EXISTS1
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
IF (
SELECT COUNT(*)
FROM SYSCAT.TRIGGERS
WHERE TRIGSCHEMA = ASCHEMA
AND TRIGNAME = ATRIGGER
) = 0 THEN
CALL SIGNAL_STATE(ASSERT_FAILED_STATE, SUBSTR(ASCHEMA || '.' || ATRIGGER, 1, 50)
|| CASE WHEN LENGTH(ASCHEMA) + 1 + LENGTH(ATRIGGER) > 50 THEN '...' ELSE '' END
|| ' does not exist');
END IF;
END!
CREATE PROCEDURE ASSERT_TRIGGER_EXISTS(ATRIGGER VARCHAR(128))
SPECIFIC ASSERT_TRIGGER_EXISTS2
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
CALL ASSERT_TRIGGER_EXISTS(CURRENT SCHEMA, ATRIGGER);
END!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_TRIGGER_EXISTS1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_TRIGGER_EXISTS2 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_TRIGGER_EXISTS1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_TRIGGER_EXISTS2 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC PROCEDURE ASSERT_TRIGGER_EXISTS1
IS 'Signals ASSERT_FAILED_STATE if the specified trigger does not exist'!
COMMENT ON SPECIFIC PROCEDURE ASSERT_TRIGGER_EXISTS2
IS 'Signals ASSERT_FAILED_STATE if the specified trigger does not exist'!
-- ASSERT_ROUTINE_EXISTS(ASCHEMA, AROUTINE)
-- ASSERT_ROUTINE_EXISTS(AROUTINE)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if ASCHEMA.AROUTINE does not exist, or is not
-- a routine. If not specified, ASCHEMA defaults to the value of the CURRENT
-- SCHEMA special register. Note that the function doesn't check whether an
-- existing routine is currently marked inoperative, merely for existence.
-------------------------------------------------------------------------------
CREATE PROCEDURE ASSERT_ROUTINE_EXISTS(ASCHEMA VARCHAR(128), AROUTINE VARCHAR(128))
SPECIFIC ASSERT_ROUTINE_EXISTS1
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
IF (
SELECT COUNT(*)
FROM SYSCAT.ROUTINES
WHERE ROUTINESCHEMA = ASCHEMA
AND ROUTINENAME = AROUTINE
) = 0 THEN
CALL SIGNAL_STATE(ASSERT_FAILED_STATE, SUBSTR(ASCHEMA || '.' || AROUTINE, 1, 50)
|| CASE WHEN LENGTH(ASCHEMA) + 1 + LENGTH(AROUTINE) > 50 THEN '...' ELSE '' END
|| ' does not exist');
END IF;
END!
CREATE PROCEDURE ASSERT_ROUTINE_EXISTS(AROUTINE VARCHAR(128))
SPECIFIC ASSERT_ROUTINE_EXISTS2
LANGUAGE SQL
MODIFIES SQL DATA
NOT DETERMINISTIC
NO EXTERNAL ACTION
BEGIN ATOMIC
CALL ASSERT_ROUTINE_EXISTS(CURRENT SCHEMA, AROUTINE);
END!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_ROUTINE_EXISTS1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_ROUTINE_EXISTS2 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_ROUTINE_EXISTS1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC PROCEDURE ASSERT_ROUTINE_EXISTS2 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC PROCEDURE ASSERT_ROUTINE_EXISTS1
IS 'Signals ASSERT_FAILED_STATE if the specified routine does not exist'!
COMMENT ON SPECIFIC PROCEDURE ASSERT_ROUTINE_EXISTS2
IS 'Signals ASSERT_FAILED_STATE if the specified routine does not exist'!
-- ASSERT_IS_NULL(A)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if A is not NULL. The function is overloaded
-- for most common types and generally should not need CASTs for usage.
-------------------------------------------------------------------------------
CREATE FUNCTION ASSERT_IS_NULL(A INTEGER)
RETURNS INTEGER
SPECIFIC ASSERT_IS_NULL1
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE, VARCHAR(A) || ' is non-NULL')
END!
CREATE FUNCTION ASSERT_IS_NULL(A DOUBLE)
RETURNS INTEGER
SPECIFIC ASSERT_IS_NULL2
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE, VARCHAR(A) || ' is non-NULL')
END!
CREATE FUNCTION ASSERT_IS_NULL(A TIMESTAMP)
RETURNS INTEGER
SPECIFIC ASSERT_IS_NULL3
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE, VARCHAR(A) || ' is non-NULL')
END!
CREATE FUNCTION ASSERT_IS_NULL(A TIME)
RETURNS INTEGER
SPECIFIC ASSERT_IS_NULL4
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE, VARCHAR(A) || ' is non-NULL')
END!
CREATE FUNCTION ASSERT_IS_NULL(A VARCHAR(4000))
RETURNS INTEGER
SPECIFIC ASSERT_IS_NULL5
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE,
QUOTE_STRING(SUBSTR(A, 1, 20) || CASE WHEN LENGTH(A) > 20 THEN '...' ELSE '' END) ||
' is non-NULL')
END!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL2 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL3 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL4 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL5 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL2 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL3 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL4 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NULL5 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NULL1
IS 'Signals ASSERT_FAILED_STATE if the specified value is not NULL'!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NULL2
IS 'Signals ASSERT_FAILED_STATE if the specified value is not NULL'!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NULL3
IS 'Signals ASSERT_FAILED_STATE if the specified value is not NULL'!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NULL4
IS 'Signals ASSERT_FAILED_STATE if the specified value is not NULL'!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NULL5
IS 'Signals ASSERT_FAILED_STATE if the specified value is not NULL'!
-- ASSERT_IS_NOT_NULL(A)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if A is not NULL. The function is overloaded
-- for most common types and generally should not need CASTs for usage.
-------------------------------------------------------------------------------
CREATE FUNCTION ASSERT_IS_NOT_NULL(A INTEGER)
RETURNS INTEGER
SPECIFIC ASSERT_IS_NOT_NULL1
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Value is NULL')
ELSE 0
END!
CREATE FUNCTION ASSERT_IS_NOT_NULL(A DOUBLE)
RETURNS INTEGER
SPECIFIC ASSERT_IS_NOT_NULL2
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Value is NULL')
ELSE 0
END!
CREATE FUNCTION ASSERT_IS_NOT_NULL(A TIMESTAMP)
RETURNS INTEGER
SPECIFIC ASSERT_IS_NOT_NULL3
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Value is NULL')
ELSE 0
END!
CREATE FUNCTION ASSERT_IS_NOT_NULL(A TIME)
RETURNS INTEGER
SPECIFIC ASSERT_IS_NOT_NULL4
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Value is NULL')
ELSE 0
END!
CREATE FUNCTION ASSERT_IS_NOT_NULL(A VARCHAR(4000))
RETURNS INTEGER
SPECIFIC ASSERT_IS_NOT_NULL5
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE WHEN A IS NULL
THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Value is NULL')
ELSE 0
END!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL2 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL3 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL4 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL5 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL2 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL3 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL4 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL5 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL1
IS 'Signals ASSERT_FAILED_STATE if the specified value is NULL'!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL2
IS 'Signals ASSERT_FAILED_STATE if the specified value is NULL'!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL3
IS 'Signals ASSERT_FAILED_STATE if the specified value is NULL'!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL4
IS 'Signals ASSERT_FAILED_STATE if the specified value is NULL'!
COMMENT ON SPECIFIC FUNCTION ASSERT_IS_NOT_NULL5
IS 'Signals ASSERT_FAILED_STATE if the specified value is NULL'!
-- ASSERT_EQUALS(A, B)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if A does not equal B. The function is
-- overloaded for most common types and generally should not need CASTs for
-- usage.
-------------------------------------------------------------------------------
CREATE FUNCTION ASSERT_EQUALS(A INTEGER, B INTEGER)
RETURNS INTEGER
SPECIFIC ASSERT_EQUALS1
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE, VARCHAR(A) || ' does not equal ' || VARCHAR(B))
END!
CREATE FUNCTION ASSERT_EQUALS(A DOUBLE, B DOUBLE)
RETURNS INTEGER
SPECIFIC ASSERT_EQUALS2
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE, VARCHAR(A) || ' does not equal ' || VARCHAR(B))
END!
CREATE FUNCTION ASSERT_EQUALS(A TIMESTAMP, B TIMESTAMP)
RETURNS INTEGER
SPECIFIC ASSERT_EQUALS3
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE, VARCHAR_FORMAT(A) || ' does not equal ' || VARCHAR_FORMAT(B))
END!
CREATE FUNCTION ASSERT_EQUALS(A TIME, B TIME)
RETURNS INTEGER
SPECIFIC ASSERT_EQUALS4
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE, VARCHAR(A) || ' does not equal ' || VARCHAR(B))
END!
CREATE FUNCTION ASSERT_EQUALS(A VARCHAR(4000), B VARCHAR(4000))
RETURNS INTEGER
SPECIFIC ASSERT_EQUALS5
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN 0
ELSE RAISE_ERROR(ASSERT_FAILED_STATE,
QUOTE_STRING(SUBSTR(A, 1, 20) || CASE WHEN LENGTH(A) > 20 THEN '...' ELSE '' END) ||
' does not equal ' ||
QUOTE_STRING(SUBSTR(B, 1, 20) || CASE WHEN LENGTH(B) > 20 THEN '...' ELSE '' END))
END!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS2 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS3 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS4 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS5 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS2 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS3 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS4 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_EQUALS5 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC FUNCTION ASSERT_EQUALS1
IS 'Signals ASSERT_FAILED_STATE if A does not equal B'!
COMMENT ON SPECIFIC FUNCTION ASSERT_EQUALS2
IS 'Signals ASSERT_FAILED_STATE if A does not equal B'!
COMMENT ON SPECIFIC FUNCTION ASSERT_EQUALS3
IS 'Signals ASSERT_FAILED_STATE if A does not equal B'!
COMMENT ON SPECIFIC FUNCTION ASSERT_EQUALS4
IS 'Signals ASSERT_FAILED_STATE if A does not equal B'!
COMMENT ON SPECIFIC FUNCTION ASSERT_EQUALS5
IS 'Signals ASSERT_FAILED_STATE if A does not equal B'!
-- ASSERT_NOT_EQUALS(A, B)
-------------------------------------------------------------------------------
-- Raises the ASSERT_FAILED_STATE if A does equal B. The function is overloaded
-- for most common types and generally should not need CASTs for usage.
-------------------------------------------------------------------------------
CREATE FUNCTION ASSERT_NOT_EQUALS(A INTEGER, B INTEGER)
RETURNS INTEGER
SPECIFIC ASSERT_NOT_EQUALS1
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Values are both ' || VARCHAR(A))
ELSE 0
END!
CREATE FUNCTION ASSERT_NOT_EQUALS(A DOUBLE, B DOUBLE)
RETURNS INTEGER
SPECIFIC ASSERT_NOT_EQUALS2
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Values are both ' || VARCHAR(A))
ELSE 0
END!
CREATE FUNCTION ASSERT_NOT_EQUALS(A TIMESTAMP, B TIMESTAMP)
RETURNS INTEGER
SPECIFIC ASSERT_NOT_EQUALS3
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Values are both ' || VARCHAR_FORMAT(A))
ELSE 0
END!
CREATE FUNCTION ASSERT_NOT_EQUALS(A TIME, B TIME)
RETURNS INTEGER
SPECIFIC ASSERT_NOT_EQUALS4
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN RAISE_ERROR(ASSERT_FAILED_STATE, 'Values are both ' || VARCHAR(A))
ELSE 0
END!
CREATE FUNCTION ASSERT_NOT_EQUALS(A VARCHAR(4000), B VARCHAR(4000))
RETURNS INTEGER
SPECIFIC ASSERT_NOT_EQUALS5
LANGUAGE SQL
CONTAINS SQL
DETERMINISTIC
NO EXTERNAL ACTION
RETURN
CASE A
WHEN B THEN RAISE_ERROR(ASSERT_FAILED_STATE,
'Values are both '
|| QUOTE_STRING(SUBSTR(A, 1, 40)
|| CASE WHEN LENGTH(A) > 40 THEN '...' ELSE '' END))
ELSE 0
END!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS1 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS2 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS3 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS4 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS5 TO ROLE UTILS_ASSERT_USER!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS1 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS2 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS3 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS4 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
GRANT EXECUTE ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS5 TO ROLE UTILS_ASSERT_ADMIN WITH GRANT OPTION!
COMMENT ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS1
IS 'Signals ASSERT_FAILED_STATE if A equals B'!
COMMENT ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS2
IS 'Signals ASSERT_FAILED_STATE if A equals B'!
COMMENT ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS3
IS 'Signals ASSERT_FAILED_STATE if A equals B'!
COMMENT ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS4
IS 'Signals ASSERT_FAILED_STATE if A equals B'!
COMMENT ON SPECIFIC FUNCTION ASSERT_NOT_EQUALS5
IS 'Signals ASSERT_FAILED_STATE if A equals B'!
-- vim: set et sw=4 sts=4: