Qore PgsqlSqlUtil Module Reference 1.7.1
Loading...
Searching...
No Matches
PgsqlSqlUtil.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* PgsqlSqlUtil.qm Copyright (C) 2013 - 2022 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
288namespace PgsqlSqlUtil {
290 PgsqlTable get_table(AbstractDatasource nds, string nname, *hash<auto> opts);
291
292
294 PgsqlDatabase get_database(AbstractDatasource nds, *hash<auto> opts);
295
296
299
300public:
302 constructor(string native_type, bool nullable, *hash<auto> options) ;
303
304 };
305
306 parse_schema_name(string nname, reference<string> schema, reference<string> name);
307
308
310class PgsqlSavepointHelper : public AbstractSavepointHelper {
311
312public:
314 constructor(AbstractDatasource ds, *string savepoint) ;
315
316
318protected:
320public:
321
322
324protected:
326public:
327
328
330protected:
332public:
333
334 };
335
338
339public:
341 string name;
342
344 string src;
345
347 constructor(string n_name, string n_src);
348
349
350 list getTypeList();
351
352
353 list getModifySql(PgsqlType old, *hash opt);
354
355
357 string getCreateSql(*hash opt);
358
359
361
363 string getDropSql(*hash opt);
364
365
367
370 string getRenameSql(string new_name, *hash opt);
371
372
374 bool equal(PgsqlType type);
375
376 };
377
380
381public:
383 *string tablespace;
384
386 constructor(string n_name, bool n_unique, hash n_cols, *string n_tablespace) ;
387
388
390 string getCreateSql(string table_name, *hash opt);
391
392
394 string getDropSql(string table_name);
395
396
398protected:
399 bool equalImpl(AbstractIndex ix);
400public:
401
402
404 string getRenameSql(string table_name, string new_name);
405
406
407 };
408
411
412public:
414 constructor(string n, Columns c, ForeignConstraintTarget t) ;
415
416
418 string getCreateSql(string table_name, *hash opt);
419
420
422 string getDropSql(string table_name);
423
424
425 softlist getRenameSql(string table_name, string new_name);
426
427
429 string getCreateSql(string name, string table_name, *hash<auto> opt);
430
431 };
432
435
436public:
438 constructor(string n, string n_src) ;
439
440
442 string getCreateSql(string table_name, *hash opt);
443
444
445 list getRenameSql(string table_name, string new_name);
446
447
449 string getCreateSql(string name, string table_name, *hash opt);
450
451 };
452
455
456public:
459
461protected:
463public:
464
465
467 constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, softint bs, *int scale)
468 ;
469
470
473
474
476
483 list getAddColumnSql(AbstractTable t);
484
485
487
503 list getModifySqlImpl(AbstractTable t, AbstractColumn col, *hash opt);
504
505
507
517 string getRenameSql(AbstractTable t, string new_name);
518
519
521
523 string getDdlName(string name);
524
525
527protected:
528 bool equalImpl(AbstractColumn c);
529public:
530
531 };
532
535
536public:
538 constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, softint bs,
539 softint scale) ;
540
541
544
545 };
546
549
550public:
551protected:
553 *string tablespace;
554
555public:
556
558 constructor(*string ts);
559
560
562 *string getTablespace();
563
564
566 setTablespace(*string ts);
567
568
570 bool setIndexBase(string ix);
571
572
575
576
578 getIndexSql(reference<string> sql, string name, *hash opts);
579
580 };
581
584
585public:
586protected:
589
590public:
591
593
598 constructor(string n, hash n_cols, bool e = True, *string ts)
599 ;
600
601
603
619
620
622 string getCreateSql(string table_name, *hash opts);
623
624
625 list<auto> getRenameSql(string table_name, string new_name);
626
627
629 string getCreateSql(string name, string table_name, *hash<auto> opts);
630
631
633 bool isEnabled();
634
635 };
636
639
640public:
643
644
646
650 constructor(string n, *hash c, *string ts) ;
651
652
654
670
671
673 string getCreateSql(string table_name, *hash<auto> opts);
674
675
677 softlist getRenameSql(string table_name, string new_name);
678
679 };
680
683
684public:
686 constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_end) ;
687
688
690 string getCreateSql(*hash opt);
691
692
694
698 softlist getRenameSql(string new_name, *hash opt);
699
700 };
701
704
705public:
707 *string viewowner;
708
710 constructor(string n_name, string n_src, *string n_schemaname,
711 *string n_viewowner)
712 ;
713
714
716 string getCreateSql(*hash opt);
717
718
720
724 softlist getRenameSql(string new_name, *hash opt);
725
726 };
727
730
731public:
733 constructor(string n, string n_src) ;
734
735
737 softlist getCreateSql(string table_name, *hash opt);
738
739
741 softlist getDropSql(string table_name);
742
743
745protected:
746 bool equalImpl(AbstractFunctionBase t);
747public:
748
749
751 softlist getRenameSql(string table_name, string new_name);
752
753
755 string getNormalizedSource(string src);
756
757 };
758
761
762public:
763 *string args;
764
765 constructor(string n, string n_src, *string a) ;
766
767
769 softlist getCreateSql(*hash opt);
770
771
773
775 string getDropSql(*hash opt);
776
777
779protected:
780 bool equalImpl(AbstractFunctionBase t);
781public:
782
783
785
788 softlist getRenameSql(string new_name, *hash opt);
789
790
792 setName(string new_name);
793
794 };
795
798
799public:
801 string trigger;
802
803 constructor(string n, string n_src, string n_trigger) ;
804
805 };
806
809
810public:
813
814
815 const PGSQL_TempSavepoint = "qore_pgsql_tmp_savepoint";
816
819
820
823 "all": True,
824 "analyse": True,
825 "analyze": True,
826 "and": True,
827 "any": True,
828 "as": True,
829 "asc": True,
830 "authorization": True,
831 "between": True,
832 "binary": True,
833 "both": True,
834 "case": True,
835 "cast": True,
836 "check": True,
837 "collate": True,
838 "column": True,
839 "constraint": True,
840 "create": True,
841 "cross": True,
842 "currentdate": True,
843 "currenttime": True,
844 "currenttimestamp": True,
845 "currentuser": True,
846 "default": True,
847 "deferrable": True,
848 "desc": True,
849 "distinct": True,
850 "do": True,
851 "else": True,
852 "end": True,
853 "except": True,
854 "false": True,
855 "for": True,
856 "foreign": True,
857 "freeze": True,
858 "from": True,
859 "full": True,
860 "grant": True,
861 "group": True,
862 "having": True,
863 "ilike": True,
864 "in": True,
865 "initially": True,
866 "inner": True,
867 "intersect": True,
868 "into": True,
869 "is": True,
870 "isnull": True,
871 "join": True,
872 "leading": True,
873 "left": True,
874 "like": True,
875 "limit": True,
876 "localtime": True,
877 "localtimestamp": True,
878 "natural": True,
879 "new": True,
880 "not": True,
881 "notnull": True,
882 "null": True,
883 "off": True,
884 "offset": True,
885 "old": True,
886 "on": True,
887 "only": True,
888 "or": True,
889 "order": True,
890 "outer": True,
891 "overlaps": True,
892 "placing": True,
893 "primary": True,
894 "references": True,
895 "right": True,
896 "select": True,
897 "sessionuser": True,
898 "similar": True,
899 "some": True,
900 "table": True,
901 "then": True,
902 "to": True,
903 "trailing": True,
904 "true": True,
905 "union": True,
906 "unique": True,
907 "user": True,
908 "using": True,
909 "verbose": True,
910 "when": True,
911 "where": True,
912 };
913
914 constructor(AbstractDatasource nds, *hash opts) ;
915
916
917protected:
918 list<string> featuresImpl();
919public:
920
921
922 PgsqlType makeType(string name, string src, *hash opts);
923
924
925 *PgsqlType getType(string name);
926
927
928protected:
929 PgsqlSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
930public:
931
932
933protected:
934 *AbstractSequence getSequenceImpl(string name);
935public:
936
937
938protected:
939 *AbstractView getViewImpl(string name);
940public:
941
942
943protected:
944 PgsqlFunction makeFunctionImpl(string name, string src, *hash opts);
945public:
946
947
948protected:
949 PgsqlFunction makeProcedureImpl(string name, string src, *hash opts);
950public:
951
952
953protected:
954 *AbstractFunction getFunctionImpl(string name);
955public:
956
957
958protected:
959 AbstractFunction getProcedureImpl(string name);
960public:
961
962
963 static *string getFunctionArgs(string err, reference<string> src);
964
965 static PgsqlFunction processFunction(hash<auto> row, bool native_case);
966
967protected:
968 list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
969public:
970
971
972protected:
973 list getAlignSqlImpl(hash schema_hash, *hash opt);
974public:
975
976
978protected:
979 list<string> listTablesImpl();
980public:
981
982
984
988protected:
989 list<string> listFunctionsImpl();
990public:
991
992
994
996protected:
997 list<string> listProceduresImpl();
998public:
999
1000
1001protected:
1002 list<string> listSequencesImpl();
1003public:
1004
1005
1006protected:
1007 list<string> listViewsImpl();
1008public:
1009
1010
1013
1014
1017
1018
1020 list<string> listTypes();
1021
1022
1024 ListIterator typeIterator();
1025
1026
1028protected:
1029 string getCreateSqlImpl(list l);
1030public:
1031
1032
1034 static string getCreateSql(list l);
1035
1037protected:
1039public:
1040
1041
1043protected:
1045public:
1046
1047
1049protected:
1050 softint getNextSequenceValueImpl(string name);
1051public:
1052
1053
1055protected:
1056 softint getCurrentSequenceValueImpl(string name);
1057public:
1058
1059
1061protected:
1063public:
1064
1065
1067protected:
1069public:
1070
1071
1073protected:
1075public:
1076
1077
1079protected:
1080 bool rebuildIndexImpl(string name, *hash options);
1081public:
1082
1083
1085protected:
1087public:
1088
1089
1091protected:
1092 reclaimSpaceImpl(*hash options);
1093public:
1094
1095
1097protected:
1099public:
1100
1101
1103protected:
1104 auto tryExecArgsImpl(string sql, *softlist<auto> args);
1105public:
1106
1107
1109protected:
1110 auto tryExecRawImpl(string sql, *softlist<auto> args);
1111public:
1112
1113
1115 static auto tryExecArgs(AbstractDatasource ds, string sql, *softlist<auto> args);
1116
1118 static auto tryExecRaw(AbstractDatasource ds, string sql);
1119 };
1120
1123
1124public:
1126 const PgsqlTypeMap = ...;
1127
1128
1130 const PgsqlNameMap = ...;
1131
1132
1134 const QoreTypeMap = ...;
1135
1136
1138
1141
1142
1143 const PgsqlColumnDescOptions = AbstractTable::ColumnDescOptions;
1144
1145 const PgsqlIndexOptions = AbstractTable::IndexOptions;
1146
1147 const PgsqlConstraintOptions = ...;
1148
1149
1150 const PgsqlTableCreationOptions = ...;
1151
1152
1153 const PgsqlAlignTableOptions = AbstractTable::AlignTableOptions + PgsqlTableCreationOptions;
1154
1156 const PgsqlExpressionMap = DefaultExpressionMap + {
1157 COP_CAST: {
1158 "exp": <DataProviderExpressionInfo>{
1159 "type": DET_Operator,
1160 "label": COP_CAST,
1161 "name": "cast",
1162 "desc": "cast operator",
1163 "symbol": "cast",
1164 "args": (
1165 DataProviderSignatureAnyType,
1166 DataProviderSignatureStringValueType,
1167 DataProviderSignatureOptionalIntValueType,
1168 DataProviderSignatureOptionalIntValueType,
1169 ),
1170 "return_type": AbstractDataProviderTypeMap."any",
1171 },
1172 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1173 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1174 AbstractDataProviderTypeMap."any");
1175 string name = QoreTypeMap{args[1]} ?? args[1];
1176 *hash<auto> desc = PgsqlTypeMap{name};
1177 string sql = sprintf ("cast (%s as %s", exp0, name);
1178 if (desc.size == SZ_MAND) {
1179 if (!exists args[1] && !exists desc.size_range)
1180 throw "OPERATOR-ERROR", sprintf ("cast operator missing size for type %s",
1181 name);
1182 sql += sprintf("(%d)", args[1] ?? desc.size_range[1]);
1183 } else if (desc.size == SZ_NUM && exists args[1]) {
1184 sql += sprintf("(%d", args[1]);
1185 sql += exists args[2] ? sprintf(",%d)", args[2]) : ")";
1186 } else if (desc.size == SZ_OPT && exists args[1]) {
1187 sql += sprintf("(%d)", args[1]);
1188 }
1189 sql += ")";
1190 return sql;
1191 },
1192 },
1193 COP_YEAR: {
1194 "exp": <DataProviderExpressionInfo>{
1195 "type": DET_Operator,
1196 "label": COP_YEAR,
1197 "name": COP_YEAR,
1198 "desc": "returns the year component of a date as a string (ex: `2022`)",
1199 "symbol": COP_YEAR,
1200 "args": (
1201 DataProviderSignatureDateType,
1202 ),
1203 "return_type": AbstractDataProviderTypeMap."string",
1204 },
1205 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1206 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1207 AbstractDataProviderTypeMap."date");
1208 return sprintf("to_char(%s, 'YYYY')", exp0);
1209 }
1210 },
1211 COP_YEAR_MONTH: {
1212 "exp": <DataProviderExpressionInfo>{
1213 "type": DET_Operator,
1214 "label": COP_YEAR_MONTH,
1215 "name": COP_YEAR_MONTH,
1216 "desc": "returns the year and month components of a date as a string (ex: `2022-06`)",
1217 "symbol": COP_YEAR_MONTH,
1218 "args": (
1219 DataProviderSignatureDateType,
1220 ),
1221 "return_type": AbstractDataProviderTypeMap."string",
1222 },
1223 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1224 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1225 AbstractDataProviderTypeMap."date");
1226 return sprintf("to_char(%s, 'YYYY-MM')", exp0);
1227 }
1228 },
1229 COP_YEAR_DAY: {
1230 "exp": <DataProviderExpressionInfo>{
1231 "type": DET_Operator,
1232 "label": COP_YEAR_DAY,
1233 "name": COP_YEAR_DAY,
1234 "desc": "returns the year, month, and day components of a date as a string (ex: `2022-06-29`)",
1235 "symbol": COP_YEAR_DAY,
1236 "args": (
1237 DataProviderSignatureDateType,
1238 ),
1239 "return_type": AbstractDataProviderTypeMap."string",
1240 },
1241 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1242 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1243 AbstractDataProviderTypeMap."date");
1244 return sprintf("to_char(%s, 'YYYY-MM-DD')", exp0);
1245 }
1246 },
1247 COP_YEAR_HOUR: {
1248 "exp": <DataProviderExpressionInfo>{
1249 "type": DET_Operator,
1250 "label": COP_YEAR_HOUR,
1251 "name": COP_YEAR_HOUR,
1252 "desc": "returns the year, month, day, and hour components of a date as a string "
1253 "(ex: `2022-06-29 15`)",
1254 "symbol": COP_YEAR_HOUR,
1255 "args": (
1256 DataProviderSignatureDateType,
1257 ),
1258 "return_type": AbstractDataProviderTypeMap."string",
1259 },
1260 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1261 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1262 AbstractDataProviderTypeMap."date");
1263 return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", exp0);
1264 }
1265 },
1266 COP_TRUNC_DATE: {
1267 "exp": <DataProviderExpressionInfo>{
1268 "type": DET_Operator,
1269 "label": COP_TRUNC_DATE,
1270 "name": COP_TRUNC_DATE,
1271 "desc": "truncates the given date to the given resolution; args: date, string code: Y: year, "
1272 "M: month, D: day, H: hour, m: minute, S: second",
1273 "symbol": COP_TRUNC_DATE,
1274 "args": (
1275 DataProviderSignatureDateType,
1276 DataProviderSignatureStringValueType,
1277 ),
1278 "return_type": AbstractDataProviderTypeMap."date",
1279 },
1280 "code": string sub(reference<hash<QueryInfo>> info, int role, list<auto> args) {
1281 *string str = PgsqlTruncDate{args[1]};
1282 if (!str) {
1283 throw "TRUNC-DATE-ERROR", sprintf("unknown date truncation format argument %y; "
1284 "supported date format arguments: %y", args[1], keys PgsqlTruncDate);
1285 }
1286 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1287 AbstractDataProviderTypeMap."date");
1288 return sprintf("date_trunc(%s, %s)", str, exp0);
1289 },
1290 },
1291 COP_SEQ: {
1292 "exp": <DataProviderExpressionInfo>{
1293 "type": DET_Operator,
1294 "label": COP_SEQ,
1295 "name": COP_SEQ,
1296 "desc": "returns the next value in the given sequence; args: sequence name",
1297 "symbol": COP_SEQ,
1298 "args": (
1299 DataProviderSignatureStringValueType,
1300 ),
1301 "return_type": AbstractDataProviderTypeMap."int",
1302 },
1303 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1304 return sprintf("nextval('%s')", args[0]);
1305 }
1306 },
1307 COP_SEQ_CURRVAL: {
1308 "exp": <DataProviderExpressionInfo>{
1309 "type": DET_Operator,
1310 "label": COP_SEQ_CURRVAL,
1311 "name": COP_SEQ_CURRVAL,
1312 "desc": "returns the current value in the given sequence; args: sequence name",
1313 "symbol": COP_SEQ_CURRVAL,
1314 "args": (
1315 DataProviderSignatureStringValueType,
1316 ),
1317 "return_type": AbstractDataProviderTypeMap."int",
1318 },
1319 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1320 return sprintf("currval('%s')", args[0]);
1321 }
1322 },
1323 };
1324
1326 const PgsqlCopMap = {
1327 COP_CAST: (
1328 "code": string sub (string cve, list<auto> args) {
1329 string name = QoreTypeMap{args[0]} ?? args[0];
1330 hash desc = PgsqlTypeMap{name};
1331 string sql = sprintf ("cast (%s as %s", cve, name);
1332 switch (name) {
1333 default:
1334 if (desc.size == SZ_MAND) {
1335 if (!exists args[1] && !exists desc.size_range)
1336 throw "OPERATOR-ERROR", sprintf ("op_cast operator missing size for type %s",
1337 name);
1338 sql += sprintf("(%d)", args[1] ?? desc.size_range[1]);
1339 } else if (desc.size == SZ_NUM && exists args[1]) {
1340 sql += sprintf("(%d", args[1]);
1341 sql += exists args[2] ? sprintf(",%d)", args[2]) : ")";
1342 } else if (desc.size == SZ_OPT && exists args[1]) {
1343 sql += sprintf("(%d)", args[1]);
1344 }
1345 }
1346 sql += ")";
1347 return sql;
1348 },
1349 ),
1350 COP_YEAR: (
1351 "code": string sub (string arg1, auto arg) {
1352 return sprintf("to_char(%s, 'YYYY')", arg1);
1353 }
1354 ),
1355 COP_YEAR_MONTH: (
1356 "code": string sub (string arg1, auto arg) {
1357 return sprintf("to_char(%s, 'YYYY-MM')", arg1);
1358 }
1359 ),
1360 COP_YEAR_DAY: (
1361 "code": string sub (string arg1, auto arg) {
1362 return sprintf("to_char(%s, 'YYYY-MM-DD')", arg1);
1363 }
1364 ),
1365 COP_YEAR_HOUR: (
1366 "code": string sub (string arg1, auto arg) {
1367 return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", arg1);
1368 }
1369 ),
1370 COP_SEQ: (
1371 "nocolumn": True,
1372 "withalias": True,
1373 "code": string sub (*string cve, hash arg, reference<hash> psch) {
1374 string sql = sprintf("nextval('%s')", arg.seq);
1375 if (arg.as) {
1376 psch{arg.as} = sql;
1377 sql += " " + arg.as;
1378 }
1379 return sql;
1380 }
1381 ),
1382 COP_SEQ_CURRVAL: (
1383 "nocolumn": True,
1384 "withalias": True,
1385 "code": string sub (*string cve, hash arg, reference<hash> psch) {
1386 string sql = sprintf("currval('%s')", arg.seq);
1387 if (arg.as) {
1388 psch{arg.as} = sql;
1389 sql += " " + arg.as;
1390 }
1391 return sql;
1392 }
1393 ),
1394 COP_TRUNC_DATE: (
1395 "code": string sub(string arg1, auto arg) {
1396 if (!PgsqlTruncDate.hasKey(arg)) {
1397 throw "COP-TRUNC-DATE-ERROR", sprintf("Not allowed format argument: %n: allowed: %n", arg,
1398 PgsqlTruncDate.keys());
1399 }
1400 return sprintf("date_trunc(%s, %s)", PgsqlTruncDate{arg}, arg1);
1401 }
1402 ),
1403 };
1404
1406 const PgsqlTruncDate = ...;
1407
1408
1410 const PgsqlIopMap = ...;
1411
1412
1414 const PgsqlUopMap = ...;
1415
1416
1417protected:
1419 *string tablespace;
1420
1422 string schema;
1423
1426
1429
1432
1435
1438
1441
1443 transient Mutex pg_state();
1444
1445public:
1446
1448 constructor(AbstractDatasource nds, string nname, *hash opts) ;
1449
1450
1453
1454
1457
1458
1459 PgsqlFunction addTriggerFunction(string tfname, string src, string trigger);
1460
1461
1464
1465
1467 string getColumnSqlName(string col);
1468
1469
1471
1473 list<auto> getColumnSqlNames(softlist<auto> cols);
1474
1475
1477
1481 code getUpsertClosure(hash<auto> row, int upsert_strategy = UpsertAuto, *hash<auto> opt);
1482
1483
1486
1487
1489protected:
1491public:
1492
1493
1494protected:
1495 code getUpsertAuto(Columns cols, hash<auto> row, *hash<auto> opt);
1496public:
1497
1498
1499protected:
1500 PgsqlFunction addTriggerFunctionUnlocked(string tfname, string src, string trigger);
1501public:
1502
1503
1505 string getSqlName();
1506
1507
1508protected:
1509 hash getTableCreationOptions();
1510public:
1511
1512
1513protected:
1514 hash getTableDescriptionHashOptions();
1515public:
1516
1517
1518protected:
1519 hash getColumnDescOptions();
1520public:
1521
1522
1523protected:
1524 hash getIndexOptions();
1525public:
1526
1527
1528protected:
1529 hash getConstraintOptions();
1530public:
1531
1532
1533protected:
1534 hash getAlignTableOptions();
1535public:
1536
1537
1539protected:
1541public:
1542
1543
1545protected:
1547public:
1548
1549
1551protected:
1553public:
1554
1555
1557 hash<auto> getExpressionMap();
1558
1559
1560protected:
1561 bool checkExistenceImpl();
1562public:
1563
1564
1565protected:
1566 Columns describeImpl();
1567public:
1568
1569
1570protected:
1571 PgsqlPrimaryKey getPrimaryKeyImpl();
1572public:
1573
1574
1575protected:
1576 Indexes getIndexesImpl();
1577public:
1578
1579
1580protected:
1581 ForeignConstraints getForeignConstraintsImpl(*hash opts);
1582public:
1583
1584
1585protected:
1586 Constraints getConstraintsImpl();
1587public:
1588
1589
1590protected:
1591 Triggers getTriggersImpl();
1592public:
1593
1594
1596protected:
1597 string getCreateTableSqlImpl(*hash opt);
1598public:
1599
1600
1601protected:
1602 *list getCreateMiscSqlImpl(*hash opt, bool cache);
1603public:
1604
1605
1606protected:
1607 *list getAlignSqlImpl(AbstractTable table, *hash<auto> opt);
1608public:
1609
1610
1612protected:
1613 string getCreateSqlImpl(list l);
1614public:
1615
1616
1617protected:
1618 string getRenameSqlImpl(string new_name);
1619public:
1620
1621
1622protected:
1623 AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
1624public:
1625
1626
1627protected:
1628 AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
1629public:
1630
1631
1632protected:
1633 AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
1634public:
1635
1636
1637 private AbstractForeignConstraint addForeignConstraintImpl(string cname, hash<auto> ch, string table,
1638 hash<auto> tch, *hash<auto> opt) {
1639 ForeignConstraintTarget fct(table, new Columns(tch));
1640 return new PgsqlForeignConstraint(cname, new Columns(ch), fct);
1641 }
1642
1643protected:
1644 AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
1645public:
1646
1647
1648protected:
1649 AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
1650public:
1651
1652
1653protected:
1654 AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
1655public:
1656
1657
1658protected:
1659 bool tryInsertImpl(string sql, hash<auto> row);
1660public:
1661
1662
1664
1666protected:
1667 bool isDuplicateRowErrorImpl(hash<ExceptionInfo> ex);
1668public:
1669
1670
1671protected:
1672 hash<auto> getQoreTypeMapImpl();
1673public:
1674
1675
1676protected:
1677 hash<auto> getTypeMapImpl();
1678public:
1679
1680
1682
1684protected:
1685 *string getSqlValueImpl(auto v);
1686public:
1687
1688
1689protected:
1690 bool emptyImpl();
1691public:
1692
1693
1695protected:
1697public:
1698
1699
1700protected:
1701 softlist getDropSqlImpl();
1702public:
1703
1704
1705protected:
1706 setupTableImpl(hash<auto> desc, *hash<auto> opt);
1707public:
1708
1709
1711protected:
1713public:
1714
1715
1717protected:
1719public:
1720
1721
1723protected:
1725public:
1726
1727
1729protected:
1730 doSelectLimitOnlyUnlockedImpl(reference<hash<QueryInfo>> info, reference<string> sql);
1731public:
1732
1733
1735 private doSelectOrderByWithOffsetSqlUnlockedImpl(reference<hash<QueryInfo>> info, reference<string> sql,
1736 list<auto> coll) {
1737 doSelectOrderBySqlUnlocked(info, \sql, coll);
1738 if (info.query_hash.limit);
1739
1740
1741 if (info.query_hash.offset);
1742
1743 }
1744
1746protected:
1747 auto tryExecArgsImpl(string sql, *softlist<auto> args);
1748public:
1749
1750
1752protected:
1753 auto tryExecRawImpl(string sql, *softlist<auto> args);
1754public:
1755
1756
1758protected:
1759 copyImpl(AbstractTable old);
1760public:
1761
1762
1763protected:
1764 *hash<auto> doReturningImpl(hash<auto> opt, reference<string> sql, list<auto> args);
1765public:
1766
1767
1768protected:
1769 list<auto> getGroupOrderByListUnlocked(hash<QueryInfo> info, string key, list<auto> coll);
1770public:
1771
1772
1774protected:
1775 AbstractDataProviderType getNumericTypeImpl(string native_type, bool nullable, *hash<auto> options);
1776public:
1777
1778
1780
1784protected:
1785 AbstractSavepointHelper getSavepointHelperImpl(*string savepoint);
1786public:
1787
1788 };
1789};
represents a PostgreSQL-specific check constraint
Definition: PgsqlSqlUtil.qm.dox.h:434
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
string getCreateSql(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: PgsqlSqlUtil.qm.dox.h:454
constructor()
empty constructor for subclasses
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
string getNativeTypeString()
returns a string giving the native type of the column
bool equalImpl(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
int byte_size
byte size of the column
Definition: PgsqlSqlUtil.qm.dox.h:458
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
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 getRenameSql(AbstractTable t, string new_name)
returns a string that can be used to rename the column
provides the PostgreSQL-specific implementation of the AbstractDatabase interface
Definition: PgsqlSqlUtil.qm.dox.h:808
list< string > listFunctionsImpl()
returns a list of string function names in the database
list< string > listTablesImpl()
returns a list of string table names in the database
bool rebuildIndexImpl(string name, *hash options)
rebuild index implementation. See SqlUtil::AbstractDatabase::rebuildIndex()
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
list< string > listProceduresImpl()
since PostgreSQL only supports functions, this method is identical to listFunctionsImpl()
static string getCreateSql(list l)
returns a string that can be used to create the schema in the database
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
const PgsqlReclaimSpaceOptions
Options for reclaimSpace()
Definition: PgsqlSqlUtil.qm.dox.h:818
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
hash getSchemaDescriptionOptions()
returns driver-specific options to the base abstract class
bool supportsPackagesImpl()
returns True if the database supports packages
const PgsqlSchemaDescriptionOptions
PostgreSQL-specific schema description keys.
Definition: PgsqlSqlUtil.qm.dox.h:812
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
reclaimSpaceImpl(*hash options)
reclaim space implementation. See SqlUtil::AbstractDatabase::reclaimSpace()
string getCreateSqlImpl(list l)
returns a string that can be used to create the schema in the database
ListIterator materializedViewIterator()
returns an iterator listing the string materialized view names in the database
const PgsqlReservedWords
hash (set) of reserved words
Definition: PgsqlSqlUtil.qm.dox.h:822
hash getReclaimSpaceOptions()
returns driver-specific options to the base abstract class
ListIterator typeIterator()
returns an iterator listing the string type names in the database
bool supportsSequencesImpl()
returns True if the database supports sequences
bool supportsTypesImpl()
returns True if the database supports named types
softint getCurrentSequenceValueImpl(string name)
returns the last value issued for the given sequence in the current session
int getPhysicalSizeImpl()
SqlUtil::AbstractDatabase::getPhysicalSize()
list< string > listMaterializedViews()
returns a list of string materialized view names in the database
list< string > listTypes()
returns a list of string type names in the database
softint getNextSequenceValueImpl(string name)
returns the next value in the given sequence
computeStatisticsImpl(*hash options)
compute statistics implementation. See SqlUtil::AbstractDatabase::computeStatistics()
represents a PostgreSQL-specific foreign constraint
Definition: PgsqlSqlUtil.qm.dox.h:410
string getDropSql(string table_name)
returns a string that can be used to drop the constraint from 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
string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the constraint in the database
represents a PostgreSQL-specific function
Definition: PgsqlSqlUtil.qm.dox.h:760
softlist getCreateSql(*hash opt)
returns a string that can be used to create the function in the database
string getDropSql(*hash opt)
returns a string that can be used to drop the function from the database
setName(string new_name)
sets the new name of the function
softlist getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename the function in the database
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
represents a PostgreSQL-specific index
Definition: PgsqlSqlUtil.qm.dox.h:379
string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database
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: PgsqlSqlUtil.qm.dox.h:383
string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the index in the database
string getDropSql(string table_name)
returns a string that can be used to drop the index from the database
bool equalImpl(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
the data type for PostgreSQL NUMBER columns
Definition: PgsqlSqlUtil.qm.dox.h:298
constructor(string native_type, bool nullable, *hash< auto > options)
creates the object
represents a PostgreSQL-specific numeric column
Definition: PgsqlSqlUtil.qm.dox.h:534
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
string getNativeTypeString()
returns a string giving the native type of the column
represents a PostgreSQL-specific primary key constraint
Definition: PgsqlSqlUtil.qm.dox.h:638
constructor(string n, *hash c, *string ts)
creates the object with the given attributes
PgsqlColumn memberGate(string k)
returns the PgsqlColumn value of the given key if it exists, otherwise throws a KEY-ERROR exception
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
constructor()
creates an empty primary key object
PostgreSQL savepoint helper.
Definition: PgsqlSqlUtil.qm.dox.h:310
createSavepointImpl()
Creates the savepoint.
constructor(AbstractDatasource ds, *string savepoint)
Creates the object.
rollbackImpl()
Rolls back to the savepoint.
deleteSavepointImpl()
Deletes the savepoint.
class for PostgreSQL sequences
Definition: PgsqlSqlUtil.qm.dox.h:682
softlist getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename the sequence in the database
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
provides the PostgreSQL-specific implementation of the SqlUtil::AbstractTable interface
Definition: PgsqlSqlUtil.qm.dox.h:1122
hash getColumnOperatorMapImpl()
returns the column operator map for this object
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
const PgsqlCopMap
column operator specializations for PostgreSQL
Definition: PgsqlSqlUtil.qm.dox.h:1326
bool isDuplicateRowErrorImpl(hash< ExceptionInfo > ex)
Returns True if the exception was raised because of a duplicate row / key error.
doSelectLimitOnlyUnlockedImpl(reference< hash< QueryInfo > > info, reference< string > sql)
processes a string for use in SQL select statements when there is a "limit" argument,...
bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
int server_version_minor
PostgreSQL server minor version.
Definition: PgsqlSqlUtil.qm.dox.h:1437
const PgsqlIopMap
a hash of default value operator descriptions for PostgreSQL
Definition: PgsqlSqlUtil.qm.dox.h:1410
bool hasArrayBind()
returns False because the pgsql driver does not support array binds / bulk DML operations
bool has_atomic_merge
Set based on the postgreSQL server version.
Definition: PgsqlSqlUtil.qm.dox.h:1428
string schema
schema name for the table
Definition: PgsqlSqlUtil.qm.dox.h:1422
clearImpl()
clears PostgreSQL-specific table information
int server_version
PostgreSQL server full version code.
Definition: PgsqlSqlUtil.qm.dox.h:1431
bool hasAtomicUpsert()
Returns True if the server supports atomic upsert/merge operations.
list< auto > getColumnSqlNames(softlist< auto > cols)
returns a list of column names for use in SQL strings
*string getTablespaceName()
returns the data tablespace name for the table or NOTHING if none is known
int server_version_major
PostgreSQL server major version.
Definition: PgsqlSqlUtil.qm.dox.h:1434
AbstractSavepointHelper getSavepointHelperImpl(*string savepoint)
get DB-specific savepoint helper
getServerVersion()
Sets the internal PostgreSQL server version.
hash< auto > getExpressionMap()
Returns the expression map for PostgreSQL.
transient Mutex pg_state()
Lock for atomicity for setting state info.
copyImpl(AbstractTable old)
db-specific copy actions
bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
const QoreTypeMap
maps qore type names to PostgreSQL type names
Definition: PgsqlSqlUtil.qm.dox.h:1134
*string tablespace
tablespace name for the table, if known
Definition: PgsqlSqlUtil.qm.dox.h:1419
constructor(AbstractDatasource nds, string nname, *hash opts)
Creates the object from the arguments.
string getCreateTableSqlImpl(*hash opt)
returns a string that can be used to create the table in the database
const PgsqlExpressionMap
Expression map for PostgreSQL.
Definition: PgsqlSqlUtil.qm.dox.h:1156
bool supportsTablespacesImpl()
returns True if the database support tablespaces
string getCreateSqlImpl(list l)
returns a string that can be used to create the table in the database
string getSchemaName()
returns the schema name
const PgsqlNameMap
maps from verbose type names to simple type names
Definition: PgsqlSqlUtil.qm.dox.h:1130
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: PgsqlSqlUtil.qm.dox.h:1735
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...
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 getColumnSqlName(string col)
returns the column name for use in SQL strings; subclasses can return a special string in case the co...
const PgsqlUopMap
a hash of default update operator definitions for PostgreSQL
Definition: PgsqlSqlUtil.qm.dox.h:1414
*string getSqlValueImpl(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument
Functions triggerFunctions
contains any trigger functions supporting triggers on the table
Definition: PgsqlSqlUtil.qm.dox.h:1425
int server_version_sub
PostgreSQL server version.
Definition: PgsqlSqlUtil.qm.dox.h:1440
const PgsqlTruncDate
Map SqlUtil::cop_trunc_date() constants to PostgreSQL internal masks.
Definition: PgsqlSqlUtil.qm.dox.h:1406
const PgsqlTypeMap
maps PostgreSQL type names to type configurations
Definition: PgsqlSqlUtil.qm.dox.h:1126
hash getRawUpdateOperatorMap()
returns the raw (default) update operator map for this object
const PgsqlTableDescriptionHashOptions
extends SqlUtil::AbstractTable::TableDescriptionHashOptions with "functions"
Definition: PgsqlSqlUtil.qm.dox.h:1140
hash getInsertOperatorMap()
returns the insert operator map for this object
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifiers for schema,...
code getUpsertClosure(hash< auto > row, int upsert_strategy=UpsertAuto, *hash< auto > opt)
returns a closure for performing upserts
represents a PostgreSQL-specific trigger function
Definition: PgsqlSqlUtil.qm.dox.h:797
string trigger
trigger name
Definition: PgsqlSqlUtil.qm.dox.h:801
represents a PostgreSQL-specific trigger
Definition: PgsqlSqlUtil.qm.dox.h:729
softlist getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the trigger in the database
softlist 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
constructor(string n, string n_src)
creates the object and sets its name and the trigger source
softlist getDropSql(string table_name)
returns a string that can be used to drop the trigger from the database
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
represents a PostgreSQL type
Definition: PgsqlSqlUtil.qm.dox.h:337
string getDropSql(*hash opt)
returns a string that can be used to drop the function from the database
string getCreateSql(*hash opt)
returns a string that can be used to create the type in the database
string src
the source of the type
Definition: PgsqlSqlUtil.qm.dox.h:344
string name
the name of the type
Definition: PgsqlSqlUtil.qm.dox.h:341
constructor(string n_name, string n_src)
creates the type from the supplied arguments
string getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename a type
bool equal(PgsqlType type)
returns True if the types are equal
common base class for unique constraints
Definition: PgsqlSqlUtil.qm.dox.h:548
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: PgsqlSqlUtil.qm.dox.h:553
getIndexSql(reference< string > sql, string name, *hash opts)
adds index options onto the sql creation string
constructor(*string ts)
creates the constraint with an optional tablespace name
clearIndex()
clears any index base for the constraint
bool setIndexBase(string ix)
sets the supporting index name
class modeling a unique constraint
Definition: PgsqlSqlUtil.qm.dox.h:583
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 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
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: PgsqlSqlUtil.qm.dox.h:588
represents a PostgreSQL view
Definition: PgsqlSqlUtil.qm.dox.h:703
string getCreateSql(*hash opt)
returns a string that can be used to create the view in the database
*string viewowner
Owner of the view.
Definition: PgsqlSqlUtil.qm.dox.h:707
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
transient AbstractDatasource ds
cache(*hash< auto > opts)
the PgsqlSqlUtil namespace contains all the objects in the PgsqlSqlUtil module
Definition: PgsqlSqlUtil.qm.dox.h:288
PgsqlDatabase get_database(AbstractDatasource nds, *hash< auto > opts)
returns a PgsqlDatabase object corresponding to the arguments
PgsqlTable get_table(AbstractDatasource nds, string nname, *hash< auto > opts)
returns a PgsqlTable object corresponding to the arguments