Qore PgsqlSqlUtilBase Module Reference 1.8
Loading...
Searching...
No Matches
PgsqlSqlUtilBase.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* PgsqlSqlUtilBase.qm Copyright (C) 2013 - 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// minimum required Qore version
26
27// requires the SqlUtil module
28
29// don't use "$" signs for variables and class members, assume local variable scope
30
31// require type definitions everywhere
32
33// enable all warnings
34
35
36// version history is included below in the docs
37
291 PgsqlTable get_table(AbstractDatasource nds, string nname, *hash<auto> opts);
292
293
295 PgsqlDatabase get_database(AbstractDatasource nds, *hash<auto> opts);
296
297
300
301public:
303 constructor(string native_type, bool nullable, *hash<auto> options) ;
304
305 };
306
307 parse_schema_name(string nname, reference<string> schema, reference<string> name);
308
309
311class PgsqlSavepointHelper : public AbstractSavepointHelper {
312
313public:
315 constructor(AbstractDatasource ds, *string savepoint) ;
316
317
319protected:
321public:
322
323
325protected:
327public:
328
329
331protected:
333public:
334
335 };
336
339
340public:
342 string name;
343
345 string src;
346
348 constructor(string n_name, string n_src);
349
350
351 list<hash<auto>> getTypeList();
352
353
354 list<string> getModifySql(PgsqlType old, *hash opt);
355
356
358 string getCreateSql(*hash opt);
359
360
362
364 string getDropSql(*hash opt);
365
366
368
371 string getRenameSql(string new_name, *hash opt);
372
373
375 bool equal(PgsqlType type);
376
377 };
378
381
382public:
384 *string tablespace;
385
387 constructor(string n_name, bool n_unique, hash n_cols, *string n_tablespace) ;
388
389
391 string getCreateSql(string table_name, *hash opt);
392
393
395 string getDropSql(string table_name);
396
397
399protected:
400 bool equalImpl(AbstractIndex ix);
401public:
402
403
405 string getRenameSql(string table_name, string new_name);
406
407
408 };
409
412
413public:
415 constructor(string n, Columns c, ForeignConstraintTarget t) ;
416
417
419 string getCreateSql(string table_name, *hash opt);
420
421
423 string getDropSql(string table_name);
424
425
426 softlist getRenameSql(string table_name, string new_name);
427
428
430 string getCreateSql(string name, string table_name, *hash<auto> opt);
431
432 };
433
436
437public:
439 constructor(string n, string n_src) ;
440
441
443 string getCreateSql(string table_name, *hash opt);
444
445
446 list getRenameSql(string table_name, string new_name);
447
448
450 string getCreateSql(string name, string table_name, *hash opt);
451
452 };
453
456
457public:
460
462protected:
464public:
465
466
468 constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, softint bs, *int scale)
469 ;
470
471
474
475
477
484 list getAddColumnSql(AbstractTable t);
485
486
488
504 list getModifySqlImpl(AbstractTable t, AbstractColumn col, *hash opt);
505
506
508
518 string getRenameSql(AbstractTable t, string new_name);
519
520
522
524 string getDdlName(string name);
525
526
528protected:
529 bool equalImpl(AbstractColumn c);
530public:
531
532 };
533
536
537public:
539 constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, softint bs,
540 softint scale) ;
541
542
545
546 };
547
550
551public:
552protected:
554 *string tablespace;
555
556public:
557
559 constructor(*string ts);
560
561
563 *string getTablespace();
564
565
567 setTablespace(*string ts);
568
569
571 bool setIndexBase(string ix);
572
573
576
577
579 getIndexSql(reference<string> sql, string name, *hash opts);
580
581 };
582
585
586public:
587protected:
590
591public:
592
594
599 constructor(string n, hash n_cols, bool e = True, *string ts)
600 ;
601
602
604
620
621
623 string getCreateSql(string table_name, *hash opts);
624
625
626 list<auto> getRenameSql(string table_name, string new_name);
627
628
630 string getCreateSql(string name, string table_name, *hash<auto> opts);
631
632
634 bool isEnabled();
635
636 };
637
640
641public:
644
645
647
651 constructor(string n, *hash c, *string ts) ;
652
653
655
671
672
674 string getCreateSql(string table_name, *hash<auto> opts);
675
676
678 softlist getRenameSql(string table_name, string new_name);
679
680 };
681
684
685public:
687 constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_end)
688 ;
689
690
692 string getCreateSql(*hash opt);
693
694
696
700 softlist getRenameSql(string new_name, *hash opt);
701
702 };
703
706
707public:
709 *string viewowner;
710
712 constructor(string n_name, string n_src, *string n_schemaname,
713 *string n_viewowner)
714 ;
715
716
718 string getCreateSql(*hash opt);
719
720
722
726 softlist getRenameSql(string new_name, *hash opt);
727
728 };
729
732
733public:
735 constructor(string n, string n_src) ;
736
737
739 softlist<string> getCreateSql(string table_name, *hash opt);
740
741
743 softlist<string> getDropSql(string table_name);
744
745
747protected:
748 bool equalImpl(AbstractFunctionBase t);
749public:
750
751
753 softlist<string> getRenameSql(string table_name, string new_name);
754
755
757 string getNormalizedSource(string src);
758
759 };
760
763
764public:
765 *string args;
766
767 constructor(string n, string n_src, *string a) ;
768
769
771 softlist<string> getCreateSql(*hash opt);
772
773
775
778 string getDropSql(*hash opt);
779
780
782protected:
783 bool equalImpl(AbstractFunctionBase t);
784public:
785
786
788
791 softlist<string> getRenameSql(string new_name, *hash opt);
792
793
795 setName(string new_name);
796
797 };
798
801
802public:
804 string trigger;
805
806 constructor(string n, string n_src, string n_trigger) ;
807
808 };
809
812
813public:
816
817
818 const PGSQL_TempSavepoint = "qore_pgsql_tmp_savepoint";
819
822
823
826 "all": True,
827 "analyse": True,
828 "analyze": True,
829 "and": True,
830 "any": True,
831 "as": True,
832 "asc": True,
833 "authorization": True,
834 "between": True,
835 "binary": True,
836 "both": True,
837 "case": True,
838 "cast": True,
839 "check": True,
840 "collate": True,
841 "column": True,
842 "constraint": True,
843 "create": True,
844 "cross": True,
845 "currentdate": True,
846 "currenttime": True,
847 "currenttimestamp": True,
848 "currentuser": True,
849 "default": True,
850 "deferrable": True,
851 "desc": True,
852 "distinct": True,
853 "do": True,
854 "else": True,
855 "end": True,
856 "except": True,
857 "false": True,
858 "for": True,
859 "foreign": True,
860 "freeze": True,
861 "from": True,
862 "full": True,
863 "grant": True,
864 "group": True,
865 "having": True,
866 "ilike": True,
867 "in": True,
868 "initially": True,
869 "inner": True,
870 "intersect": True,
871 "into": True,
872 "is": True,
873 "isnull": True,
874 "join": True,
875 "leading": True,
876 "left": True,
877 "like": True,
878 "limit": True,
879 "localtime": True,
880 "localtimestamp": True,
881 "natural": True,
882 "new": True,
883 "not": True,
884 "notnull": True,
885 "null": True,
886 "off": True,
887 "offset": True,
888 "old": True,
889 "on": True,
890 "only": True,
891 "or": True,
892 "order": True,
893 "outer": True,
894 "overlaps": True,
895 "placing": True,
896 "primary": True,
897 "references": True,
898 "right": True,
899 "select": True,
900 "sessionuser": True,
901 "similar": True,
902 "some": True,
903 "table": True,
904 "then": True,
905 "to": True,
906 "trailing": True,
907 "true": True,
908 "union": True,
909 "unique": True,
910 "user": True,
911 "using": True,
912 "verbose": True,
913 "when": True,
914 "where": True,
915 };
916
917 constructor(AbstractDatasource nds, *hash opts) ;
918
919
920protected:
921 list<string> featuresImpl();
922public:
923
924
925 PgsqlType makeType(string name, string src, *hash opts);
926
927
928 *PgsqlType getType(string name);
929
930
931protected:
932 PgsqlSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
933public:
934
935
936protected:
937 *AbstractSequence getSequenceImpl(string name);
938public:
939
940
941protected:
942 *AbstractView getViewImpl(string name);
943public:
944
945
946protected:
947 PgsqlFunction makeFunctionImpl(string name, string src, *hash opts);
948public:
949
950
951protected:
952 PgsqlFunction makeProcedureImpl(string name, string src, *hash opts);
953public:
954
955
956protected:
957 *AbstractFunction getFunctionImpl(string name);
958public:
959
960
961protected:
962 AbstractFunction getProcedureImpl(string name);
963public:
964
965
966 static *string getFunctionArgs(string err, reference<string> src);
967
968 static PgsqlFunction processFunction(hash<auto> row, bool native_case);
969
970protected:
971 list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
972public:
973
974
975protected:
976 list getAlignSqlImpl(hash schema_hash, *hash opt);
977public:
978
979
981protected:
982 list<string> listTablesImpl();
983public:
984
985
987
991protected:
992 list<string> listFunctionsImpl();
993public:
994
995
997
999protected:
1000 list<string> listProceduresImpl();
1001public:
1002
1003
1004protected:
1005 list<string> listSequencesImpl();
1006public:
1007
1008
1009protected:
1010 list<string> listViewsImpl();
1011public:
1012
1013
1016
1017
1020
1021
1023 list<string> listTypes();
1024
1025
1027 ListIterator typeIterator();
1028
1029
1031protected:
1032 string getCreateSqlImpl(list l);
1033public:
1034
1035
1037 static string getCreateSql(list l);
1038
1040protected:
1042public:
1043
1044
1046protected:
1048public:
1049
1050
1052protected:
1053 softint getNextSequenceValueImpl(string name);
1054public:
1055
1056
1058protected:
1059 softint getCurrentSequenceValueImpl(string name);
1060public:
1061
1062
1064protected:
1066public:
1067
1068
1070protected:
1072public:
1073
1074
1076protected:
1078public:
1079
1080
1082protected:
1083 bool rebuildIndexImpl(string name, *hash options);
1084public:
1085
1086
1088protected:
1090public:
1091
1092
1094protected:
1095 reclaimSpaceImpl(*hash options);
1096public:
1097
1098
1099protected:
1100 *string getDbName();
1101public:
1102
1103
1105protected:
1107public:
1108
1109
1111protected:
1112 auto tryExecArgsImpl(string sql, *softlist<auto> args);
1113public:
1114
1115
1117protected:
1118 auto tryExecRawImpl(string sql, *softlist<auto> args);
1119public:
1120
1121
1123 static auto tryExecArgs(AbstractDatasource ds, string sql, *softlist<auto> args);
1124
1126 static auto tryExecRaw(AbstractDatasource ds, string sql);
1127 };
1128
1131
1132public:
1134 const PgsqlTypeMap = ...;
1135
1136
1138 const PgsqlNameMap = ...;
1139
1140
1142 const QoreTypeMap = ...;
1143
1144
1146
1149
1150
1151 const PgsqlColumnDescOptions = AbstractTable::ColumnDescOptions;
1152
1153 const PgsqlIndexOptions = AbstractTable::IndexOptions;
1154
1155 const PgsqlConstraintOptions = ...;
1156
1157
1158 const PgsqlTableCreationOptions = ...;
1159
1160
1161 const PgsqlAlignTableOptions = AbstractTable::AlignTableOptions + PgsqlTableCreationOptions;
1162
1164 const PgsqlExpressionMap = DefaultExpressionMap + {
1165 COP_CAST: {
1166 "exp": <DataProviderExpressionInfo>{
1167 "type": DET_Operator,
1168 "label": COP_CAST,
1169 "name": "cast",
1170 "desc": "cast operator",
1171 "symbol": "cast",
1172 "args": (
1173 DataProviderSignatureAnyType,
1174 DataProviderSignatureStringValueType,
1175 DataProviderSignatureOptionalIntValueType,
1176 DataProviderSignatureOptionalIntValueType,
1177 ),
1178 "return_type": AbstractDataProviderTypeMap."any",
1179 },
1180 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1181 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1182 AbstractDataProviderTypeMap."any");
1183 string name = QoreTypeMap{args[1]} ?? args[1];
1184 *hash<auto> desc = PgsqlTypeMap{name};
1185 string sql = sprintf ("cast (%s as %s", exp0, name);
1186 if (desc.size == SZ_MAND) {
1187 if (!exists args[1] && !exists desc.size_range)
1188 throw "OPERATOR-ERROR", sprintf ("cast operator missing size for type %s",
1189 name);
1190 sql += sprintf("(%d)", args[1] ?? desc.size_range[1]);
1191 } else if (desc.size == SZ_NUM && exists args[1]) {
1192 sql += sprintf("(%d", args[1]);
1193 sql += exists args[2] ? sprintf(",%d)", args[2]) : ")";
1194 } else if (desc.size == SZ_OPT && exists args[1]) {
1195 sql += sprintf("(%d)", args[1]);
1196 }
1197 sql += ")";
1198 return sql;
1199 },
1200 },
1201 COP_YEAR: {
1202 "exp": <DataProviderExpressionInfo>{
1203 "type": DET_Operator,
1204 "label": COP_YEAR,
1205 "name": COP_YEAR,
1206 "desc": "returns the year component of a date as a string (ex: `2022`)",
1207 "symbol": COP_YEAR,
1208 "args": (
1209 DataProviderSignatureDateType,
1210 ),
1211 "return_type": AbstractDataProviderTypeMap."string",
1212 },
1213 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1214 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1215 AbstractDataProviderTypeMap."date");
1216 return sprintf("to_char(%s, 'YYYY')", exp0);
1217 }
1218 },
1219 COP_YEAR_MONTH: {
1220 "exp": <DataProviderExpressionInfo>{
1221 "type": DET_Operator,
1222 "label": COP_YEAR_MONTH,
1223 "name": COP_YEAR_MONTH,
1224 "desc": "returns the year and month components of a date as a string (ex: `2022-06`)",
1225 "symbol": COP_YEAR_MONTH,
1226 "args": (
1227 DataProviderSignatureDateType,
1228 ),
1229 "return_type": AbstractDataProviderTypeMap."string",
1230 },
1231 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1232 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1233 AbstractDataProviderTypeMap."date");
1234 return sprintf("to_char(%s, 'YYYY-MM')", exp0);
1235 }
1236 },
1237 COP_YEAR_DAY: {
1238 "exp": <DataProviderExpressionInfo>{
1239 "type": DET_Operator,
1240 "label": COP_YEAR_DAY,
1241 "name": COP_YEAR_DAY,
1242 "desc": "returns the year, month, and day components of a date as a string (ex: `2022-06-29`)",
1243 "symbol": COP_YEAR_DAY,
1244 "args": (
1245 DataProviderSignatureDateType,
1246 ),
1247 "return_type": AbstractDataProviderTypeMap."string",
1248 },
1249 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1250 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1251 AbstractDataProviderTypeMap."date");
1252 return sprintf("to_char(%s, 'YYYY-MM-DD')", exp0);
1253 }
1254 },
1255 COP_YEAR_HOUR: {
1256 "exp": <DataProviderExpressionInfo>{
1257 "type": DET_Operator,
1258 "label": COP_YEAR_HOUR,
1259 "name": COP_YEAR_HOUR,
1260 "desc": "returns the year, month, day, and hour components of a date as a string "
1261 "(ex: `2022-06-29 15`)",
1262 "symbol": COP_YEAR_HOUR,
1263 "args": (
1264 DataProviderSignatureDateType,
1265 ),
1266 "return_type": AbstractDataProviderTypeMap."string",
1267 },
1268 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1269 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1270 AbstractDataProviderTypeMap."date");
1271 return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", exp0);
1272 }
1273 },
1274 COP_TRUNC_DATE: {
1275 "exp": <DataProviderExpressionInfo>{
1276 "type": DET_Operator,
1277 "label": COP_TRUNC_DATE,
1278 "name": COP_TRUNC_DATE,
1279 "desc": "truncates the given date to the given resolution; args: date, string code: Y: year, "
1280 "M: month, D: day, H: hour, m: minute, S: second",
1281 "symbol": COP_TRUNC_DATE,
1282 "args": (
1283 DataProviderSignatureDateType,
1284 DataProviderSignatureStringValueType,
1285 ),
1286 "return_type": AbstractDataProviderTypeMap."date",
1287 },
1288 "code": string sub(reference<hash<QueryInfo>> info, int role, list<auto> args) {
1289 *string str = PgsqlTruncDate{args[1]};
1290 if (!str) {
1291 throw "TRUNC-DATE-ERROR", sprintf("unknown date truncation format argument %y; "
1292 "supported date format arguments: %y", args[1], keys PgsqlTruncDate);
1293 }
1294 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1295 AbstractDataProviderTypeMap."date");
1296 return sprintf("date_trunc(%s, %s)", str, exp0);
1297 },
1298 },
1299 COP_SEQ: {
1300 "exp": <DataProviderExpressionInfo>{
1301 "type": DET_Operator,
1302 "label": COP_SEQ,
1303 "name": COP_SEQ,
1304 "desc": "returns the next value in the given sequence; args: sequence name",
1305 "symbol": COP_SEQ,
1306 "args": (
1307 DataProviderSignatureStringValueType,
1308 ),
1309 "return_type": AbstractDataProviderTypeMap."int",
1310 },
1311 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1312 return sprintf("nextval('%s')", args[0]);
1313 }
1314 },
1315 COP_SEQ_CURRVAL: {
1316 "exp": <DataProviderExpressionInfo>{
1317 "type": DET_Operator,
1318 "label": COP_SEQ_CURRVAL,
1319 "name": COP_SEQ_CURRVAL,
1320 "desc": "returns the current value in the given sequence; args: sequence name",
1321 "symbol": COP_SEQ_CURRVAL,
1322 "args": (
1323 DataProviderSignatureStringValueType,
1324 ),
1325 "return_type": AbstractDataProviderTypeMap."int",
1326 },
1327 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1328 return sprintf("currval('%s')", args[0]);
1329 }
1330 },
1331 };
1332
1334 const PgsqlCopMap = {
1335 COP_CAST: (
1336 "code": string sub (string cve, list<auto> args) {
1337 string name = QoreTypeMap{args[0]} ?? args[0];
1338 hash desc = PgsqlTypeMap{name};
1339 string sql = sprintf ("cast (%s as %s", cve, name);
1340 switch (name) {
1341 default:
1342 if (desc.size == SZ_MAND) {
1343 if (!exists args[1] && !exists desc.size_range)
1344 throw "OPERATOR-ERROR", sprintf ("op_cast operator missing size for type %s",
1345 name);
1346 sql += sprintf("(%d)", args[1] ?? desc.size_range[1]);
1347 } else if (desc.size == SZ_NUM && exists args[1]) {
1348 sql += sprintf("(%d", args[1]);
1349 sql += exists args[2] ? sprintf(",%d)", args[2]) : ")";
1350 } else if (desc.size == SZ_OPT && exists args[1]) {
1351 sql += sprintf("(%d)", args[1]);
1352 }
1353 }
1354 sql += ")";
1355 return sql;
1356 },
1357 ),
1358 COP_YEAR: (
1359 "code": string sub (string arg1, auto arg) {
1360 return sprintf("to_char(%s, 'YYYY')", arg1);
1361 }
1362 ),
1363 COP_YEAR_MONTH: (
1364 "code": string sub (string arg1, auto arg) {
1365 return sprintf("to_char(%s, 'YYYY-MM')", arg1);
1366 }
1367 ),
1368 COP_YEAR_DAY: (
1369 "code": string sub (string arg1, auto arg) {
1370 return sprintf("to_char(%s, 'YYYY-MM-DD')", arg1);
1371 }
1372 ),
1373 COP_YEAR_HOUR: (
1374 "code": string sub (string arg1, auto arg) {
1375 return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", arg1);
1376 }
1377 ),
1378 COP_SEQ: (
1379 "nocolumn": True,
1380 "withalias": True,
1381 "code": string sub (*string cve, hash arg, reference<hash> psch) {
1382 string sql = sprintf("nextval('%s')", arg.seq);
1383 if (arg.as) {
1384 psch{arg.as} = sql;
1385 sql += " " + arg.as;
1386 }
1387 return sql;
1388 }
1389 ),
1390 COP_SEQ_CURRVAL: (
1391 "nocolumn": True,
1392 "withalias": True,
1393 "code": string sub (*string cve, hash arg, reference<hash> psch) {
1394 string sql = sprintf("currval('%s')", arg.seq);
1395 if (arg.as) {
1396 psch{arg.as} = sql;
1397 sql += " " + arg.as;
1398 }
1399 return sql;
1400 }
1401 ),
1402 COP_TRUNC_DATE: (
1403 "code": string sub(string arg1, auto arg) {
1404 if (!PgsqlTruncDate.hasKey(arg)) {
1405 throw "COP-TRUNC-DATE-ERROR", sprintf("Not allowed format argument: %n: allowed: %n", arg,
1406 PgsqlTruncDate.keys());
1407 }
1408 return sprintf("date_trunc(%s, %s)", PgsqlTruncDate{arg}, arg1);
1409 }
1410 ),
1411 };
1412
1414 const PgsqlTruncDate = ...;
1415
1416
1418 const PgsqlIopMap = ...;
1419
1420
1422 const PgsqlUopMap = ...;
1423
1424
1425protected:
1427 *string tablespace;
1428
1430 string schema;
1431
1434
1437
1440
1443
1446
1449
1451 transient Mutex pg_state();
1452
1453public:
1454
1456 constructor(AbstractDatasource nds, string nname, *hash opts) ;
1457
1458
1461
1462
1465
1466
1467 PgsqlFunction addTriggerFunction(string tfname, string src, string trigger);
1468
1469
1472
1473
1475 string getColumnSqlName(string col);
1476
1477
1479
1481 list<auto> getColumnSqlNames(softlist<auto> cols);
1482
1483
1485
1489 code getUpsertClosure(hash<auto> row, int upsert_strategy = UpsertAuto, *hash<auto> opt);
1490
1491
1494
1495
1497protected:
1499public:
1500
1501
1502protected:
1503 code getUpsertAuto(Columns cols, hash<auto> row, *hash<auto> opt);
1504public:
1505
1506
1507protected:
1508 PgsqlFunction addTriggerFunctionUnlocked(string tfname, string src, string trigger);
1509public:
1510
1511
1513 string getSqlName();
1514
1515
1516protected:
1517 hash getTableCreationOptions();
1518public:
1519
1520
1521protected:
1522 hash getTableDescriptionHashOptions();
1523public:
1524
1525
1526protected:
1527 hash getColumnDescOptions();
1528public:
1529
1530
1531protected:
1532 hash getIndexOptions();
1533public:
1534
1535
1536protected:
1537 hash getConstraintOptions();
1538public:
1539
1540
1541protected:
1542 hash getAlignTableOptions();
1543public:
1544
1545
1547protected:
1549public:
1550
1551
1553protected:
1555public:
1556
1557
1559protected:
1561public:
1562
1563
1565 hash<auto> getExpressionMap();
1566
1567
1568protected:
1569 bool checkExistenceImpl();
1570public:
1571
1572
1573protected:
1574 Columns describeImpl();
1575public:
1576
1577
1578protected:
1579 PgsqlPrimaryKey getPrimaryKeyImpl();
1580public:
1581
1582
1583protected:
1584 Indexes getIndexesImpl();
1585public:
1586
1587
1588protected:
1589 ForeignConstraints getForeignConstraintsImpl(*hash opts);
1590public:
1591
1592
1593protected:
1594 Constraints getConstraintsImpl();
1595public:
1596
1597
1598protected:
1599 Triggers getTriggersImpl();
1600public:
1601
1602
1604protected:
1605 string getCreateTableSqlImpl(*hash opt);
1606public:
1607
1608
1609protected:
1610 *list getCreateMiscSqlImpl(*hash opt, bool cache);
1611public:
1612
1613
1614protected:
1615 *list getAlignSqlImpl(AbstractTable table, *hash<auto> opt);
1616public:
1617
1618
1620protected:
1621 string getCreateSqlImpl(list l);
1622public:
1623
1624
1625protected:
1626 string getRenameSqlImpl(string new_name);
1627public:
1628
1629
1630protected:
1631 AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
1632public:
1633
1634
1635protected:
1636 AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
1637public:
1638
1639
1640protected:
1641 AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
1642public:
1643
1644
1645 private AbstractForeignConstraint addForeignConstraintImpl(string cname, hash<auto> ch, string table,
1646 hash<auto> tch, *hash<auto> opt) {
1647 ForeignConstraintTarget fct(table, new Columns(tch));
1648 return new PgsqlForeignConstraint(cname, new Columns(ch), fct);
1649 }
1650
1651protected:
1652 AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
1653public:
1654
1655
1656protected:
1657 AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
1658public:
1659
1660
1661protected:
1662 AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
1663public:
1664
1665
1666protected:
1667 bool tryInsertImpl(string sql, hash<auto> row);
1668public:
1669
1670
1672
1674protected:
1675 bool isDuplicateRowErrorImpl(hash<ExceptionInfo> ex);
1676public:
1677
1678
1679protected:
1680 hash<auto> getQoreTypeMapImpl();
1681public:
1682
1683
1684protected:
1685 hash<auto> getTypeMapImpl();
1686public:
1687
1688
1690
1692protected:
1693 *string getSqlValueImpl(auto v);
1694public:
1695
1696
1697protected:
1698 bool emptyImpl();
1699public:
1700
1701
1703protected:
1705public:
1706
1707
1708protected:
1709 softlist getDropSqlImpl();
1710public:
1711
1712
1713protected:
1714 setupTableImpl(hash<auto> desc, *hash<auto> opt);
1715public:
1716
1717
1719protected:
1721public:
1722
1723
1725protected:
1727public:
1728
1729
1731protected:
1733public:
1734
1735
1737protected:
1738 doSelectLimitOnlyUnlockedImpl(reference<hash<QueryInfo>> info, reference<string> sql);
1739public:
1740
1741
1743 private doSelectOrderByWithOffsetSqlUnlockedImpl(reference<hash<QueryInfo>> info, reference<string> sql,
1744 list<auto> coll) {
1745 doSelectOrderBySqlUnlocked(info, \sql, coll);
1746 if (info.query_hash.limit);
1747
1748
1749 if (info.query_hash.offset);
1750
1751 }
1752
1754protected:
1755 auto tryExecArgsImpl(string sql, *softlist<auto> args);
1756public:
1757
1758
1760protected:
1761 auto tryExecRawImpl(string sql, *softlist<auto> args);
1762public:
1763
1764
1766protected:
1767 copyImpl(AbstractTable old);
1768public:
1769
1770
1771protected:
1772 *hash<auto> doReturningImpl(hash<auto> opt, reference<string> sql, list<auto> args);
1773public:
1774
1775
1776protected:
1777 list<auto> getGroupOrderByListUnlocked(hash<QueryInfo> info, string key, list<auto> coll);
1778public:
1779
1780
1782protected:
1783 AbstractDataProviderType getNumericTypeImpl(string native_type, bool nullable, *hash<auto> options);
1784public:
1785
1786
1788
1792protected:
1793 AbstractSavepointHelper getSavepointHelperImpl(*string savepoint);
1794public:
1795
1796 };
1797};
represents a PostgreSQL-specific check constraint
Definition: PgsqlSqlUtilBase.qm.dox.h:435
string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the constraint in the database
constructor(string n, string n_src)
creates the constraint from the supplied arguments
string getCreateSql(string name, string table_name, *hash opt)
returns a string that can be used to create the constraint in the database
represents a PostgreSQL-specific column
Definition: PgsqlSqlUtilBase.qm.dox.h:455
int byte_size
byte size of the column
Definition: PgsqlSqlUtilBase.qm.dox.h:459
constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, softint bs, *int scale)
creates the column from the supplied arguments
string getNativeTypeString()
returns a string giving the native type of the column
constructor()
empty constructor for subclasses
string getRenameSql(AbstractTable t, string new_name)
returns a string that can be used to rename the column
list getModifySqlImpl(AbstractTable t, AbstractColumn col, *hash opt)
returns a list of sql strings that can be used to modify the column to the new definition
list getAddColumnSql(AbstractTable t)
returns a list of sql strings that can be used to add the column to an existing table
string getDdlName(string name)
returns the column name with quoting in case the column name is a reserved word
bool equalImpl(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
provides the PostgreSQL-specific implementation of the AbstractDatabase interface
Definition: PgsqlSqlUtilBase.qm.dox.h:811
auto tryExecRawImpl(string sql, *softlist< auto > args)
tries to execute a command so that if an error occurs the current transaction status is not lost
ListIterator materializedViewIterator()
returns an iterator listing the string materialized view names in the database
const PgsqlReservedWords
hash (set) of reserved words
Definition: PgsqlSqlUtilBase.qm.dox.h:825
ListIterator typeIterator()
returns an iterator listing the string type names in the database
hash getSchemaDescriptionOptions()
returns driver-specific options to the base abstract class
const PgsqlReclaimSpaceOptions
Options for reclaimSpace()
Definition: PgsqlSqlUtilBase.qm.dox.h:821
list< string > listFunctionsImpl()
returns a list of string function names in the database
bool supportsTypesImpl()
returns True if the database supports named types
list< string > listTablesImpl()
returns a list of string table names in the database
list< string > listMaterializedViews()
returns a list of string materialized view names in the database
reclaimSpaceImpl(*hash options)
reclaim space implementation. See SqlUtil::AbstractDatabase::reclaimSpace()
bool rebuildIndexImpl(string name, *hash options)
rebuild index implementation. See SqlUtil::AbstractDatabase::rebuildIndex()
list< string > listProceduresImpl()
since PostgreSQL only supports functions, this method is identical to listFunctionsImpl()
auto tryExecArgsImpl(string sql, *softlist< auto > args)
tries to execute a command so that if an error occurs the current transaction status is not lost
softint getNextSequenceValueImpl(string name)
returns the next value in the given sequence
static string getCreateSql(list l)
returns a string that can be used to create the schema in the database
int getPhysicalSizeImpl()
SqlUtil::AbstractDatabase::getPhysicalSize()
bool supportsSequencesImpl()
returns True if the database supports sequences
hash getReclaimSpaceOptions()
returns driver-specific options to the base abstract class
string getCreateSqlImpl(list l)
returns a string that can be used to create the schema in the database
bool supportsPackagesImpl()
returns True if the database supports packages
const PgsqlSchemaDescriptionOptions
PostgreSQL-specific schema description keys.
Definition: PgsqlSqlUtilBase.qm.dox.h:815
static auto tryExecRaw(AbstractDatasource ds, string sql)
tries to execute a command so that if an error occurs the current transaction status is not lost
computeStatisticsImpl(*hash options)
compute statistics implementation. See SqlUtil::AbstractDatabase::computeStatistics()
static auto tryExecArgs(AbstractDatasource ds, string sql, *softlist< auto > args)
tries to execute a command so that if an error occurs the current transaction status is not lost
softint getCurrentSequenceValueImpl(string name)
returns the last value issued for the given sequence in the current session
list< string > listTypes()
returns a list of string type names in the database
represents a PostgreSQL-specific foreign constraint
Definition: PgsqlSqlUtilBase.qm.dox.h:411
string getDropSql(string table_name)
returns a string that can be used to drop the constraint from the database
string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the constraint in the database
constructor(string n, Columns c, ForeignConstraintTarget t)
creates the constraint from the supplied arguments
string getCreateSql(string name, string table_name, *hash< auto > opt)
returns a string that can be used to create the constraint in the database
represents a PostgreSQL-specific function
Definition: PgsqlSqlUtilBase.qm.dox.h:762
setName(string new_name)
sets the new name of the function
string getDropSql(*hash opt)
returns a string that can be used to drop the function from the database
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
softlist< string > getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename the function in the database
softlist< string > getCreateSql(*hash opt)
returns a string that can be used to create the function in the database
represents a PostgreSQL-specific index
Definition: PgsqlSqlUtilBase.qm.dox.h:380
constructor(string n_name, bool n_unique, hash n_cols, *string n_tablespace)
creates the object from the arguments
*string tablespace
the tablespace name of the index
Definition: PgsqlSqlUtilBase.qm.dox.h:384
bool equalImpl(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database
string getDropSql(string table_name)
returns a string that can be used to drop the index from the database
string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the index in the database
the data type for PostgreSQL NUMBER columns
Definition: PgsqlSqlUtilBase.qm.dox.h:299
constructor(string native_type, bool nullable, *hash< auto > options)
creates the object
represents a PostgreSQL-specific numeric column
Definition: PgsqlSqlUtilBase.qm.dox.h:535
string getNativeTypeString()
returns a string giving the native type of the column
constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, softint bs, softint scale)
creates the column from the supplied arguments
represents a PostgreSQL-specific primary key constraint
Definition: PgsqlSqlUtilBase.qm.dox.h:639
softlist getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the constraint
string getCreateSql(string table_name, *hash< auto > opts)
returns a string that can be used to create the constraint
PgsqlColumn memberGate(string k)
returns the PgsqlColumn value of the given key if it exists, otherwise throws a KEY-ERROR exception
constructor(string n, *hash c, *string ts)
creates the object with the given attributes
constructor()
creates an empty primary key object
PostgreSQL savepoint helper.
Definition: PgsqlSqlUtilBase.qm.dox.h:311
constructor(AbstractDatasource ds, *string savepoint)
Creates the object.
deleteSavepointImpl()
Deletes the savepoint.
createSavepointImpl()
Creates the savepoint.
rollbackImpl()
Rolls back to the savepoint.
class for PostgreSQL sequences
Definition: PgsqlSqlUtilBase.qm.dox.h:683
constructor(string n_name, number n_start=1, number n_increment=1, *softnumber n_end)
creates the object from the arguments
string getCreateSql(*hash opt)
returns a string that can be used to create the sequence in the database
softlist getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename the sequence in the database
provides the PostgreSQL-specific implementation of the SqlUtil::AbstractTable interface
Definition: PgsqlSqlUtilBase.qm.dox.h:1130
const PgsqlNameMap
maps from verbose type names to simple type names
Definition: PgsqlSqlUtilBase.qm.dox.h:1138
copyImpl(AbstractTable old)
db-specific copy actions
int server_version_sub
PostgreSQL server version.
Definition: PgsqlSqlUtilBase.qm.dox.h:1448
hash< auto > getExpressionMap()
Returns the expression map for PostgreSQL.
const PgsqlIopMap
a hash of default value operator descriptions for PostgreSQL
Definition: PgsqlSqlUtilBase.qm.dox.h:1418
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifiers for schema,...
bool isDuplicateRowErrorImpl(hash< ExceptionInfo > ex)
Returns True if the exception was raised because of a duplicate row / key error.
const PgsqlUopMap
a hash of default update operator definitions for PostgreSQL
Definition: PgsqlSqlUtilBase.qm.dox.h:1422
hash getInsertOperatorMap()
returns the insert operator map for this object
bool has_atomic_merge
Set based on the postgreSQL server version.
Definition: PgsqlSqlUtilBase.qm.dox.h:1436
int server_version_major
PostgreSQL server major version.
Definition: PgsqlSqlUtilBase.qm.dox.h:1442
constructor(AbstractDatasource nds, string nname, *hash opts)
Creates the object from the arguments.
doSelectLimitOnlyUnlockedImpl(reference< hash< QueryInfo > > info, reference< string > sql)
processes a string for use in SQL select statements when there is a "limit" argument,...
private doSelectOrderByWithOffsetSqlUnlockedImpl(reference< hash< QueryInfo > > info, reference< string > sql, list< auto > coll)
processes a string for use in SQL select statements when there is an "order by" and "offset" argument
Definition: PgsqlSqlUtilBase.qm.dox.h:1743
auto tryExecArgsImpl(string sql, *softlist< auto > args)
tries to execute a command so that if an error occurs the current transaction status is not lost
AbstractDataProviderType getNumericTypeImpl(string native_type, bool nullable, *hash< auto > options)
returns the type for number / numeric columns for the database so that data conversions can be handle...
const PgsqlCopMap
column operator specializations for PostgreSQL
Definition: PgsqlSqlUtilBase.qm.dox.h:1334
string getSchemaName()
returns the schema name
bool hasArrayBind()
returns False because the pgsql driver does not support array binds / bulk DML operations
const PgsqlTableDescriptionHashOptions
extends SqlUtil::AbstractTable::TableDescriptionHashOptions with "functions"
Definition: PgsqlSqlUtilBase.qm.dox.h:1148
string getColumnSqlName(string col)
returns the column name for use in SQL strings; subclasses can return a special string in case the co...
string getCreateSqlImpl(list l)
returns a string that can be used to create the table in the database
bool supportsTablespacesImpl()
returns True if the database support tablespaces
string getCreateTableSqlImpl(*hash opt)
returns a string that can be used to create the table in the database
int server_version_minor
PostgreSQL server minor version.
Definition: PgsqlSqlUtilBase.qm.dox.h:1445
const PgsqlTypeMap
maps PostgreSQL type names to type configurations
Definition: PgsqlSqlUtilBase.qm.dox.h:1134
AbstractSavepointHelper getSavepointHelperImpl(*string savepoint)
get DB-specific savepoint helper
string schema
schema name for the table
Definition: PgsqlSqlUtilBase.qm.dox.h:1430
transient Mutex pg_state()
Lock for atomicity for setting state info.
clearImpl()
clears PostgreSQL-specific table information
bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
code getUpsertClosure(hash< auto > row, int upsert_strategy=UpsertAuto, *hash< auto > opt)
returns a closure for performing upserts
getServerVersion()
Sets the internal PostgreSQL server version.
auto tryExecRawImpl(string sql, *softlist< auto > args)
tries to execute a command so that if an error occurs the current transaction status is not lost
*string getSqlValueImpl(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument
const PgsqlTruncDate
Map SqlUtil::cop_trunc_date() constants to PostgreSQL internal masks.
Definition: PgsqlSqlUtilBase.qm.dox.h:1414
bool hasAtomicUpsert()
Returns True if the server supports atomic upsert/merge operations.
*string getTablespaceName()
returns the data tablespace name for the table or NOTHING if none is known
int server_version
PostgreSQL server full version code.
Definition: PgsqlSqlUtilBase.qm.dox.h:1439
list< auto > getColumnSqlNames(softlist< auto > cols)
returns a list of column names for use in SQL strings
hash getColumnOperatorMapImpl()
returns the column operator map for this object
Functions triggerFunctions
contains any trigger functions supporting triggers on the table
Definition: PgsqlSqlUtilBase.qm.dox.h:1433
const QoreTypeMap
maps qore type names to PostgreSQL type names
Definition: PgsqlSqlUtilBase.qm.dox.h:1142
hash getRawUpdateOperatorMap()
returns the raw (default) update operator map for this object
const PgsqlExpressionMap
Expression map for PostgreSQL.
Definition: PgsqlSqlUtilBase.qm.dox.h:1164
*string tablespace
tablespace name for the table, if known
Definition: PgsqlSqlUtilBase.qm.dox.h:1427
represents a PostgreSQL-specific trigger function
Definition: PgsqlSqlUtilBase.qm.dox.h:800
string trigger
trigger name
Definition: PgsqlSqlUtilBase.qm.dox.h:804
represents a PostgreSQL-specific trigger
Definition: PgsqlSqlUtilBase.qm.dox.h:731
softlist< string > getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the trigger in the database
string getNormalizedSource(string src)
returns normalized source for comparisons
softlist< string > getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the trigger in the database
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
constructor(string n, string n_src)
creates the object and sets its name and the trigger source
softlist< string > getDropSql(string table_name)
returns a string that can be used to drop the trigger from the database
represents a PostgreSQL type
Definition: PgsqlSqlUtilBase.qm.dox.h:338
string getDropSql(*hash opt)
returns a string that can be used to drop the function from the database
string name
the name of the type
Definition: PgsqlSqlUtilBase.qm.dox.h:342
string getCreateSql(*hash opt)
returns a string that can be used to create the type in the database
string getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename a type
constructor(string n_name, string n_src)
creates the type from the supplied arguments
string src
the source of the type
Definition: PgsqlSqlUtilBase.qm.dox.h:345
bool equal(PgsqlType type)
returns True if the types are equal
common base class for unique constraints
Definition: PgsqlSqlUtilBase.qm.dox.h:549
bool setIndexBase(string ix)
sets the supporting index name
getIndexSql(reference< string > sql, string name, *hash opts)
adds index options onto the sql creation string
clearIndex()
clears any index base for the constraint
constructor(*string ts)
creates the constraint with an optional tablespace name
setTablespace(*string ts)
sets or clears the tablespace name
*string getTablespace()
returns the tablespace name used for this constraint, if known
*string tablespace
any tablespace for the unique key index
Definition: PgsqlSqlUtilBase.qm.dox.h:554
class modeling a unique constraint
Definition: PgsqlSqlUtilBase.qm.dox.h:584
constructor(string n, hash n_cols, bool e=True, *string ts)
creates the object with the given attributes
bool isEnabled()
returns True if the constraint is enabled, False if not
string getCreateSql(string name, string table_name, *hash< auto > opts)
returns a string that can be used to rename the constraint
PgsqlColumn memberGate(string k)
returns the PgsqlColumn value of the given key if it exists, otherwise throws a KEY-ERROR exception
string getCreateSql(string table_name, *hash opts)
returns a string that can be used to create the constraint
bool enabled
True if the constraint is enabled, False if not
Definition: PgsqlSqlUtilBase.qm.dox.h:589
represents a PostgreSQL view
Definition: PgsqlSqlUtilBase.qm.dox.h:705
softlist getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename the view in the database
constructor(string n_name, string n_src, *string n_schemaname, *string n_viewowner)
creates the object from the arguments
*string viewowner
Owner of the view.
Definition: PgsqlSqlUtilBase.qm.dox.h:709
string getCreateSql(*hash opt)
returns a string that can be used to create the view in the database
transient AbstractDatasource ds
cache(*hash< auto > opts)
the PgsqlSqlUtilBase namespace contains all the objects in the PgsqlSqlUtilBase module
Definition: PgsqlSqlUtilBase.qm.dox.h:289
PgsqlTable get_table(AbstractDatasource nds, string nname, *hash< auto > opts)
returns a PgsqlTable object corresponding to the arguments
PgsqlDatabase get_database(AbstractDatasource nds, *hash< auto > opts)
returns a PgsqlDatabase object corresponding to the arguments