Qore MysqlSqlUtil Module Reference 1.5
Loading...
Searching...
No Matches
MysqlSqlUtil.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* MysqlSqlUtil.qm Copyright 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
184namespace MysqlSqlUtil {
186 MysqlTable get_table(AbstractDatasource nds, string nname, *hash opts);
187
188
190 MysqlDatabase get_database(AbstractDatasource nds, *hash opts);
191
192
193 parse_schema_name(string nname, reference<*string> schema, reference<string> name);
194
195
197class MysqlSavepointHelper : public AbstractSavepointHelper {
198
199public:
201 constructor(AbstractDatasource ds, *string savepoint) ;
202
203
205protected:
207public:
208
209
211protected:
213public:
214
215
217protected:
219public:
220
221 };
222
225
226public:
228 constructor(string native_type, bool nullable, *hash<auto> options)
229 ;
230
231 };
232
235
236public:
237 string type;
238
240 constructor(string n_name, bool n_unique, hash n_cols, string n_type = 'BTREE') ;
241
242
244 string getCreateSql(string table_name, *hash opt);
245
246
248protected:
249 bool equalImpl(AbstractIndex ix);
250public:
251
252
254 string getRenameSql(string table_name, string new_name);
255
256
258 string getDropSql(string table_name);
259
260 };
261
264
265public:
266 constructor(string n, Columns c, ForeignConstraintTarget t) ;
267
268
269 string getCreateSql(string table_name, *hash opt);
270
271
273 softlist getRenameSql(string table_name, string new_name);
274
275
276 string getCreateSql(string name, string table_name, *hash opt);
277
278
279 string getAddSql(string name, string table_name, *hash opt);
280
281
283 string getDropSql(string table_name);
284
285 };
286
289
290public:
293
295protected:
297public:
298
299
300 constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, *softint bs,
301 *int scale) ;
302
303
305
312 softlist<string> getAddColumnSql(AbstractTable t);
313
314
316 string getCreateSql(AbstractTable t);
317
318
320
336 softlist<string> getModifySqlImpl(AbstractTable t, AbstractColumn col, *hash opt);
337
338
340
350 string getRenameSql(AbstractTable t, string new_name);
351
352
354
356 string getDdlName(string name);
357
358
360protected:
361 bool equalImpl(AbstractColumn c);
362public:
363
364 };
365
368
369public:
370 bool unsigned;
371 bool auto_increment;
372 // auto-incrememnt columns must be either "unique" or "primary key" in mysql
373 bool pk = False;
374
375protected:
376 // AUTO_INCREMENT applies only to integer and floating-point types
377 const AUTO_INCREMENT_VALID_TYPES = {
378 // int types
379 "tinyint": True,
380 "smallint": True,
381 "mediumint": True,
382 "int": True,
383 "bigint": True,
384 # float types
385 "float": True,
386 "real": True,
387 "double precision": True,
388 };
389
390public:
391
392 constructor(string n, string nt, *string qt, int sz, bool nul, *string dv, *string cm, softint bs,
393 softint scale, bool n_unsigned = False, bool n_auto_increment = False, bool n_pk = False)
394 ;
395
396
398private:
399 deserializeMembers(hash<auto> members);
400public:
401
402
403protected:
404 validateConstructor();
405public:
406
407
408 string getNativeTypeString();
409
410
412protected:
413 bool equalImpl(AbstractColumn c);
414public:
415
416 };
417
418class MysqlUniqueConstraintCommon : public SqlUtil::AbstractUniqueConstraint {
419
420public:
421 constructor();
422
423
424 bool setIndexBase(string ix);
425
426
428 clearIndex();
429
430
432 getIndexSql(reference<string> sql, string name, *hash opts);
433
434 };
435
436class MysqlUniqueConstraint : public SqlUtil::AbstractUniqueConstraint,public MysqlUniqueConstraintCommon {
437
438public:
439 constructor(string n, hash n_cols) ;
440
441
443
458 MysqlColumn memberGate(string k);
459
460
461 string getCreateSql(string table_name, *hash opts);
462
463
464 list getRenameSql(string table_name, string new_name);
465
466
467 string getCreateSql(string name, string table_name, *hash opts);
468
469
471 string getDropSql(string table_name);
472
473 };
474
476class MysqlPrimaryKey : public SqlUtil::AbstractPrimaryKey,public MysqlUniqueConstraintCommon {
477
478public:
479 constructor();
480
481
482 constructor(*hash c) ;
483
484
486
502
503
504 string getCreateSql(string table_name, *hash opts);
505
506
508 softlist getRenameSql(string table_name, string new_name);
509
510
512 string getDropSql(string table_name);
513
514
517
518 };
519
522
523public:
525 constructor(string n, string n_src) ;
526
527
529 softlist getCreateSql(string table_name, *hash opt);
530
531
533 softlist getDropSql(string table_name);
534
535
537protected:
538 bool equalImpl(AbstractFunctionBase t);
539public:
540
541
543 softlist getRenameSql(string table_name, string new_name);
544
545 };
546
549
550public:
551 constructor(string n, string n_src) ;
552
553
555 softlist getCreateSql(*hash opt);
556
557
559
561 string getDropSql(*hash opt);
562
563
565protected:
566 bool equalImpl(AbstractFunctionBase t);
567public:
568
569
571
574 softlist getRenameSql(string new_name, *hash opt);
575
576 };
577
580
581public:
582protected:
583 string table_name;
584
585public:
586
588 constructor(string n_table_name, string n_name, number n_start = 1, number n_increment = 1, *softnumber n_end) ;
589
590
592 string getCreateSql(*hash opt);
593
594
596
599 softlist getRenameSql(string new_name, *hash opt);
600
601
603
605 string getDropSql(*hash opt);
606
607 };
608
611
612public:
616 *string checkoption;
618 *string definer;
621
623 constructor(string n_name, string n_src, *string n_tablecatalog,
624 *string n_schema,
625 *string n_checkoption, *string n_definer,
626 *string n_securitytype, bool n_updatable)
627 ;
628
629
631 string getCreateSql(*hash opt);
632
633
635
638 softlist getRenameSql(string new_name, *hash opt);
639
640 };
641
644
645public:
647 const MysqlOptions = ...;
648
649
651 const MysqlSchemaDescriptionOptions = AbstractDatabase::SchemaDescriptionOptions + MysqlOptions;
652
654 const MysqlDatabaseOptions = AbstractDatabase::DatabaseOptions + MysqlOptions;
655
658
659
661 const MysqlSequenceFunction = "%s(seq_name varchar(40)) returns decimal(14)
662begin
663 update %s set id = last_insert_id(id + 1) where name = seq_name;
664 return last_insert_id();
665end";
666
669
670
673
674
677
678
681
682protected:
683 string schema;
684
686 Datasource seqds;
687
688 string sequence_table = "sqlutil_sequences";
689 string sequence_function = "sqlutil_nextval";
690
691public:
692
693 constructor(AbstractDatasource nds, *hash opts) ;
694
695
697
702
703
705
710
711
712protected:
713 list<string> featuresImpl();
714public:
715
716
717 string getSchemaName();
718
719
720protected:
721 AbstractSequence makeSequenceImpl(string name, number start = 1, number increment = 1, *softnumber end, *hash opts);
722public:
723
724
725protected:
726 *AbstractSequence getSequenceImpl(string name);
727public:
728
729
730protected:
731 *AbstractView getViewImpl(string name);
732public:
733
734
735protected:
736 MysqlFunction makeFunctionImpl(string name, string src, *hash opts);
737public:
738
739
740protected:
741 MysqlFunction makeProcedureImpl(string name, string src, *hash opts);
742public:
743
744
745protected:
746 *AbstractFunction getFunctionImpl(string name);
747public:
748
749
750protected:
751 static string makeParameter(hash<auto> row);
752public:
753
754
755protected:
756 AbstractFunction getProcedureImpl(string name);
757public:
758
759
760protected:
761 list getDropSchemaSqlImpl(hash schema_hash, *hash opt);
762public:
763
764
765protected:
766 list getAlignSqlImpl(hash schema_hash, *hash opt);
767public:
768
769
771protected:
772 list<string> listTablesImpl();
773public:
774
775
777
781protected:
782 list<string> listFunctionsImpl();
783public:
784
785
787
791protected:
792 list<string> listProceduresImpl();
793public:
794
795
796protected:
797 list<string> listSequencesImpl();
798public:
799
800
801protected:
802 list<string> listViewsImpl();
803public:
804
805
806protected:
807 string getCreateSqlImpl(list l);
808public:
809
810
811 static string getCreateSql(list l);
812
814protected:
816public:
817
818
820protected:
822public:
823
824
826protected:
828public:
829
830
832protected:
834public:
835
836
838protected:
839 softint getNextSequenceValueImpl(string name);
840public:
841
842
844protected:
845 softint getCurrentSequenceValueImpl(string name);
846public:
847
848
850protected:
852public:
853
854
856protected:
858public:
859
860
862protected:
864public:
865
866
868protected:
869 bool rebuildIndexImpl(string name, *hash options);
870public:
871
872
874protected:
875 computeStatisticsImpl(*hash options);
876public:
877
878
880protected:
881 reclaimSpaceImpl(*hash options);
882public:
883
884
886protected:
888public:
889
890 };
891
894
895public:
897 const MysqlTypeMap = {
898 "decimal": {
899 "qore": Type::Number,
900 "size": SZ_NUM,
901 },
902 "tinyint": ("qore": Type::Int, "ai": True,),
903 "smallint": ("qore": Type::Int, "ai": True,),
904 "mediumint": ("qore": Type::Int, "ai": True,),
905 "int": ("qore": Type::Int, "ai": True,),
906 "bigint": ("qore": Type::Int, "ai": True,),
907 "float": ("qore": Type::Float, "ai": True,),
908 "double": ("qore": Type::Float, "ai": True,),
909
910 "date": ("qore": Type::Date,),
911 "datetime": ("qore": Type::Date,),
912 "timestamp": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 6), "default_size": 6,),
913 "time": ("qore": Type::Date, "size": SZ_OPT, "size_range": (0, 6), "default_size": 6,),
914 "year": ("qore": Type::Int,),
915
916 "char": {
917 "qore": Type::String,
918 "size": SZ_OPT,
919 "size_range": (0, 255),
920 },
921 "varchar": {
922 "qore": Type::String,
923 "size": SZ_MAND,
924 "size_range": (0, 65535),
925 "default_size": AbstractColumn::DefaultVarcharSize,
926 },
927
928 "binary": ("qore": Type::Binary, "size": SZ_OPT, "size_range": (0, 255)),
929 "varbinary": {
930 "qore": Type::Binary,
931 "size": SZ_MAND,
932 "size_range": (0, 65535),
933 "default_size": 80,
934 },
935
936 "tinytext": ("qore": Type::String,),
937 "text": ("qore": Type::String,),
938 "mediumtext": ("qore": Type::String,),
939 "longtext": ("qore": Type::String,),
940
941 "tinyblob": ("qore": Type::Binary,),
942 "blob": ("qore": Type::Binary,),
943 "mediumblob": ("qore": Type::Binary,),
944 "longblob": ("qore": Type::Binary,),
945
946 "bit": ("qore": Type::Int,),
947 };
948
950 const QoreTypeMap = ...;
951
952
954
962
963
965
971
972
973 const MysqlIndexOptions = AbstractTable::IndexOptions;
974
975 const MysqlConstraintOptions = ...;
976
977
978 const MysqlTableCreationOptions = AbstractTable::TableCreationOptions + MysqlConstraintOptions;
979
980 const MysqlAlignTableOptions = AbstractTable::AlignTableOptions + MysqlTableCreationOptions;
981
983 const MysqlCopMap = ...;
984
985
987 const MysqlExpressionMap = DefaultExpressionMap + {
988 COP_CAST: {
989 "exp": <DataProviderExpressionInfo>{
990 "type": DET_Operator,
991 "label": COP_CAST,
992 "name": "cast",
993 "desc": "cast operator",
994 "symbol": "cast",
995 "args": (
996 DataProviderSignatureAnyType,
997 DataProviderSignatureStringValueType,
998 DataProviderSignatureOptionalIntValueType,
999 DataProviderSignatureOptionalIntValueType),
1000 "varargs": True,
1001 "return_type": AbstractDataProviderTypeMap."any",
1002 },
1003 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1004 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1005 AbstractDataProviderTypeMap."any");
1006 string name = QoreTypeMap{args[1]} ?? args[1];
1007 *hash<auto> desc = MysqlTypeMap{name};
1008 string sql = sprintf ("cast (%s as %s", exp0, name);
1009 if (desc.size == SZ_MAND) {
1010 if (!exists args[1] && !exists desc.size_range)
1011 throw "OPERATOR-ERROR", sprintf ("cast operator missing size for type %s",
1012 name);
1013 sql += sprintf("(%d)", args[1] ?? desc.size_range[1]);
1014 } else if (desc.size == SZ_NUM && exists args[1]) {
1015 sql += sprintf("(%d", args[1]);
1016 sql += exists args[2] ? sprintf(",%d)", args[2]) : ")";
1017 } else if (desc.size == SZ_OPT && exists args[1]) {
1018 sql += sprintf("(%d)", args[1]);
1019 }
1020 sql += ")";
1021 return sql;
1022 },
1023 },
1024 COP_PREPEND: DefaultExpressionMap{COP_PREPEND} + {
1025 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1026 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1027 AbstractDataProviderTypeMap."string");
1028 string exp1 = info.table.getExpressionArg(\info, role, args[1],
1029 AbstractDataProviderTypeMap."string");
1030 return sprintf("concat(%s, %s)", exp1, exp0);
1031 },
1032 },
1033 COP_APPEND: DefaultExpressionMap{COP_APPEND} + {
1034 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1035 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1036 AbstractDataProviderTypeMap."string");
1037 string exp1 = info.table.getExpressionArg(\info, role, args[1],
1038 AbstractDataProviderTypeMap."string");
1039 return sprintf("concat(%s, %s)", exp0, exp1);
1040 },
1041 },
1042 COP_YEAR: {
1043 "exp": <DataProviderExpressionInfo>{
1044 "type": DET_Operator,
1045 "label": COP_YEAR,
1046 "name": COP_YEAR,
1047 "desc": "returns the year component of a date as a string (ex: `2022`)",
1048 "symbol": COP_YEAR,
1049 "args": (
1050 DataProviderSignatureDateType,
1051 ),
1052 "return_type": AbstractDataProviderTypeMap."string",
1053 },
1054 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1055 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1056 AbstractDataProviderTypeMap."date");
1057 return sprintf("date_format(%s, '%%Y')", exp0);
1058 }
1059 },
1060 COP_YEAR_MONTH: {
1061 "exp": <DataProviderExpressionInfo>{
1062 "type": DET_Operator,
1063 "label": COP_YEAR_MONTH,
1064 "name": COP_YEAR_MONTH,
1065 "desc": "returns the year and month components of a date as a string (ex: `2022-06`)",
1066 "symbol": COP_YEAR_MONTH,
1067 "args": (
1068 DataProviderSignatureDateType,
1069 ),
1070 "return_type": AbstractDataProviderTypeMap."string",
1071 },
1072 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1073 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1074 AbstractDataProviderTypeMap."date");
1075 return sprintf("date_format(%s, '%%Y-%%m')", exp0);
1076 }
1077 },
1078 COP_YEAR_DAY: {
1079 "exp": <DataProviderExpressionInfo>{
1080 "type": DET_Operator,
1081 "label": COP_YEAR_DAY,
1082 "name": COP_YEAR_DAY,
1083 "desc": "returns the year, month, and day components of a date as a string (ex: `2022-06-29`)",
1084 "symbol": COP_YEAR_DAY,
1085 "args": (
1086 DataProviderSignatureDateType,
1087 ),
1088 "return_type": AbstractDataProviderTypeMap."string",
1089 },
1090 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1091 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1092 AbstractDataProviderTypeMap."date");
1093 return sprintf("date_format(%s, '%%Y-%%m-%%e')", exp0);
1094 }
1095 },
1096 COP_YEAR_HOUR: {
1097 "exp": <DataProviderExpressionInfo>{
1098 "type": DET_Operator,
1099 "label": COP_YEAR_HOUR,
1100 "name": COP_YEAR_HOUR,
1101 "desc": "returns the year, month, day, and hour components of a date as a string "
1102 "(ex: `2022-06-29 15`)",
1103 "symbol": COP_YEAR_HOUR,
1104 "args": (
1105 DataProviderSignatureDateType,
1106 ),
1107 "return_type": AbstractDataProviderTypeMap."string",
1108 },
1109 "code": string sub (reference<hash<QueryInfo>> info, int role, list<auto> args) {
1110 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1111 AbstractDataProviderTypeMap."date");
1112 return sprintf("date_format(%s, '%%Y-%%m-%%e %%k')", exp0);
1113 }
1114 },
1115 COP_TRUNC_DATE: {
1116 "exp": <DataProviderExpressionInfo>{
1117 "type": DET_Operator,
1118 "label": COP_TRUNC_DATE,
1119 "name": COP_TRUNC_DATE,
1120 "desc": "truncates the given date to the given resolution; args: date, string code: Y: year, "
1121 "M: month, D: day, H: hour, m: minute, S: second",
1122 "symbol": COP_TRUNC_DATE,
1123 "args": (
1124 DataProviderSignatureDateType,
1125 DataProviderSignatureStringValueType,
1126 ),
1127 "return_type": AbstractDataProviderTypeMap."date",
1128 },
1129 "code": string sub(reference<hash<QueryInfo>> info, int role, list<auto> args) {
1130 *string str = MysqlTruncDate{args[1]};
1131 if (!str) {
1132 throw "COP-TRUNC-DATE-ERROR", sprintf("unknown date truncation format argument %y; "
1133 "supported date format arguments: %y", args[1], keys MysqlTruncDate);
1134 }
1135 string exp0 = info.table.getExpressionArg(\info, role, args[0],
1136 AbstractDataProviderTypeMap."date");
1137 return sprintf("cast(date_format(%s, %s) as datetime)", exp0, str);
1138 },
1139 },
1140 };
1141
1143 const MysqlOpMap = DefaultOpMap + {
1144 COP_PREPEND: {
1145 "arg": Type::String,
1146 "sqlvalue": True,
1147 "code": string sub (string cve, string arg) {
1148 return sprintf("concat(%s, %s)", arg, cve);
1149 },
1150 },
1151 COP_APPEND: {
1152 "arg": Type::String,
1153 "sqlvalue": True,
1154 "code": string sub (string cve, string arg) {
1155 return sprintf("concat(%s, %s)", cve, arg);
1156 },
1157 },
1158 };
1159
1162 DT_YEAR : "'%Y-01-01 00:00:00'",
1163 DT_MONTH : "'%Y-%m-01 00:00:00'",
1164 DT_DAY : "'%Y-%m-%d 00:00:00'",
1165 DT_HOUR : "'%Y-%m-%d %H:00:00'",
1166 DT_MINUTE: "'%Y-%m-%d %H:%i:00'",
1167 DT_SECOND: "'%Y-%m-%d %H:%i:%s'",
1168 };
1169
1170protected:
1171 string schema;
1172 string engine = "innodb";
1173 string collation;
1174 string table_encoding;
1175
1176public:
1177
1178 constructor(AbstractDatasource nds, string nname, *hash opts) ;
1179
1180
1182 string getSqlName();
1183
1184
1186 hash<auto> getExpressionMap();
1187
1188
1191
1192
1193protected:
1194 hash getTableCreationOptions();
1195public:
1196
1197
1198protected:
1199 hash getTableDescriptionHashOptions();
1200public:
1201
1202
1203protected:
1204 hash getColumnDescOptions();
1205public:
1206
1207
1208protected:
1209 hash getIndexOptions();
1210public:
1211
1212
1213protected:
1214 hash getConstraintOptions();
1215public:
1216
1217
1218protected:
1219 hash getAlignTableOptions();
1220public:
1221
1222
1224protected:
1226public:
1227
1228
1229protected:
1230 bool checkExistenceImpl();
1231public:
1232
1233
1234protected:
1235 Columns describeImpl();
1236public:
1237
1238
1239protected:
1240 *string getCreatePrimaryKeySqlUnlocked(*hash opt, bool cache = True);
1241public:
1242
1243
1244protected:
1245 MysqlPrimaryKey getPrimaryKeyImpl();
1246public:
1247
1248
1249protected:
1250 Indexes getIndexesImpl();
1251public:
1252
1253
1254protected:
1255 ForeignConstraints getForeignConstraintsImpl(*hash opts);
1256public:
1257
1258
1259protected:
1260 Constraints getConstraintsImpl();
1261public:
1262
1263
1264protected:
1265 Triggers getTriggersImpl();
1266public:
1267
1268
1269 string getCreateTableSqlImpl(*hash opt);
1270
1271
1274
1275
1276protected:
1277 *list getCreateMiscSqlImpl(*hash opt, bool cache);
1278public:
1279
1280
1281protected:
1282 *list getAlignSqlImpl(AbstractTable table, *hash opt);
1283public:
1284
1285
1286protected:
1287 string getCreateSqlImpl(list l);
1288public:
1289
1290
1291protected:
1292 string getRenameSqlImpl(string new_name);
1293public:
1294
1295
1296protected:
1297 AbstractColumn addColumnImpl(string cname, hash<auto> opt, bool nullable = True);
1298public:
1299
1300
1301protected:
1302 setPrimaryKeyUnlocked(AbstractPrimaryKey pk);
1303public:
1304
1305
1306protected:
1307 addColumnToTableUnlocked(AbstractColumn c);
1308public:
1309
1310
1311protected:
1312 AbstractPrimaryKey addPrimaryKeyImpl(string cname, hash ch, *hash opt);
1313public:
1314
1315
1316protected:
1317 AbstractIndex addIndexImpl(string iname, bool enabled, hash ch, *hash opt);
1318public:
1319
1320
1321protected:
1322 AbstractForeignConstraint addForeignConstraintImpl(string cname, hash ch, string table, hash tch, *hash opt);
1323public:
1324
1325
1326protected:
1327 AbstractCheckConstraint addCheckConstraintImpl(string cname, string src, *hash opt);
1328public:
1329
1330
1331protected:
1332 AbstractUniqueConstraint addUniqueConstraintImpl(string cname, hash ch, *hash opt);
1333public:
1334
1335
1336protected:
1337 AbstractTrigger addTriggerImpl(string tname, string src, *hash opt);
1338public:
1339
1340
1341protected:
1342 bool tryInsertImpl(string sql, hash<auto> row);
1343public:
1344
1345
1347
1349protected:
1350 bool isDuplicateRowErrorImpl(hash<ExceptionInfo> ex);
1351public:
1352
1353
1354protected:
1355 hash getQoreTypeMapImpl();
1356public:
1357
1358
1359protected:
1360 hash getTypeMapImpl();
1361public:
1362
1363
1365protected:
1366 *string getSqlValueImpl(auto v);
1367public:
1368
1369
1371protected:
1372 static *string getSqlValueIntern(auto v);
1373public:
1374
1375
1377
1379 string getColumnSqlName(string col);
1380
1381
1383 list getColumnSqlNames(softlist cols);
1384
1385
1387
1398 static *string getSqlValue(auto v);
1399
1400protected:
1401 bool emptyImpl();
1402public:
1403
1404
1405protected:
1406 preSetupTableImpl(reference<hash> desc, *hash opt);
1407public:
1408
1409
1410protected:
1411 setupTableImpl(hash desc, *hash opt);
1412public:
1413
1414
1416protected:
1418public:
1419
1420
1422protected:
1424public:
1425
1426
1428protected:
1430public:
1431
1432
1434protected:
1435 doSelectLimitOnlyUnlockedImpl(reference<hash<QueryInfo>> info, reference<string> sql);
1436public:
1437
1438
1440 private doSelectOrderByWithOffsetSqlUnlockedImpl(reference<hash<QueryInfo>> info, reference<string> sql,
1441 list<auto> coll) {
1442 doSelectOrderBySqlUnlocked(info, \sql, coll);
1443 if (info.query_hash.limit);
1444
1445
1446 if (info.query_hash.offset);
1447
1448 }
1449
1451protected:
1453public:
1454
1455
1456protected:
1457 *hash<auto> doReturningImpl(hash<auto> opt, reference<string> sql, list<auto> args);
1458public:
1459
1460
1461protected:
1462 list<auto> getGroupOrderByListUnlocked(hash<QueryInfo> info, string key, list<auto> coll);
1463public:
1464
1465
1468
1469
1471protected:
1472 copyImpl(AbstractTable old);
1473public:
1474
1475
1477protected:
1478 AbstractDataProviderType getNumericTypeImpl(string native_type, bool nullable, *hash<auto> options);
1479public:
1480
1481
1483
1487protected:
1488 AbstractSavepointHelper getSavepointHelperImpl(*string savepoint);
1489public:
1490
1491 };
1492};
represents a MySQL-specific column
Definition: MysqlSqlUtil.qm.dox.h:288
softlist< string > getAddColumnSql(AbstractTable t)
returns a list of sql strings that can be used to add the column to an existing table
softlist< string > 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
string getCreateSql(AbstractTable t)
returns an sql string that can be used to add the column to a table
constructor()
empty constructor for subclasses
string getRenameSql(AbstractTable t, string new_name)
returns a string that can be used to rename the column
int byte_size
byte size of the column
Definition: MysqlSqlUtil.qm.dox.h:292
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 MySQL-specific implementation of the AbstractDatabase interface
Definition: MysqlSqlUtil.qm.dox.h:643
bool rebuildIndexImpl(string name, *hash options)
rebuild index implementation. See SqlUtil::AbstractDatabase::rebuildIndex()
const MysqlSequenceTable
MySQL sequence emulation table.
Definition: MysqlSqlUtil.qm.dox.h:657
const MysqlComputeStatisticsOptions
Options for computeStatistics()
Definition: MysqlSqlUtil.qm.dox.h:668
const MysqlSchemaDescriptionOptions
MySQL-specific schema description keys.
Definition: MysqlSqlUtil.qm.dox.h:651
bool requiresScale()
Returns True if the driver requires a scale to support decimal values in numeric or decimal columns.
Datasource seqds
separate datasource dedicated for extern sequence implementation with autonomous transactions
Definition: MysqlSqlUtil.qm.dox.h:686
list< string > listProceduresImpl()
returns a list of string procedure names in the database
int getMaximumPrecision()
Returns the maximum precision for numeric or decimal columns.
softint getNextSequenceValueImpl(string name)
returns the next value in the given sequence
const MysqlMaxPrecision
Maximum precision.
Definition: MysqlSqlUtil.qm.dox.h:680
bool supportsPackagesImpl()
returns True if the database supports packages
hash getSchemaDescriptionOptions()
returns driver-specific options to the base abstract class
int getPhysicalSizeImpl()
SqlUtil::AbstractDatabase::getPhysicalSize()
const MysqlReclaimSpaceOptions
Options for reclaimSpace()
Definition: MysqlSqlUtil.qm.dox.h:672
const MysqlReservedWords
hash of reserved words
Definition: MysqlSqlUtil.qm.dox.h:676
computeStatisticsImpl(*hash options)
compute statistics implementation. See SqlUtil::AbstractDatabase::computeStatistics()
hash getDatabaseOptions()
returns driver-specific options to the base abstract class
const MysqlSequenceFunction
MySQL sequence function.
Definition: MysqlSqlUtil.qm.dox.h:661
reclaimSpaceImpl(*hash options)
reclaim space implementation. See SqlUtil::AbstractDatabase::reclaimSpace()
softint getCurrentSequenceValueImpl(string name)
returns the last value issued for the given sequence in the current session
list< string > listFunctionsImpl()
returns a list of string function names in the database
hash getReclaimSpaceOptions()
returns driver-specific options to the base abstract class
bool supportsTypesImpl()
returns True if the database supports named types
list< string > listTablesImpl()
returns a list of string table names in the database
hash getComputeStatisticsOptions()
returns driver-specific options to the base abstract class
bool supportsSequencesImpl()
returns True since we have a workaround implementation for sequences in MySQL
const MysqlOptions
MySQL-specific options.
Definition: MysqlSqlUtil.qm.dox.h:647
const MysqlDatabaseOptions
MySQL-specific database options.
Definition: MysqlSqlUtil.qm.dox.h:654
represents a MySQL-specific foreign constraint
Definition: MysqlSqlUtil.qm.dox.h:263
string getDropSql(string table_name)
returns a string that can be used to drop the foreign constraint from the database
softlist getRenameSql(string table_name, string new_name)
returns a string that drops the constraint and re-adds it, since MySQL does not support renaming cons...
represents a MySQL-specific function
Definition: MysqlSqlUtil.qm.dox.h:548
softlist getCreateSql(*hash opt)
returns a string that can be used to create the function in the database
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
string getDropSql(*hash opt)
returns a string that can be used to drop the function from the database
softlist getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename the function in the database
represents a MySQL-specific index
Definition: MysqlSqlUtil.qm.dox.h:234
constructor(string n_name, bool n_unique, hash n_cols, string n_type='BTREE')
creates the object from the arguments
string getDropSql(string table_name)
returns a string that can be used to drop the index from the table
string getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the index in the database
string getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the index in the database; hwoever mysql does not support...
bool equalImpl(AbstractIndex ix)
returns True if the argument is equal to the current index, False if not
the data type for DECIMAL columns
Definition: MysqlSqlUtil.qm.dox.h:224
constructor(string native_type, bool nullable, *hash< auto > options)
creates the object
represents a MySQL-specific numeric column
Definition: MysqlSqlUtil.qm.dox.h:367
bool equalImpl(AbstractColumn c)
returns True if the argument is equal to the current object, False if not
deserializeMembers(hash< auto > members)
deserializes the hash to a replica of the original object
represents a MySQL-specific primary key constraint
Definition: MysqlSqlUtil.qm.dox.h:476
MysqlColumn memberGate(string k)
returns the MysqlColumn value of the given key if it exists, otherwise throws a KEY-ERROR exception
string getDropSql(string table_name)
returns a string that can be used to drop the constraint from the database
bool supportsName()
returns False since primary key constraints in MySQL have no name
softlist getRenameSql(string table_name, string new_name)
primary keys have no name in MySQL so this method returns an empty list
MySQL savepoint helper.
Definition: MysqlSqlUtil.qm.dox.h:197
deleteSavepointImpl()
Deletes the savepoint.
createSavepointImpl()
Creates the savepoint.
constructor(AbstractDatasource ds, *string savepoint)
Creates the object.
rollbackImpl()
Rolls back to the savepoint.
class for MySQL sequences based on a sequence table and autonomous transactions
Definition: MysqlSqlUtil.qm.dox.h:579
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
string getDropSql(*hash opt)
returns a string that can be used to drop the sequence from the database
constructor(string n_table_name, string n_name, number n_start=1, number n_increment=1, *softnumber n_end)
creates the object from the arguments
provides the MySQL-specific implementation of the AbstractTable interface
Definition: MysqlSqlUtil.qm.dox.h:893
hash< auto > getExpressionMap()
Returns the expression map for MySQL.
bool isDuplicateRowErrorImpl(hash< ExceptionInfo > ex)
Returns True if the exception was raised because of a duplicate row / key error.
hash< auto > getWhereOperatorMap()
returns the "where" operator map for MySQL
bool hasReturningImpl()
returns True if the current driver supports the "returning" clause in insert statements
list getColumnSqlNames(softlist cols)
returns a list of column names for use in SQL strings; subclasses can process the argument list in ca...
string getColumnSqlName(string col)
returns the column name for use in SQL strings; subclasses can return a special string in case the co...
const QoreTypeMap
maps qore type names to MySQL type names
Definition: MysqlSqlUtil.qm.dox.h:950
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: MysqlSqlUtil.qm.dox.h:1440
bool constraintsLinkedToIndexesImpl()
returns True if the database links constraints to indexes (ie dropping the constraint drops the index...
doSelectLimitOnlyUnlockedImpl(reference< hash< QueryInfo > > info, reference< string > sql)
processes a string for use in SQL select statements when there is a "limit" argument,...
const MysqlTypeMap
maps mysql type names to type configurations
Definition: MysqlSqlUtil.qm.dox.h:897
bool supportsTablespacesImpl()
returns True if the database support tablespaces
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...
hash getColumnOperatorMapImpl()
returns the column operator map for this object
bool asteriskRequiresPrefix()
returns True if the database requires a wildcard "*" to be prefixed with the table name when it appea...
string getSqlName()
returns the name of the table to be used in SQL (with a possible qualifiers for schema,...
static *string getSqlValue(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument
bool hasArrayBind()
returns False because the mysql driver does not support array binds / bulk DML operations
const MysqlOpMap
where operator specializations for MySQL
Definition: MysqlSqlUtil.qm.dox.h:1143
const MysqlTableDescriptionHashOptions
extends SqlUtil::AbstractTable::TableDescriptionHashOptions
Definition: MysqlSqlUtil.qm.dox.h:961
const MysqlExpressionMap
MySQL Expression map.
Definition: MysqlSqlUtil.qm.dox.h:987
const MysqlTruncDate
Map SqlUtil::cop_trunc_date() constants for internal masks.
Definition: MysqlSqlUtil.qm.dox.h:1161
const MysqlCopMap
column operator specializations for MySQL
Definition: MysqlSqlUtil.qm.dox.h:983
const MysqlColumnDescOptions
extends SqlUtil::AbstractTable::ColumnDescOptions with MySQL-specific values
Definition: MysqlSqlUtil.qm.dox.h:970
static *string getSqlValueIntern(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
copyImpl(AbstractTable old)
db-specific copy actions
AbstractSavepointHelper getSavepointHelperImpl(*string savepoint)
get DB-specific savepoint helper
bool uniqueIndexCreatesConstraintImpl()
returns True if the database automatically creates a unique constraint when a unique index is created...
*string getSqlValueImpl(auto v)
returns a string for use in SQL queries representing the DB-specific value of the argument; returns N...
represents a MySQL-specific trigger
Definition: MysqlSqlUtil.qm.dox.h:521
bool equalImpl(AbstractFunctionBase t)
returns True if the argument is equal to the current object, False if not
softlist getCreateSql(string table_name, *hash opt)
returns a string that can be used to create the trigger in the database
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
softlist getRenameSql(string table_name, string new_name)
returns a string that can be used to rename the trigger in the database
represents a MySQL view
Definition: MysqlSqlUtil.qm.dox.h:610
constructor(string n_name, string n_src, *string n_tablecatalog, *string n_schema, *string n_checkoption, *string n_definer, *string n_securitytype, bool n_updatable)
creates the object from the arguments
softlist getRenameSql(string new_name, *hash opt)
returns a string that can be used to rename the view in the database
string getCreateSql(*hash opt)
returns a string that can be used to create the view in the database
*string tablecatalog
table catalog value
Definition: MysqlSqlUtil.qm.dox.h:614
*string definer
dafiner clause
Definition: MysqlSqlUtil.qm.dox.h:618
*string checkoption
checkoption clause
Definition: MysqlSqlUtil.qm.dox.h:616
*string securitytype
security type value
Definition: MysqlSqlUtil.qm.dox.h:620
cache(*hash< auto > opts)
the MysqlSqlUtil namespace contains all the objects in the MysqlSqlUtil module
Definition: MysqlSqlUtil.qm.dox.h:184
MysqlDatabase get_database(AbstractDatasource nds, *hash opts)
returns a MysqlDatabase object corresponding to the arguments
MysqlTable get_table(AbstractDatasource nds, string nname, *hash opts)
returns a MysqlTable object corresponding to the arguments