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
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, softint scale) ;
539
540
543
544 };
545
548
549public:
550protected:
552 *string tablespace;
553
554public:
555
557 constructor(*string ts);
558
559
561 *string getTablespace();
562
563
565 setTablespace(*string ts);
566
567
569 bool setIndexBase(string ix);
570
571
574
575
577 getIndexSql(reference<string> sql, string name, *hash opts);
578
579 };
580
583
584public:
585protected:
588
589public:
590
592
597 constructor(string n, hash n_cols, bool e = True, *string ts) ;
598
599
601
617
618
620 string getCreateSql(string table_name, *hash opts);
621
622
623 list<auto> getRenameSql(string table_name, string new_name);
624
625
627 string getCreateSql(string name, string table_name, *hash<auto> opts);
628
629
631 bool isEnabled();
632
633 };
634
637
638public:
641
642
644
648 constructor(string n, *hash c, *string ts) ;
649
650
652
668
669
671 string getCreateSql(string table_name, *hash<auto> opts);
672
673
675 softlist getRenameSql(string table_name, string new_name);
676
677 };
678
681
682public:
684 constructor(string n_name, number n_start = 1, number n_increment = 1, *softnumber n_end) ;
685
686
688 string getCreateSql(*hash opt);
689
690
692
696 softlist getRenameSql(string new_name, *hash opt);
697
698 };
699
702
703public:
705 *string viewowner;
706
708 constructor(string n_name, string n_src, *string n_schemaname, *string n_viewowner)
709 ;
710
711
713 string getCreateSql(*hash opt);
714
715
717
721 softlist getRenameSql(string new_name, *hash opt);
722
723 };
724
727
728public:
730 constructor(string n, string n_src) ;
731
732
734 softlist<string> getCreateSql(string table_name, *hash opt);
735
736
738 softlist<string> getDropSql(string table_name);
739
740
742protected:
743 bool equalImpl(AbstractFunctionBase t);
744public:
745
746
748 softlist<string> getRenameSql(string table_name, string new_name);
749
750
752 string getNormalizedSource(string src);
753
754 };
755
758
759public:
760 *string args;
761
762 constructor(string n, string n_src, *string a) ;
763
764
766 softlist<string> getCreateSql(*hash opt);
767
768
770
773 string getDropSql(*hash opt);
774
775
777protected:
778 bool equalImpl(AbstractFunctionBase t);
779public:
780
781
783
786 softlist<string> getRenameSql(string new_name, *hash opt);
787
788
790 setName(string new_name);
791
792 };
793
796
797public:
799 string trigger;
800
801 constructor(string n, string n_src, string n_trigger) ;
802
803 };
804
807
808public:
811
812
813 const PGSQL_TempSavepoint = "qore_pgsql_tmp_savepoint";
814
817
818
821 "all": True,
822 "analyse": True,
823 "analyze": True,
824 "and": True,
825 "any": True,
826 "as": True,
827 "asc": True,
828 "authorization": True,
829 "between": True,
830 "binary": True,
831 "both": True,
832 "case": True,
833 "cast": True,
834 "check": True,
835 "collate": True,
836 "column": True,
837 "constraint": True,
838 "create": True,
839 "cross": True,
840 "currentdate": True,
841 "currenttime": True,
842 "currenttimestamp": True,
843 "currentuser": True,
844 "default": True,
845 "deferrable": True,
846 "desc": True,
847 "distinct": True,
848 "do": True,
849 "else": True,
850 "end": True,
851 "except": True,
852 "false": True,
853 "for": True,
854 "foreign": True,
855 "freeze": True,
856 "from": True,
857 "full": True,
858 "grant": True,
859 "group": True,
860 "having": True,
861 "ilike": True,
862 "in": True,
863 "initially": True,
864 "inner": True,
865 "intersect": True,
866 "into": True,
867 "is": True,
868 "isnull": True,
869 "join": True,
870 "leading": True,
871 "left": True,
872 "like": True,
873 "limit": True,
874 "localtime": True,
875 "localtimestamp": True,
876 "natural": True,
877 "new": True,
878 "not": True,
879 "notnull": True,
880 "null": True,
881 "off": True,
882 "offset": True,
883 "old": True,
884 "on": True,
885 "only": True,
886 "or": True,
887 "order": True,
888 "outer": True,
889 "overlaps": True,
890 "placing": True,
891 "primary": True,
892 "references": True,
893 "right": True,
894 "select": True,
895 "sessionuser": True,
896 "similar": True,
897 "some": True,
898 "table": True,
899 "then": True,
900 "to": True,
901 "trailing": True,
902 "true": True,
903 "union": True,
904 "unique": True,
905 "user": True,
906 "using": True,
907 "verbose": True,
908 "when": True,
909 "where": True,
910 };
911
912 constructor(AbstractDatasource nds, *hash opts) ;
913
914
915protected:
916 list<string> featuresImpl();
917public:
918
919
920 PgsqlType makeType(string name, string src, *hash opts);
921
922
923 *PgsqlType getType(string name);
924
925
926protected:
927 PgsqlSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
928public:
929
930
931protected:
932 *AbstractSequence getSequenceImpl(string name);
933public:
934
935
936protected:
937 *AbstractView getViewImpl(string name);
938public:
939
940
941protected:
942 PgsqlFunction makeFunctionImpl(string name, string src, *hash opts);
943public:
944
945
946protected:
947 PgsqlFunction makeProcedureImpl(string name, string src, *hash opts);
948public:
949
950
951protected:
952 *AbstractFunction getFunctionImpl(string name);
953public:
954
955
956protected:
957 AbstractFunction getProcedureImpl(string name);
958public:
959
960
961 static *string getFunctionArgs(string err, reference<string> src);
962
963 static PgsqlFunction processFunction(hash<auto> row, bool native_case);
964
965protected:
966 list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
967public:
968
969
970protected:
971 list getAlignSqlImpl(hash schema_hash, *hash opt);
972public:
973
974
976protected:
977 list<string> listTablesImpl();
978public:
979
980
982
986protected:
987 list<string> listFunctionsImpl();
988public:
989
990
992
994protected:
995 list<string> listProceduresImpl();
996public:
997
998
999protected:
1000 list<string> listSequencesImpl();
1001public:
1002
1003
1004protected:
1005 list<string> listViewsImpl();
1006public:
1007
1008
1011
1012
1015
1016
1018 list<string> listTypes();
1019
1020
1022 ListIterator typeIterator();
1023
1024
1026protected:
1027 string getCreateSqlImpl(list l);
1028public:
1029
1030
1032 static string getCreateSql(list l);
1033
1035protected:
1037public:
1038
1039
1041protected:
1043public:
1044
1045
1047protected:
1048 softint getNextSequenceValueImpl(string name);
1049public:
1050
1051
1053protected:
1054 softint getCurrentSequenceValueImpl(string name);
1055public:
1056
1057
1059protected:
1061public:
1062
1063
1065protected:
1067public:
1068
1069
1071protected:
1073public:
1074
1075
1077protected:
1078 bool rebuildIndexImpl(string name, *hash options);
1079public:
1080
1081
1083protected:
1085public:
1086
1087
1089protected:
1090 reclaimSpaceImpl(*hash options);
1091public:
1092
1093
1094protected:
1095 *string getDbName();
1096public:
1097
1098
1100protected:
1102public:
1103
1104
1106protected:
1107 auto tryExecArgsImpl(string sql, *softlist<auto> args);
1108public:
1109
1110
1112protected:
1113 auto tryExecRawImpl(string sql, *softlist<auto> args);
1114public:
1115
1116
1118 static auto tryExecArgs(AbstractDatasource ds, string sql, *softlist<auto> args);
1119
1121 static auto tryExecRaw(AbstractDatasource ds, string sql);
1122 };
1123
1126
1127public:
1129 const PgsqlTypeMap = ...;
1130
1131
1133 const PgsqlNameMap = ...;
1134
1135
1137 const QoreTypeMap = ...;
1138
1139
1141
1144
1145
1146 const PgsqlColumnDescOptions = AbstractTable::ColumnDescOptions;
1147
1148 const PgsqlIndexOptions = AbstractTable::IndexOptions;
1149
1150 const PgsqlConstraintOptions = ...;
1151
1152
1153 const PgsqlTableCreationOptions = ...;
1154
1155
1156 const PgsqlAlignTableOptions = AbstractTable::AlignTableOptions + PgsqlTableCreationOptions;
1157
1159 const PgsqlExpressionMap = DefaultExpressionMap + {
1160 COP_CAST: {
1161 "exp": <DataProviderExpressionInfo>{
1162 "type": DET_Operator,
1163 "label": COP_CAST,
1164 "name": "cast",
1165 "desc": "cast operator",
1166 "symbol": "cast",
1167 "args": (
1168 DataProviderSignatureAnyType,
1169 DataProviderSignatureStringValueType,
1170 DataProviderSignatureOptionalIntValueType,
1171 DataProviderSignatureOptionalIntValueType,
1172 ),
1173 "return_type": AbstractDataProviderTypeMap."any",
1174 },
1175 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1176 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1177 AbstractDataProviderTypeMap."any");
1178 string name = QoreTypeMap{args[1]} ?? args[1];
1179 *hash<auto> desc = PgsqlTypeMap{name};
1180 string sql = sprintf ("cast (%s as %s", exp0, name);
1181 if (desc.size == SZ_MAND) {
1182 if (!exists args[1] && !exists desc.size_range)
1183 throw "OPERATOR-ERROR", sprintf ("cast operator missing size for type %s",
1184 name);
1185 sql += sprintf("(%d)", args[1] ?? desc.size_range[1]);
1186 } else if (desc.size == SZ_NUM && exists args[1]) {
1187 sql += sprintf("(%d", args[1]);
1188 sql += exists args[2] ? sprintf(",%d)", args[2]) : ")";
1189 } else if (desc.size == SZ_OPT && exists args[1]) {
1190 sql += sprintf("(%d)", args[1]);
1191 }
1192 sql += ")";
1193 return sql;
1194 },
1195 },
1196 COP_YEAR: {
1197 "exp": <DataProviderExpressionInfo>{
1198 "type": DET_Operator,
1199 "label": COP_YEAR,
1200 "name": COP_YEAR,
1201 "desc": "returns the year component of a date as a string (ex: `2022`)",
1202 "symbol": COP_YEAR,
1203 "args": (
1204 DataProviderSignatureDateType,
1205 ),
1206 "return_type": AbstractDataProviderTypeMap."string",
1207 },
1208 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1209 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1210 AbstractDataProviderTypeMap."date");
1211 return sprintf("to_char(%s, 'YYYY')", exp0);
1212 }
1213 },
1214 COP_YEAR_MONTH: {
1215 "exp": <DataProviderExpressionInfo>{
1216 "type": DET_Operator,
1217 "label": COP_YEAR_MONTH,
1218 "name": COP_YEAR_MONTH,
1219 "desc": "returns the year and month components of a date as a string (ex: `2022-06`)",
1220 "symbol": COP_YEAR_MONTH,
1221 "args": (
1222 DataProviderSignatureDateType,
1223 ),
1224 "return_type": AbstractDataProviderTypeMap."string",
1225 },
1226 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1227 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1228 AbstractDataProviderTypeMap."date");
1229 return sprintf("to_char(%s, 'YYYY-MM')", exp0);
1230 }
1231 },
1232 COP_YEAR_DAY: {
1233 "exp": <DataProviderExpressionInfo>{
1234 "type": DET_Operator,
1235 "label": COP_YEAR_DAY,
1236 "name": COP_YEAR_DAY,
1237 "desc": "returns the year, month, and day components of a date as a string (ex: `2022-06-29`)",
1238 "symbol": COP_YEAR_DAY,
1239 "args": (
1240 DataProviderSignatureDateType,
1241 ),
1242 "return_type": AbstractDataProviderTypeMap."string",
1243 },
1244 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1245 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1246 AbstractDataProviderTypeMap."date");
1247 return sprintf("to_char(%s, 'YYYY-MM-DD')", exp0);
1248 }
1249 },
1250 COP_YEAR_HOUR: {
1251 "exp": <DataProviderExpressionInfo>{
1252 "type": DET_Operator,
1253 "label": COP_YEAR_HOUR,
1254 "name": COP_YEAR_HOUR,
1255 "desc": "returns the year, month, day, and hour components of a date as a string "
1256 "(ex: `2022-06-29 15`)",
1257 "symbol": COP_YEAR_HOUR,
1258 "args": (
1259 DataProviderSignatureDateType,
1260 ),
1261 "return_type": AbstractDataProviderTypeMap."string",
1262 },
1263 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1264 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1265 AbstractDataProviderTypeMap."date");
1266 return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", exp0);
1267 }
1268 },
1269 COP_TRUNC_DATE: {
1270 "exp": <DataProviderExpressionInfo>{
1271 "type": DET_Operator,
1272 "label": COP_TRUNC_DATE,
1273 "name": COP_TRUNC_DATE,
1274 "desc": "truncates the given date to the given resolution; args: date, string code: Y: year, "
1275 "M: month, D: day, H: hour, m: minute, S: second",
1276 "symbol": COP_TRUNC_DATE,
1277 "args": (
1278 DataProviderSignatureDateType,
1279 DataProviderSignatureStringValueType,
1280 ),
1281 "return_type": AbstractDataProviderTypeMap."date",
1282 },
1283 "code": string sub(reference<hash<QueryInfo>> info, int role, list<auto> args) {
1284 *string str = PgsqlTruncDate{args[1]};
1285 if (!str) {
1286 throw "TRUNC-DATE-ERROR", sprintf("unknown date truncation format argument %y; "
1287 "supported date format arguments: %y", args[1], keys PgsqlTruncDate);
1288 }
1289 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1290 AbstractDataProviderTypeMap."date");
1291 return sprintf("date_trunc(%s, %s)", str, exp0);
1292 },
1293 },
1294 COP_SEQ: {
1295 "exp": <DataProviderExpressionInfo>{
1296 "type": DET_Operator,
1297 "label": COP_SEQ,
1298 "name": COP_SEQ,
1299 "desc": "returns the next value in the given sequence; args: sequence name",
1300 "symbol": COP_SEQ,
1301 "args": (
1302 DataProviderSignatureStringValueType,
1303 ),
1304 "return_type": AbstractDataProviderTypeMap."int",
1305 },
1306 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1307 return sprintf("nextval('%s')", args[0]);
1308 }
1309 },
1310 COP_SEQ_CURRVAL: {
1311 "exp": <DataProviderExpressionInfo>{
1312 "type": DET_Operator,
1313 "label": COP_SEQ_CURRVAL,
1314 "name": COP_SEQ_CURRVAL,
1315 "desc": "returns the current value in the given sequence; args: sequence name",
1316 "symbol": COP_SEQ_CURRVAL,
1317 "args": (
1318 DataProviderSignatureStringValueType,
1319 ),
1320 "return_type": AbstractDataProviderTypeMap."int",
1321 },
1322 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1323 return sprintf("currval('%s')", args[0]);
1324 }
1325 },
1326 };
1327
1329 const PgsqlCopMap = {
1330 COP_CAST: (
1331 "code": string sub (string cve, list<auto> args) {
1332 string name = QoreTypeMap{args[0]} ?? args[0];
1333 hash desc = PgsqlTypeMap{name};
1334 string sql = sprintf ("cast (%s as %s", cve, name);
1335 switch (name) {
1336 default:
1337 if (desc.size == SZ_MAND) {
1338 if (!exists args[1] && !exists desc.size_range)
1339 throw "OPERATOR-ERROR", sprintf ("op_cast operator missing size for type %s",
1340 name);
1341 sql += sprintf("(%d)", args[1] ?? desc.size_range[1]);
1342 } else if (desc.size == SZ_NUM && exists args[1]) {
1343 sql += sprintf("(%d", args[1]);
1344 sql += exists args[2] ? sprintf(",%d)", args[2]) : ")";
1345 } else if (desc.size == SZ_OPT && exists args[1]) {
1346 sql += sprintf("(%d)", args[1]);
1347 }
1348 }
1349 sql += ")";
1350 return sql;
1351 },
1352 ),
1353 COP_YEAR: (
1354 "code": string sub (string arg1, auto arg) {
1355 return sprintf("to_char(%s, 'YYYY')", arg1);
1356 }
1357 ),
1358 COP_YEAR_MONTH: (
1359 "code": string sub (string arg1, auto arg) {
1360 return sprintf("to_char(%s, 'YYYY-MM')", arg1);
1361 }
1362 ),
1363 COP_YEAR_DAY: (
1364 "code": string sub (string arg1, auto arg) {
1365 return sprintf("to_char(%s, 'YYYY-MM-DD')", arg1);
1366 }
1367 ),
1368 COP_YEAR_HOUR: (
1369 "code": string sub (string arg1, auto arg) {
1370 return sprintf("to_char(%s, 'YYYY-MM-DD HH24')", arg1);
1371 }
1372 ),
1373 COP_SEQ: (
1374 "nocolumn": True,
1375 "withalias": True,
1376 "code": string sub (*string cve, hash arg, reference<hash> psch) {
1377 string sql = sprintf("nextval('%s')", arg.seq);
1378 if (arg.as) {
1379 psch{arg.as} = sql;
1380 sql += " " + arg.as;
1381 }
1382 return sql;
1383 }
1384 ),
1385 COP_SEQ_CURRVAL: (
1386 "nocolumn": True,
1387 "withalias": True,
1388 "code": string sub (*string cve, hash arg, reference<hash> psch) {
1389 string sql = sprintf("currval('%s')", arg.seq);
1390 if (arg.as) {
1391 psch{arg.as} = sql;
1392 sql += " " + arg.as;
1393 }
1394 return sql;
1395 }
1396 ),
1397 COP_TRUNC_DATE: (
1398 "code": string sub(string arg1, auto arg) {
1399 if (!PgsqlTruncDate.hasKey(arg)) {
1400 throw "COP-TRUNC-DATE-ERROR", sprintf("Not allowed format argument: %n: allowed: %n", arg,
1401 PgsqlTruncDate.keys());
1402 }
1403 return sprintf("date_trunc(%s, %s)", PgsqlTruncDate{arg}, arg1);
1404 }
1405 ),
1406 };
1407
1409 const PgsqlTruncDate = ...;
1410
1411
1413 const PgsqlIopMap = ...;
1414
1415
1417 const PgsqlUopMap = ...;
1418
1419
1420protected:
1422 *string tablespace;
1423
1425 string schema;
1426
1429
1432
1435
1438
1441
1444
1446 transient Mutex pg_state();
1447
1448public:
1449
1451 constructor(AbstractDatasource nds, string nname, *hash opts) ;
1452
1453
1456
1457
1460
1461
1462 PgsqlFunction addTriggerFunction(string tfname, string src, string trigger);
1463
1464
1467
1468
1470 string getColumnSqlName(string col);
1471
1472
1474
1476 list<auto> getColumnSqlNames(softlist<auto> cols);
1477
1478
1480
1484 code getUpsertClosure(hash<auto> row, int upsert_strategy = UpsertAuto, *hash<auto> opt);
1485
1486
1489
1490
1492protected:
1494public:
1495
1496
1497protected:
1498 code getUpsertAuto(Columns cols, hash<auto> row, *hash<auto> opt);
1499public:
1500
1501
1502protected:
1503 PgsqlFunction addTriggerFunctionUnlocked(string tfname, string src, string trigger);
1504public:
1505
1506
1508 string getSqlName();
1509
1510
1511protected:
1512 hash getTableCreationOptions();
1513public:
1514
1515
1516protected:
1517 hash getTableDescriptionHashOptions();
1518public:
1519
1520
1521protected:
1522 hash getColumnDescOptions();
1523public:
1524
1525
1526protected:
1527 hash getIndexOptions();
1528public:
1529
1530
1531protected:
1532 hash getConstraintOptions();
1533public:
1534
1535
1536protected:
1537 hash getAlignTableOptions();
1538public:
1539
1540
1542protected:
1544public:
1545
1546
1548protected:
1550public:
1551
1552
1554protected:
1556public:
1557
1558
1560 hash<auto> getExpressionMap();
1561
1562
1563protected:
1564 bool checkExistenceImpl();
1565public:
1566
1567
1568protected:
1569 Columns describeImpl();
1570public:
1571
1572
1573protected:
1574 PgsqlPrimaryKey getPrimaryKeyImpl();
1575public:
1576
1577
1578protected:
1579 Indexes getIndexesImpl();
1580public:
1581
1582
1583protected:
1584 ForeignConstraints getForeignConstraintsImpl(*hash opts);
1585public:
1586
1587
1588protected:
1589 Constraints getConstraintsImpl();
1590public:
1591
1592
1593protected:
1594 Triggers getTriggersImpl();
1595public:
1596
1597
1599protected:
1600 string getCreateTableSqlImpl(*hash opt);
1601public:
1602
1603
1604protected:
1605 *list getCreateMiscSqlImpl(*hash opt, bool cache);
1606public:
1607
1608
1609protected:
1610 *list getAlignSqlImpl(AbstractTable table, *hash<auto> opt);
1611public:
1612
1613
1615protected:
1616 string getCreateSqlImpl(list l);
1617public:
1618
1619
1620protected:
1621 string getRenameSqlImpl(string new_name);
1622public:
1623
1624
1625protected:
1626 AbstractColumn addColumnImpl(string cname, hash opt, bool nullable = True);
1627public:
1628
1629
1630protected:
1631 AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
1632public:
1633
1634
1635protected:
1636 AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
1637public:
1638
1639
1640protected:
1641 AbstractForeignConstraint addForeignConstraintImpl(string cname, hash<auto> ch, string table, hash<auto> tch, *hash<auto> opt);
1642public:
1643
1644
1645protected:
1646 AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
1647public:
1648
1649
1650protected:
1651 AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
1652public:
1653
1654
1655protected:
1656 AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
1657public:
1658
1659
1660protected:
1661 bool tryInsertImpl(string sql, hash<auto> row);
1662public:
1663
1664
1666
1668protected:
1669 bool isDuplicateRowErrorImpl(hash<ExceptionInfo> ex);
1670public:
1671
1672
1673protected:
1674 hash<auto> getQoreTypeMapImpl();
1675public:
1676
1677
1678protected:
1679 hash<auto> getTypeMapImpl();
1680public:
1681
1682
1684
1686protected:
1687 *string getSqlValueImpl(auto v);
1688public:
1689
1690
1691protected:
1692 bool emptyImpl();
1693public:
1694
1695
1697protected:
1699public:
1700
1701
1702protected:
1703 softlist getDropSqlImpl();
1704public:
1705
1706
1707protected:
1708 setupTableImpl(hash<auto> desc, *hash<auto> opt);
1709public:
1710
1711
1713protected:
1715public:
1716
1717
1719protected:
1721public:
1722
1723
1725protected:
1727public:
1728
1729
1731protected:
1732 doSelectLimitOnlyUnlockedImpl(reference<hash<QueryInfo>> info, reference<string> sql);
1733public:
1734
1735
1737protected:
1738 doSelectOrderByWithOffsetSqlUnlockedImpl(reference<hash<QueryInfo>> info, reference<string> sql, list<auto> coll);
1739public:
1740
1741
1743protected:
1744 auto tryExecArgsImpl(string sql, *softlist<auto> args);
1745public:
1746
1747
1749protected:
1750 auto tryExecRawImpl(string sql, *softlist<auto> args);
1751public:
1752
1753
1755protected:
1756 copyImpl(AbstractTable old);
1757public:
1758
1759
1760protected:
1761 *hash<auto> doReturningImpl(hash<auto> opt, reference<string> sql, list<auto> args);
1762public:
1763
1764
1765protected:
1766 list<auto> getGroupOrderByListUnlocked(hash<QueryInfo> info, string key, list<auto> coll);
1767public:
1768
1769
1771protected:
1772 AbstractDataProviderType getNumericTypeImpl(string native_type, bool nullable, *hash<auto> options);
1773public:
1774
1775
1777
1781protected:
1782 AbstractSavepointHelper getSavepointHelperImpl(*string savepoint);
1783public:
1784
1785 };
1786};
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:806
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:820
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:816
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:810
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:757
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:534
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:636
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:680
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:1125
const PgsqlNameMap
maps from verbose type names to simple type names
Definition: PgsqlSqlUtilBase.qm.dox.h:1133
copyImpl(AbstractTable old)
db-specific copy actions
int server_version_sub
PostgreSQL server version.
Definition: PgsqlSqlUtilBase.qm.dox.h:1443
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
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:1413
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:1417
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:1431
int server_version_major
PostgreSQL server major version.
Definition: PgsqlSqlUtilBase.qm.dox.h:1437
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,...
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:1329
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:1143
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:1440
const PgsqlTypeMap
maps PostgreSQL type names to type configurations
Definition: PgsqlSqlUtilBase.qm.dox.h:1129
AbstractSavepointHelper getSavepointHelperImpl(*string savepoint)
get DB-specific savepoint helper
string schema
schema name for the table
Definition: PgsqlSqlUtilBase.qm.dox.h:1425
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:1409
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:1434
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:1428
const QoreTypeMap
maps qore type names to PostgreSQL type names
Definition: PgsqlSqlUtilBase.qm.dox.h:1137
hash getRawUpdateOperatorMap()
returns the raw (default) update operator map for this object
const PgsqlExpressionMap
Expression map for PostgreSQL.
Definition: PgsqlSqlUtilBase.qm.dox.h:1159
*string tablespace
tablespace name for the table, if known
Definition: PgsqlSqlUtilBase.qm.dox.h:1422
represents a PostgreSQL-specific trigger function
Definition: PgsqlSqlUtilBase.qm.dox.h:795
string trigger
trigger name
Definition: PgsqlSqlUtilBase.qm.dox.h:799
represents a PostgreSQL-specific trigger
Definition: PgsqlSqlUtilBase.qm.dox.h:726
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:547
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:552
class modeling a unique constraint
Definition: PgsqlSqlUtilBase.qm.dox.h:582
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:587
represents a PostgreSQL view
Definition: PgsqlSqlUtilBase.qm.dox.h:701
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:705
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