Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
#include <ctime>
#include <cstring>
#include <iomanip>
#include <limits>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
 
#include "owa_util.hpp"
#include "dbms/htp.h"
 
extern "C"
{
#include "utils/builtins.h"
#include "utils/elog.h"
#include "utils/lsyscache.h"
#include "executor/executor.h"
}
 
#include "dbms/htp.h"
 
extern "C"
{
 
PG_FUNCTION_INFO_V1(owa_util_bind_variables);
PG_FUNCTION_INFO_V1(owa_util_calendarprint_ovr1);
PG_FUNCTION_INFO_V1(owa_util_calendarprint_ovr2);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr1);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr2);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr3);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr4);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr5);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr6);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr7);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr8);
PG_FUNCTION_INFO_V1(owa_util_cellsprint_ovr9);
PG_FUNCTION_INFO_V1(owa_util_choose_date);
PG_FUNCTION_INFO_V1(owa_util_comma_to_ident_arr_ovr1);
PG_FUNCTION_INFO_V1(owa_util_comma_to_ident_arr_ovr2);
PG_FUNCTION_INFO_V1(owa_util_describe_cols);
// PG_FUNCTION_INFO_V1(owa_util_get_cgi_env);
PG_FUNCTION_INFO_V1(owa_util_get_owa_service_path);
PG_FUNCTION_INFO_V1(owa_util_get_procedure);
PG_FUNCTION_INFO_V1(owa_util_get_version);
PG_FUNCTION_INFO_V1(owa_util_ite);
PG_FUNCTION_INFO_V1(owa_util_listprint_ovr1);
PG_FUNCTION_INFO_V1(owa_util_listprint_ovr2);
PG_FUNCTION_INFO_V1(owa_util_mime_header);
PG_FUNCTION_INFO_V1(owa_util_name_resolve);
PG_FUNCTION_INFO_V1(owa_util_path_to_me);
PG_FUNCTION_INFO_V1(owa_util_redirect_url);
PG_FUNCTION_INFO_V1(owa_util_resolve_table);
PG_FUNCTION_INFO_V1(owa_util_showsource);
PG_FUNCTION_INFO_V1(owa_util_show_query_columns);
PG_FUNCTION_INFO_V1(owa_util_signature_ovr1);
PG_FUNCTION_INFO_V1(owa_util_signature_ovr2);
PG_FUNCTION_INFO_V1(owa_util_status_line);
PG_FUNCTION_INFO_V1(owa_util_tablecaption);
PG_FUNCTION_INFO_V1(owa_util_tableclose_ovr1);
PG_FUNCTION_INFO_V1(owa_util_tableclose_ovr2);
PG_FUNCTION_INFO_V1(owa_util_tabledata);
PG_FUNCTION_INFO_V1(owa_util_tableheader_ovr1);
PG_FUNCTION_INFO_V1(owa_util_tableheader_ovr2);
PG_FUNCTION_INFO_V1(owa_util_tableheaderrowclose_ovr1);
PG_FUNCTION_INFO_V1(owa_util_tableheaderrowclose_ovr2);
PG_FUNCTION_INFO_V1(owa_util_tableheaderrowopen_ovr1);
PG_FUNCTION_INFO_V1(owa_util_tableheaderrowopen_ovr2);
PG_FUNCTION_INFO_V1(owa_util_tablenodata);
PG_FUNCTION_INFO_V1(owa_util_tableopen);
PG_FUNCTION_INFO_V1(owa_util_tableprint);
PG_FUNCTION_INFO_V1(owa_util_tablerowclose);
PG_FUNCTION_INFO_V1(owa_util_tablerowopen);
PG_FUNCTION_INFO_V1(owa_util_todate);
PG_FUNCTION_INFO_V1(owa_util_validate_arg);
PG_FUNCTION_INFO_V1(owa_util_who_called_me);
PG_FUNCTION_INFO_V1(owa_util_http_header_close);
 
/**
 * @brief This function prepares a SQL query by binding variables to it, and stores the output in an opened cursor. Use this function as a parameter to a procedure sending a dynamically generated query. Specify up to 25 bind variables.
 * @details This function prepares a SQL query by binding variables to it, and stores the output in an opened cursor. Use this function as a parameter to a procedure sending a dynamically generated query. Specify up to 25 bind variables.
 *  * Parameters:
 *  * @param THEQUERY (in) VARCHAR2: The SQL query statement which must be a SELECT statement
 *  * @param BV1NAME (in) VARCHAR2: The name of the variable
 *  * @param BV1VALUE (in) VARCHAR2: The value of the variable
 *  * @param BV2NAME (in) VARCHAR2: TODO: Описание параметра BV2NAME
 *  * @param BV2VALUE (in) VARCHAR2: TODO: Описание параметра BV2VALUE
 *  * @param BV3NAME (in) VARCHAR2: TODO: Описание параметра BV3NAME
 *  * @param BV3VALUE (in) VARCHAR2: TODO: Описание параметра BV3VALUE
 *  * @param BV4NAME (in) VARCHAR2: TODO: Описание параметра BV4NAME
 *  * @param BV4VALUE (in) VARCHAR2: TODO: Описание параметра BV4VALUE
 *  * @param BV5NAME (in) VARCHAR2: TODO: Описание параметра BV5NAME
 *  * @param BV5VALUE (in) VARCHAR2: TODO: Описание параметра BV5VALUE
 *  * @param BV6NAME (in) VARCHAR2: TODO: Описание параметра BV6NAME
 *  * @param BV6VALUE (in) VARCHAR2: TODO: Описание параметра BV6VALUE
 *  * @param BV7NAME (in) VARCHAR2: TODO: Описание параметра BV7NAME
 *  * @param BV7VALUE (in) VARCHAR2: TODO: Описание параметра BV7VALUE
 *  * @param BV8NAME (in) VARCHAR2: TODO: Описание параметра BV8NAME
 *  * @param BV8VALUE (in) VARCHAR2: TODO: Описание параметра BV8VALUE
 *  * @param BV9NAME (in) VARCHAR2: TODO: Описание параметра BV9NAME
 *  * @param BV9VALUE (in) VARCHAR2: TODO: Описание параметра BV9VALUE
 *  * @param BV10NAME (in) VARCHAR2: TODO: Описание параметра BV10NAME
 *  * @param BV10VALUE (in) VARCHAR2: TODO: Описание параметра BV10VALUE
 *  * @param BV11NAME (in) VARCHAR2: TODO: Описание параметра BV11NAME
 *  * @param BV11VALUE (in) VARCHAR2: TODO: Описание параметра BV11VALUE
 *  * @param BV12NAME (in) VARCHAR2: TODO: Описание параметра BV12NAME
 *  * @param BV12VALUE (in) VARCHAR2: TODO: Описание параметра BV12VALUE
 *  * @param BV13NAME (in) VARCHAR2: TODO: Описание параметра BV13NAME
 *  * @param BV13VALUE (in) VARCHAR2: TODO: Описание параметра BV13VALUE
 *  * @param BV14NAME (in) VARCHAR2: TODO: Описание параметра BV14NAME
 *  * @param BV14VALUE (in) VARCHAR2: TODO: Описание параметра BV14VALUE
 *  * @param BV15NAME (in) VARCHAR2: TODO: Описание параметра BV15NAME
 *  * @param BV15VALUE (in) VARCHAR2: TODO: Описание параметра BV15VALUE
 *  * @param BV16NAME (in) VARCHAR2: TODO: Описание параметра BV16NAME
 *  * @param BV16VALUE (in) VARCHAR2: TODO: Описание параметра BV16VALUE
 *  * @param BV17NAME (in) VARCHAR2: TODO: Описание параметра BV17NAME
 *  * @param BV17VALUE (in) VARCHAR2: TODO: Описание параметра BV17VALUE
 *  * @param BV18NAME (in) VARCHAR2: TODO: Описание параметра BV18NAME
 *  * @param BV18VALUE (in) VARCHAR2: TODO: Описание параметра BV18VALUE
 *  * @param BV19NAME (in) VARCHAR2: TODO: Описание параметра BV19NAME
 *  * @param BV19VALUE (in) VARCHAR2: TODO: Описание параметра BV19VALUE
 *  * @param BV20NAME (in) VARCHAR2: TODO: Описание параметра BV20NAME
 *  * @param BV20VALUE (in) VARCHAR2: TODO: Описание параметра BV20VALUE
 *  * @param BV21NAME (in) VARCHAR2: TODO: Описание параметра BV21NAME
 *  * @param BV21VALUE (in) VARCHAR2: TODO: Описание параметра BV21VALUE
 *  * @param BV22NAME (in) VARCHAR2: TODO: Описание параметра BV22NAME
 *  * @param BV22VALUE (in) VARCHAR2: TODO: Описание параметра BV22VALUE
 *  * @param BV23NAME (in) VARCHAR2: TODO: Описание параметра BV23NAME
 *  * @param BV23VALUE (in) VARCHAR2: TODO: Описание параметра BV23VALUE
 *  * @param BV24NAME (in) VARCHAR2: TODO: Описание параметра BV24NAME
 *  * @param BV24VALUE (in) VARCHAR2: TODO: Описание параметра BV24VALUE
 *  * @param BV25NAME (in) VARCHAR2: TODO: Описание параметра BV25NAME
 *  * @param BV25VALUE (in) VARCHAR2: TODO: Описание параметра BV25VALUE
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_bind_variables(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.bind_variables еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief These procedures creates a calendar in HTML with a visible border. Each date in the calendar can contain any number of hypertext links.
 * @details These procedures creates a calendar in HTML with a visible border. Each date in the calendar can contain any number of hypertext links.
 *  * Parameters:
 *  * @param P_QUERY (in) VARCHAR2: A PL/SQL query.
 *  * @param P_MF_ONLY (in) VARCHAR2: If "N" (the default), the generated calendar includes Sunday through Saturday. Otherwise, it includes Monday through Friday only.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_calendarprint_ovr1(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.calendarprint еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief These procedures creates a calendar in HTML with a visible border. Each date in the calendar can contain any number of hypertext links.
 * @details These procedures creates a calendar in HTML with a visible border. Each date in the calendar can contain any number of hypertext links.
 *  * Parameters:
 *  * @param P_CURSOR (in) NUMBER: A PL/SQL cursor containing the same format asp_query.
 *  * @param P_MF_ONLY (in) VARCHAR2: If "N" (the default), the generated calendar includes Sunday through Saturday. Otherwise, it includes Monday through Friday only.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_calendarprint_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.calendarprint еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_COLCNT (in) NUMBER: The number of columns in the table.
 *  * @param P_RESULTTBL (in) PL/SQL TABLE: The index table which will contain the result of the query. Each entry in the query will correspond to one column value.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr1(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_THEQUERY (in) VARCHAR2: A SQLSELECTstatement.
 *  * @param P_MAX_ROWS (in) NUMBER: The maximum number of rows to print.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_THECURSOR (in) NUMBER: A cursor ID. This can be the return value from theBIND_VARIABLES Function.
 *  * @param P_MAX_ROWS (in) NUMBER: The maximum number of rows to print.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr3(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_THEQUERY (in) VARCHAR2: A SQLSELECTstatement.
 *  * @param P_MAX_ROWS (in) NUMBER: The maximum number of rows to print.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  * @param P_SKIP_REC (in) NUMBER: The number of rows to exclude from the HTML table.
 *  *  * @param P_MORE_DATA (out) BOOLEAN: TRUEif there are more rows in the query or cursor,FALSEotherwise. (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (boolean), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr4(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_THECURSOR (in) NUMBER: A cursor ID. This can be the return value from theBIND_VARIABLES Function.
 *  * @param P_MAX_ROWS (in) NUMBER: The maximum number of rows to print.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  * @param P_SKIP_REC (in) NUMBER: The number of rows to exclude from the HTML table.
 *  *  * @param P_MORE_DATA (out) BOOLEAN: TRUEif there are more rows in the query or cursor,FALSEotherwise. (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (boolean), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr5(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_THEQUERY (in) VARCHAR2: A SQLSELECTstatement.
 *  * @param P_MAX_ROWS (in) NUMBER: The maximum number of rows to print.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  *  * @param P_RECCNT (out) NUMBER: The number of rows that have been returned by the query. This value does not include skipped rows (if any). (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr6(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_THECURSOR (in) NUMBER: A cursor ID. This can be the return value from theBIND_VARIABLES Function.
 *  * @param P_MAX_ROWS (in) NUMBER: The maximum number of rows to print.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  *  * @param P_RECCNT (out) NUMBER: The number of rows that have been returned by the query. This value does not include skipped rows (if any). (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr7(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_THEQUERY (in) VARCHAR2: A SQLSELECTstatement.
 *  * @param P_MAX_ROWS (in) NUMBER: The maximum number of rows to print.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  * @param P_SKIP_REC (in) NUMBER: The number of rows to exclude from the HTML table.
 *  *  * @param P_MORE_DATA (out) BOOLEAN: TRUEif there are more rows in the query or cursor,FALSEotherwise. (Возвращается через результат)
 *  * @param P_RECCNT (out) NUMBER: The number of rows that have been returned by the query. This value does not include skipped rows (if any). (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (boolean number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr8(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 * @details This procedure generates an HTML table from the output of a SQL query. SQL atomic data items are mapped to HTML cells and SQL rows to HTML rows. You must write the code to begin and end the HTML table.
 *  * Parameters:
 *  * @param P_THECURSOR (in) NUMBER: A cursor ID. This can be the return value from theBIND_VARIABLES Function.
 *  * @param P_MAX_ROWS (in) NUMBER: The maximum number of rows to print.
 *  * @param P_FORMAT_NUMBERS (in) VARCHAR2: If the value of this parameter is notNULL, number fields are right justified and rounded to two decimal places.
 *  * @param P_SKIP_REC (in) NUMBER: The number of rows to exclude from the HTML table.
 *  *  * @param P_MORE_DATA (out) BOOLEAN: TRUEif there are more rows in the query or cursor,FALSEotherwise. (Возвращается через результат)
 *  * @param P_RECCNT (out) NUMBER: The number of rows that have been returned by the query. This value does not include skipped rows (if any). (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (boolean number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_cellsprint_ovr9(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.cellsprint еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This procedure generates three HTML form elements that allow the user to select the day, the month, and the year.
 * @details This procedure generates three HTML form elements that allow the user to select the day, the month, and the year.
 *  * Parameters:
 *  * @param P_NAME (in) VARCHAR2: The name of the form elements.
 *  * @param P_DATE (in) DATE: The initial date that is selected when the HTML page is displayed.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_choose_date(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.choose_date еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param LIST (in) VARCHAR2: TODO: Описание параметра LIST
 *  *  * @param ARR (out) PL/SQL TABLE: TODO: Описание параметра ARR (Возвращается через результат)
 *  * @param LENARR (out) PL/SQL TABLE: TODO: Описание параметра LENARR (Возвращается через результат)
 *  * @param ARRLEN (out) NUMBER: TODO: Описание параметра ARRLEN (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (pl/sql table pl/sql table number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_comma_to_ident_arr_ovr1(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.comma_to_ident_arr еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param LIST (in) VARCHAR2: TODO: Описание параметра LIST
 *  *  * @param ARR (out) PL/SQL TABLE: TODO: Описание параметра ARR (Возвращается через результат)
 *  * @param LENARR (out) PL/SQL TABLE: TODO: Описание параметра LENARR (Возвращается через результат)
 *  * @param ARRLEN (out) NUMBER: TODO: Описание параметра ARRLEN (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (pl/sql table pl/sql table number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_comma_to_ident_arr_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.comma_to_ident_arr еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CTABLE (in) VARCHAR2: TODO: Описание параметра CTABLE
 *  * @param CCOLUMNS (in) VARCHAR2: TODO: Описание параметра CCOLUMNS
 *  *  * @param COL_NAMES (out) PL/SQL TABLE: TODO: Описание параметра COL_NAMES (Возвращается через результат)
 *  * @param COL_DTYPES (out) PL/SQL TABLE: TODO: Описание параметра COL_DTYPES (Возвращается через результат)
 *  * @param NNUM_COLS (out) NUMBER: TODO: Описание параметра NNUM_COLS (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (pl/sql table pl/sql table number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_describe_cols(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.describe_cols еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This function returns the value of the specified CGI environment variable.
 * @details This function returns the value of the specified CGI environment variable.
 *  * Parameters:
 *  * @param PARAM_NAME (in) VARCHAR2: The name of the CGI environment variable. It is case-insensitive.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
/*
Datum owa_util_get_cgi_env(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.get_cgi_env еще не реализована.")));
 
    PG_RETURN_VOID();
}
*/
 
/**
 * @brief This function returns the full virtual path of the PL/SQL Gateway that is handling the request.
 * @details This function returns the full virtual path of the PL/SQL Gateway that is handling the request.
 *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_get_owa_service_path(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.get_owa_service_path еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This function returns the name of the procedure that is being invoked by the PL/SQL Gateway.
 * @details This function returns the name of the procedure that is being invoked by the PL/SQL Gateway.
 *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_get_procedure(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.get_procedure еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_get_version(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.get_version еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param TF (in) BOOLEAN: TODO: Описание параметра TF
 *  * @param YES (in) VARCHAR2: TODO: Описание параметра YES
 *  * @param NO (in) VARCHAR2: TODO: Описание параметра NO
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_ite(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.ite еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure generates an HTML selection list form element from the output of a SQL query.
 * @details This procedure generates an HTML selection list form element from the output of a SQL query.
 
The first column specifies the values that are sent back. These values are for theVALUEattribute of theOPTIONtag.
The second column specifies the values that the user sees.
The third column specifies whether or not the row is marked asSELECTEDin theOPTIONtag. If the value is notNULL, the row is selected.
 *  * Parameters:
 *  * @param P_THECURSOR (in) NUMBER: The cursor ID. This can be the return value from theBIND_VARIABLES Function.
 *  * @param P_CNAME (in) VARCHAR2: The name of the HTML form element.
 *  * @param P_NSIZE (in) NUMBER: The size of the form element (this controls how many items the user can see without scrolling).
 *  * @param P_MULTIPLE (in) BOOLEAN: Whether multiple selection is permitted.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_listprint_ovr1(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.listprint еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure generates an HTML selection list form element from the output of a SQL query.
 * @details This procedure generates an HTML selection list form element from the output of a SQL query.
 
The first column specifies the values that are sent back. These values are for theVALUEattribute of theOPTIONtag.
The second column specifies the values that the user sees.
The third column specifies whether or not the row is marked asSELECTEDin theOPTIONtag. If the value is notNULL, the row is selected.
 *  * Parameters:
 *  * @param P_THEQUERY (in) VARCHAR2: The SQL query.
 *  * @param P_CNAME (in) VARCHAR2: The name of the HTML form element.
 *  * @param P_NSIZE (in) NUMBER: The size of the form element (this controls how many items the user can see without scrolling).
 *  * @param P_MULTIPLE (in) BOOLEAN: Whether multiple selection is permitted.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_listprint_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.listprint еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure changes the default MIME header that the script returns. This procedure must come before anyHTP.PRINT or HTP.PRNcalls to direct the script not to use the default MIME header.
 * @details This procedure changes the default MIME header that the script returns. This procedure must come before anyHTP.PRINT or HTP.PRNcalls to direct the script not to use the default MIME header.
 *  * Parameters:
 *  * @param CCONTENT_TYPE (in) VARCHAR2: The MIME type to generate
 *  * @param BCLOSE_HEADER (in) BOOLEAN: Whether or not to close the HTTP header. IfTRUE, two newlines are sent, which closes the HTTP header. Otherwise, one newline is sent, and the HTTP header remains open.
 *  * @param CCHARSET (in) VARCHAR2: The character set to use.The character set only makes sense if the MIME type is of type 'text'. Therefore, the character set is only tagged on to the Content-Type header only if the MIME type passed in is of type 'text'. Any other MIME type, such as 'image', will not have any character set tagged on.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_mime_header(PG_FUNCTION_ARGS)
{
    text *ccontent_type_txt = PG_GETARG_TEXT_P(0);
    char *ccontent_type = text_to_cstring(ccontent_type_txt);
    bool bclose_header = PG_GETARG_BOOL(1);
 
    char *ccharset = nullptr;
    if (!PG_ARGISNULL(2))
    {
        text *ccharset_txt = PG_GETARG_TEXT_P(2);
        ccharset = text_to_cstring(ccharset_txt);
 
        char *terminate = strchr(ccharset, '\n');
        if (terminate != nullptr)
        {
            *terminate = '\0';
        }
        terminate = strchr(ccharset, '\r');
        if (terminate != nullptr)
        {
            *terminate = '\0';
        }
    }
 
    char *terminate = strchr(ccontent_type, '\n');
    if (terminate != nullptr)
    {
        *terminate = '\0';
    }
    terminate = strchr(ccontent_type, '\r');
    if (terminate != nullptr)
    {
        *terminate = '\0';
    }
 
    std::string header;
    header.append("Content-Type: ");
    header.append(ccontent_type);
 
    if (ccharset != nullptr)
    {
        header.append("; charset=");
        header.append(ccharset);
    }
    header.append("\n");
 
    text *header_txt = cstring_to_text(header.c_str());
    DirectFunctionCall1(htp_prn_ovr1, PointerGetDatum(header_txt));
 
    if (bclose_header)
    {
        LOCAL_FCINFO(fcinfo2, 0);
        InitFunctionCallInfoData(*fcinfo2, nullptr, 0, InvalidOid, nullptr, nullptr);
        owa_util_http_header_close(fcinfo2);
    }
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CNAME (in) VARCHAR2: TODO: Описание параметра CNAME
 *  *  * @param O_PROCOWNER (out) VARCHAR2: TODO: Описание параметра O_PROCOWNER (Возвращается через результат)
 *  * @param O_PROCNAME (out) VARCHAR2: TODO: Описание параметра O_PROCNAME (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2 varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_name_resolve(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.name_resolve еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_path_to_me(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.path_to_me еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure specifies that the application server is to visit the specified URL. The URL may specify either a Web page to return or a program to execute.
 * @details This procedure specifies that the application server is to visit the specified URL. The URL may specify either a Web page to return or a program to execute.
 *  * Parameters:
 *  * @param CURL (in) VARCHAR2: The URL to visit.
 *  * @param BCLOSE_HEADER (in) BOOLEAN: Whether or not to close the HTTP header. IfTRUE, two newlines are sent, which closes the HTTP header. Otherwise, one newline is sent, and the HTTP header remains open.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_redirect_url(PG_FUNCTION_ARGS)
{
    text *location_txt = PG_GETARG_TEXT_P(0);
    bool bclose_header = PG_GETARG_BOOL(1);
 
    char *location = text_to_cstring(location_txt);
 
    char *terminate = strchr(location, '\n');
    if (terminate != nullptr)
    {
        *terminate = '\0';
    }
    terminate = strchr(location, '\r');
    if (terminate != nullptr)
    {
        *terminate = '\0';
    }
 
    std::string result;
 
    result.append("Location: ");
    result.append(location);
    result.append("\n");
 
    pfree(location);
 
    text *result_txt = cstring_to_text(result.c_str());
 
    DirectFunctionCall1(htp_print_ovr1, PointerGetDatum(result_txt));
 
    if (bclose_header)
    {
        LOCAL_FCINFO(fcinfo2, 0);
        InitFunctionCallInfoData(*fcinfo2, nullptr, 0, InvalidOid, nullptr, nullptr);
        owa_util_http_header_close(fcinfo2);
    }
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param COBJECT (in) VARCHAR2: TODO: Описание параметра COBJECT
 *  * @param CSCHEMA (in) VARCHAR2: TODO: Описание параметра CSCHEMA
 *  *  * @param RESOLVED_NAME (out) VARCHAR2: TODO: Описание параметра RESOLVED_NAME (Возвращается через результат)
 *  * @param RESOLVED_OWNER (out) VARCHAR2: TODO: Описание параметра RESOLVED_OWNER (Возвращается через результат)
 *  * @param RESOLVED_DB_LINK (out) VARCHAR2: TODO: Описание параметра RESOLVED_DB_LINK (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2 varchar2 varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_resolve_table(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.resolve_table еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This procedure prints the source of the specified procedure, function, or package. If a procedure or function which belongs to a package is specified, then the entire package is displayed.
 * @details This procedure prints the source of the specified procedure, function, or package. If a procedure or function which belongs to a package is specified, then the entire package is displayed.
 *  * Parameters:
 *  * @param CNAME (in) VARCHAR2: The function or procedure whose source you want to show.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_showsource(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.showsource еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CTABLE (in) VARCHAR2: TODO: Описание параметра CTABLE
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_show_query_columns(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.show_query_columns еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_signature_ovr1(PG_FUNCTION_ARGS)
{
    std::time_t timestamp = std::time(nullptr);
    std::tm *local_tm = std::localtime(&timestamp);
 
    std::ostringstream stream;
    stream << "This page was produced by the ";
    stream << "<b>PL/SQL Web Toolkit</b> on";
    stream << std::put_time(local_tm, "%B %e, %Y %H:%M");
    stream << ".\n";
 
    text *result = cstring_to_text(stream.str().c_str());
    DirectFunctionCall1(htp_p_ovr1, PointerGetDatum(result));
    pfree(result);
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CNAME (in) VARCHAR2: TODO: Описание параметра CNAME
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_signature_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.signature еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure sends a standard HTTP status code to the client.
 * @details This procedure sends a standard HTTP status code to the client.
 *  * Parameters:
 *  * @param NSTATUS (in) NUMBER: The status code.
 *  * @param CREASON (in) VARCHAR2: The string for the status code.
 *  * @param BCLOSE_HEADER (in) BOOLEAN: Whether or not to close the HTTP header. IfTRUE, two newlines are sent, which closes the HTTP header. Otherwise, one newline is sent, and the HTTP header remains open.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_status_line(PG_FUNCTION_ARGS)
{
    Datum nstatus_num = PG_GETARG_DATUM(0);
    int32_t nstatus = DatumGetInt32(DirectFunctionCall1(numeric_int4, nstatus_num));
 
    char *creason;
    if (!PG_ARGISNULL(1))
    {
        text *creason_txt = PG_GETARG_TEXT_P(1);
        creason = text_to_cstring(creason_txt);
    }
    else
    {
        creason = pstrdup("");
    }
 
    bool bclose_header = PG_GETARG_BOOL(2);
 
    std::string result = "Status: ";
    result.append(std::to_string(nstatus));
    result.append(" ");
    result.append(creason);
    result.push_back('\n');
 
    text *result_txt = cstring_to_text(result.c_str());
    DirectFunctionCall1(htp_prn_ovr1, PointerGetDatum(result_txt));
    pfree(result_txt);
 
    if (bclose_header)
    {
        LOCAL_FCINFO(fcinfo2, 0);
        InitFunctionCallInfoData(*fcinfo2, nullptr, 0, InvalidOid, nullptr, nullptr);
        owa_util_http_header_close(fcinfo2);
    }
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CCAPTION (in) VARCHAR2: TODO: Описание параметра CCAPTION
 *  * @param CALIGN (in) VARCHAR2: TODO: Описание параметра CALIGN
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tablecaption(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tablecaption еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableclose_ovr1(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableclose еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param NTABLE_WIDTH (in) NUMBER: TODO: Описание параметра NTABLE_WIDTH
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableclose_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableclose еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CDATA (in) VARCHAR2: TODO: Описание параметра CDATA
 *  * @param NCOLUMN_SIZE (in) NUMBER: TODO: Описание параметра NCOLUMN_SIZE
 *  * @param CALIGN (in) VARCHAR2: TODO: Описание параметра CALIGN
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tabledata(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tabledata еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CCOLUMN_NAME (in) VARCHAR2: TODO: Описание параметра CCOLUMN_NAME
 *  * @param NCOLUMN_SIZE (in) NUMBER: TODO: Описание параметра NCOLUMN_SIZE
 *  * @param CALIGN (in) VARCHAR2: TODO: Описание параметра CALIGN
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableheader_ovr1(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableheader еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CCOLUMN_NAME (in) VARCHAR2: TODO: Описание параметра CCOLUMN_NAME
 *  * @param NCOLUMN_SIZE (in) NUMBER: TODO: Описание параметра NCOLUMN_SIZE
 *  * @param CALIGN (in) VARCHAR2: TODO: Описание параметра CALIGN
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_WIDTH (in/out) NUMBER: TODO: Описание параметра NTABLE_WIDTH
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  * @param NTABLE_WIDTH (in/out) NUMBER: TODO: Описание параметра NTABLE_WIDTH (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2 number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableheader_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableheader еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableheaderrowclose_ovr1(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableheaderrowclose еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_WIDTH (in) NUMBER: TODO: Описание параметра NTABLE_WIDTH
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableheaderrowclose_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableheaderrowclose еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableheaderrowopen_ovr1(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableheaderrowopen еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  * @param NTABLE_WIDTH (out) NUMBER: TODO: Описание параметра NTABLE_WIDTH (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2 number), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableheaderrowopen_ovr2(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableheaderrowopen еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CALIGN (in) VARCHAR2: TODO: Описание параметра CALIGN
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NNUM_COLS (in) NUMBER: TODO: Описание параметра NNUM_COLS
 *  * @param NTABLE_WIDTH (in) NUMBER: TODO: Описание параметра NTABLE_WIDTH
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tablenodata(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tablenodata еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CATTRIBUTES (in) VARCHAR2: TODO: Описание параметра CATTRIBUTES
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableopen(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tableopen еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This function generates either preformatted tables or HTML tables (depending on the capabilities of the user's browser) from database tables.
 * @details This function generates either preformatted tables or HTML tables (depending on the capabilities of the user's browser) from database tables.
 *  * Parameters:
 *  * @param CTABLE (in) VARCHAR2: The database table.
 *  * @param CATTRIBUTES (in) VARCHAR2: Other attributes to be included as-is in the tag.
 *  * @param NTABLE_TYPE (in) NUMBER: How to generate the table. SpecifyHTML_TABLEto generate the table using<TABLE>tags or PRE_TABLEto generate the table using the<PRE>tags. These are constants:HTML_TABLECONSTANT INTEGER:= 1;PRE_TABLECONSTANT INTEGER:= 2;
 *  * @param CCOLUMNS (in) VARCHAR2: A comma-delimited list of columns fromctableto include in the generated table.
 *  * @param CCLAUSES (in) VARCHAR2: WHEREor ORDERBYclauses, which specify which rows to retrieve from the database table, and how to order them.
 *  * @param CCOL_ALIASES (in) VARCHAR2: A comma-delimited list of headings for the generated table.
 *  * @param NROW_MIN (in) NUMBER: The first row, of those retrieved, to display.
 *  * @param NROW_MAX (in) NUMBER: The last row, of those retrieved, to display.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tableprint(PG_FUNCTION_ARGS)
{
    char *ctable = text_to_cstring(PG_GETARG_TEXT_P(0));
 
    Datum cattributes_datum = PG_ARGISNULL(1) ? static_cast<Datum>(0) : PG_GETARG_DATUM(1);
 
    int32_t table_type = DatumGetInt32(DirectFunctionCall1(numeric_int4, PG_GETARG_DATUM(2)));
 
    char *ccolumns = text_to_cstring(PG_GETARG_TEXT_P(3));
 
    char *cclauses;
    if (!PG_ARGISNULL(4))
    {
        cclauses = text_to_cstring(PG_GETARG_TEXT_P(4));
    }
    else
    {
        cclauses = pstrdup("");
    }
 
    std::vector<std::string> headings;
    if (!PG_ARGISNULL(5))
    {
        char *ccol_aliases = text_to_cstring(PG_GETARG_TEXT_P(5));
        char *alias = strtok(ccol_aliases, ",");
        while (alias != nullptr)
        {
            headings.push_back(alias);
            alias = strtok(nullptr, ",");
        }
        pfree(ccol_aliases);
    }
 
    int32_t nrow_min;
    if (!PG_ARGISNULL(6))
    {
        nrow_min = 0;
    }
    else
    {
        nrow_min = DatumGetInt32(DirectFunctionCall1(numeric_int4, PG_GETARG_DATUM(6)));
    }
    int32_t nrow_max;
    if (!PG_ARGISNULL(7))
    {
        nrow_max = DatumGetInt32(DirectFunctionCall1(numeric_int4, PG_GETARG_DATUM(7)));
    }
    else
    {
        nrow_max = std::numeric_limits<int32_t>::max();
    }
 
    SPI_connect();
 
    std::string query = "SELECT ";
    query.append(ccolumns);
    query.append(" FROM ");
    query.append(ctable);
    query.append(" ");
    query.append(cclauses);
    query.append(";");
 
    pfree(ccolumns);
    pfree(ctable);
    pfree(cclauses);
 
    ereport(DEBUG1,
            errmsg_internal("OWA_UTIL.TABLEPRINT: query: %s", query.c_str()));
 
    int query_res = SPI_execute(query.c_str(), true, 0);
 
    if (query_res < 0)
    {
        ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
                        errmsg("Query failed: %d", query_res)));
        SPI_finish();
        PG_RETURN_NULL();
    }
 
    if (headings.empty())
    {
        for (int i = 0; i < SPI_tuptable->tupdesc->natts; i++)
        {
            headings.push_back(TupleDescAttr(SPI_tuptable->tupdesc, i)->attname.data);
        }
    }
    else if (headings.size() != static_cast<size_t>(SPI_tuptable->tupdesc->natts))
    {
        ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                        errmsg("Invalid number of aliases!")));
    }
 
    std::vector<Oid> out_functions(headings.size());
    for (size_t i = 0; i < headings.size(); i++)
    {
        Oid target_type = TupleDescAttr(SPI_tuptable->tupdesc, i)->atttypid;
        Oid out_func;
        bool output_is_varlena;
        getTypeOutputInfo(target_type, &out_func, &output_is_varlena);
        out_functions[i] = out_func;
    }
 
    std::vector<size_t> column_widths(headings.size());
    if (table_type == OWA_UTIL_PRE_TABLE)
    {
        for (size_t i = 0; i < headings.size(); i++)
        {
            column_widths[i] = headings[i].size();
        }
    }
 
    std::vector<std::vector<char*>> entries(SPI_tuptable->numvals, std::vector<char*>(headings.size()));
 
    for (size_t i = 0; i < SPI_tuptable->numvals; i++)
    {
        std::vector<Datum> datums(headings.size());
        bool *nulls = (bool*)palloc(headings.size() * sizeof(bool));
        heap_deform_tuple(SPI_tuptable->vals[i], SPI_tuptable->tupdesc,
                          datums.data(), nulls);
        for (size_t j = 0; j < headings.size(); j++)
        {
            if (!nulls[j])
            {
                char *out_value = OidOutputFunctionCall(out_functions[j], datums[j]);
                if (table_type == OWA_UTIL_PRE_TABLE)
                {
                    column_widths[i] = Max(column_widths[i], strlen(out_value));
                }
                entries[i][j] = out_value;
                pfree(out_value);
            }
            else
            {
                entries[i][j] = pstrdup("");
            }
        }
        pfree(nulls);
    }
 
    bool too_many_rows = SPI_tuptable->numvals > static_cast<uint64_t>(nrow_max - nrow_min + 1);
 
    char table_border;
    // print table
    // start
    if (table_type == OWA_UTIL_HTML_TABLE)
    {
        {
            LOCAL_FCINFO(fcinfo2, 5);
            InitFunctionCallInfoData(*fcinfo2, NULL, 5, PG_GET_COLLATION(), NULL, NULL);
            fcinfo2->args[0].isnull = true;
            fcinfo2->args[1].isnull = true;
            fcinfo2->args[2].isnull = true;
            fcinfo2->args[3].isnull = true;
            fcinfo2->args[4].isnull = cattributes_datum == 0;
            fcinfo2->args[4].value = cattributes_datum;
            htp_tableopen(fcinfo2);
        }
 
        {
            LOCAL_FCINFO(fcinfo2, 5);
            InitFunctionCallInfoData(*fcinfo2, NULL, 5, PG_GET_COLLATION(), NULL, NULL);
            fcinfo2->args[0].isnull = true;
            fcinfo2->args[1].isnull = true;
            fcinfo2->args[2].isnull = true;
            fcinfo2->args[3].isnull = true;
            fcinfo2->args[4].isnull = true;
            htp_tablerowopen(fcinfo2);
        }
 
        for (auto &heading: headings)
        {
            text *heading_txt = cstring_to_text(heading.c_str());
 
            LOCAL_FCINFO(fcinfo2, 6);
            InitFunctionCallInfoData(*fcinfo2, NULL, 6, PG_GET_COLLATION(), NULL, NULL);
            fcinfo2->args[0].isnull = false;
            fcinfo2->args[1].value = PointerGetDatum(heading_txt);
            fcinfo2->args[1].isnull = true;
            fcinfo2->args[2].isnull = true;
            fcinfo2->args[3].isnull = true;
            fcinfo2->args[4].isnull = true;
            fcinfo2->args[5].isnull = true;
            htp_tabledata(fcinfo2);
 
            pfree(heading_txt);
        }
 
        {
            LOCAL_FCINFO(fcinfo2, 5);
            InitFunctionCallInfoData(*fcinfo2, NULL, 5, PG_GET_COLLATION(), NULL, NULL);
            fcinfo2->args[0].isnull = true;
            fcinfo2->args[1].isnull = true;
            fcinfo2->args[2].isnull = true;
            fcinfo2->args[3].isnull = true;
            fcinfo2->args[4].isnull = true;
            htp_tablerowclose(fcinfo2);
        }
 
        for (auto &row: entries)
        {
            {
                LOCAL_FCINFO(fcinfo2, 5);
                InitFunctionCallInfoData(*fcinfo2, NULL, 5, PG_GET_COLLATION(), NULL, NULL);
                fcinfo2->args[0].isnull = true;
                fcinfo2->args[1].isnull = true;
                fcinfo2->args[2].isnull = true;
                fcinfo2->args[3].isnull = true;
                fcinfo2->args[4].isnull = true;
                htp_tablerowopen(fcinfo2);
            }
 
            for (auto &cell: row)
            {
                text *cell_txt = cstring_to_text(cell);
 
                LOCAL_FCINFO(fcinfo2, 6);
                InitFunctionCallInfoData(*fcinfo2, NULL, 6, PG_GET_COLLATION(), NULL, NULL);
                fcinfo2->args[0].isnull = false;
                fcinfo2->args[1].value = PointerGetDatum(cell_txt);
                fcinfo2->args[1].isnull = true;
                fcinfo2->args[2].isnull = true;
                fcinfo2->args[3].isnull = true;
                fcinfo2->args[4].isnull = true;
                fcinfo2->args[5].isnull = true;
                htp_tabledata(fcinfo2);
                pfree(cell_txt);
            }
 
            {
                LOCAL_FCINFO(fcinfo2, 5);
                InitFunctionCallInfoData(*fcinfo2, NULL, 5, PG_GET_COLLATION(), NULL, NULL);
                fcinfo2->args[0].isnull = true;
                fcinfo2->args[1].isnull = true;
                fcinfo2->args[2].isnull = true;
                fcinfo2->args[3].isnull = true;
                fcinfo2->args[4].isnull = true;
                htp_tablerowclose(fcinfo2);
            }
        }
    }
    else // table_type == OWA_UTIL_PRE_TABLE
    {
        table_border = PG_ARGISNULL(1)? ' ' : '|';
        std::ostringstream stream;
        std::string line;
 
        size_t line_width = std::accumulate(column_widths.begin(),
                                            column_widths.end(),
                                            static_cast<size_t>(0));
 
        // For each column we add two spaces and one table_border characters
        // also we add additional table border character for table line begin
        line_width += 3 * headings.size() + 1;
        line.resize(line_width, '-');
 
        stream << "<pre>\n" << line << "\n" << table_border;
        for (size_t i = 0; i < headings.size(); i++)
        {
            stream << ' ' << std::setw(column_widths[i] + 1) << headings[i]
                   << std::setw(0) << table_border;
        }
        stream << "\n";
 
        for (auto &row: entries)
        {
            stream << table_border;
            for (size_t i = 0; i < row.size(); i++)
            {
                stream << ' ' << std::setw(column_widths[i] + 1) << headings[i]
                       << std::setw(0) << table_border;
            }
            stream << "\n";
        }
 
        stream << "</pre>";
 
        text *result = cstring_to_text(stream.str().c_str());
 
        DirectFunctionCall1(htp_print_ovr1, PointerGetDatum(result));
        pfree(result);
    }
 
    for (auto &row: entries)
    {
        for (char *cell: row)
        {
            pfree(cell);
        }
    }
 
    SPI_finish();
    PG_RETURN_BOOL(too_many_rows);
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tablerowclose(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tablerowclose еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING
 *  * @param NTABLE_TYPE (in) NUMBER: TODO: Описание параметра NTABLE_TYPE
 *  *  * @param CROWSTRING (in/out) VARCHAR2: TODO: Описание параметра CROWSTRING (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_tablerowopen(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.tablerowopen еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
/**
 * @brief This function converts the DATETYPE Datatype to the standard OracleDATEtype.
 * @details This function converts the DATETYPE Datatype to the standard OracleDATEtype.
 *  * Parameters:
 *  * @param P_DATEARRAY (in) PL/SQL TABLE: The value to convert.
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_todate(PG_FUNCTION_ARGS)
{
    ArrayType *arr = PG_GETARG_ARRAYTYPE_P(0);
 
    Datum *elems;
    bool *nulls;
    int len;
 
    deconstruct_array(arr, VARCHAR2OID, -1, false, TYPALIGN_INT,
                      &elems, &nulls, &len);
 
    Assert(len == 3);
 
    text *dd_txt = DatumGetTextP(elems[0]);
    text *mm_txt = DatumGetTextP(elems[1]);
    text *yyyy_txt = DatumGetTextP(elems[2]);
 
    char dd[3];
    char mm[3];
    char yyyy[5];
    char date[11];
 
    text_to_cstring_buffer(dd_txt, dd, 2);
    text_to_cstring_buffer(mm_txt, mm, 2);
    text_to_cstring_buffer(yyyy_txt, yyyy, 4);
 
    sprintf(date, "%s-%s-%s", dd, mm, yyyy);
 
    text *date_txt = cstring_to_text(date);
 
    pfree(elems);
    pfree(nulls);
 
    PG_RETURN_DATUM(DirectFunctionCall1(date_in, PointerGetDatum(date_txt)));
}
 
/**
 * @brief TODO: Добавить описание
 * @details TODO: Добавить детальное описание
 *  * Parameters:
 *  * @param PARAM (in) VARCHAR2: TODO: Описание параметра PARAM
 *  *  *  *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_validate_arg(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.validate_arg еще не реализована.")));
 
    PG_RETURN_VOID();
}
 
/**
 * @brief This procedure returns information (in the form of output parameters) about the PL/SQL code unit that invoked it.
 * @details This procedure returns information (in the form of output parameters) about the PL/SQL code unit that invoked it.
 *  * Parameters:
 *  *  * @param OWNER (out) VARCHAR2: The owner of the program unit. (Возвращается через результат)
 *  * @param NAME (out) VARCHAR2: The name of the program unit. This is the name of the package, if the calling program unit is wrapped in a package, or the name of the procedure or function if the calling program unit is a standalone procedure or function. If the calling program unit is part of an anonymous block, this isNULL. (Возвращается через результат)
 *  * @param LINENO (out) NUMBER: The line number within the program unit where the call was made. (Возвращается через результат)
 *  * @param CALLER_T (out) VARCHAR2: The type of program unit that made the call. The possibilities are: package body, anonymous block, procedure, and function. Procedure and function are only for standalone procedures and functions. (Возвращается через результат)
 *  *  *  * @return record: Композитный тип (varchar2 varchar2 number varchar2), содержащий OUT/INOUT параметры.
 *  *
 * @see https://docs.oracle.com/en/database/oracle/oracle-database/23/arpls/OWA_UTIL.html
 */
Datum owa_util_who_called_me(PG_FUNCTION_ARGS)
{
    ereport(NOTICE, (errmsg("Функция owa_util.who_called_me еще не реализована.")));
 
    PG_RETURN_NULL();
}
 
Datum owa_util_http_header_close(PG_FUNCTION_ARGS)
{
    text *nl = cstring_to_text("\n");
    DirectFunctionCall1(htp_prn_ovr1, PointerGetDatum(nl));
    PG_RETURN_VOID();
}
 
} // extern "C"