QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
qgsabstractdatabaseproviderconnection.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsabstractdatabaseproviderconnection.cpp - QgsAbstractDatabaseProviderConnection
3
4 ---------------------
5 begin : 2.8.2019
6 copyright : (C) 2019 by Alessandro Pasotti
7 email : elpaso at itopen dot it
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
17
18#include "qgsexception.h"
19#include "qgsfeedback.h"
21#include "qgssqlstatement.h"
22#include "qgsvectorlayer.h"
23#include "qgsweakrelation.h"
24
25#include <QObject>
26#include <QString>
27#include <QVariant>
28
29#include "moc_qgsabstractdatabaseproviderconnection.cpp"
30
31using namespace Qt::StringLiterals;
32
38
44
49
54
59
64
66{
67 throw QgsProviderConnectionException( QObject::tr( "Operation 'createVectorLayerExporterDestinationUri' is not supported" ) );
68}
69
70QString QgsAbstractDatabaseProviderConnection::tableUri( const QString &schema, const QString &name ) const
71{
72 Q_UNUSED( schema )
73 Q_UNUSED( name )
74 throw QgsProviderConnectionException( QObject::tr( "Operation 'tableUri' is not supported" ) );
75}
76
77
79void QgsAbstractDatabaseProviderConnection::checkCapability( QgsAbstractDatabaseProviderConnection::Capability capability ) const
80{
81 if ( ! mCapabilities.testFlag( capability ) )
82 {
83 static QMetaEnum metaEnum = QMetaEnum::fromType<QgsAbstractDatabaseProviderConnection::Capability>();
84 const QString capName { metaEnum.valueToKey( capability ) };
85 throw QgsProviderConnectionException( QObject::tr( "Operation '%1' is not supported for this connection" ).arg( capName ) );
86 }
87}
88
89void QgsAbstractDatabaseProviderConnection::checkCapability( Qgis::DatabaseProviderConnectionCapability2 capability ) const
90{
91 if ( ! mCapabilities2.testFlag( capability ) )
92 {
93 throw QgsProviderConnectionException( QObject::tr( "Operation '%1' is not supported for this connection" ).arg( qgsEnumValueToKey( capability ) ) );
94 }
95}
96
97QString QgsAbstractDatabaseProviderConnection::sanitizeSqlForQueryLayer( const QString &sql ) const
98{
99 QString sanitizedSql { sql.trimmed() };
100 while ( sanitizedSql.endsWith( ';' ) )
101 {
102 sanitizedSql.chop( 1 );
103 }
104 return sanitizedSql;
105}
106
108
113
114QMultiMap<Qgis::SqlKeywordCategory, QStringList> QgsAbstractDatabaseProviderConnection::sqlDictionary()
115{
116 return
117 {
118 // Common constants
119 {
121 u"NULL"_s,
122 u"FALSE"_s,
123 u"TRUE"_s,
124 }
125 },
126 // Common SQL reserved words
127 // From: GET https://en.wikipedia.org/wiki/SQL_reserved_words| grep 'style="background: #ececec; color: black; font-weight: bold;'| sed -e 's/.*>//'|sort
128 {
130 {
131 u"ABORT "_s,
132 u"ABORTSESSION"_s,
133 u"ABS"_s,
134 u"ABSOLUTE"_s,
135 u"ACCESS"_s,
136 u"ACCESSIBLE"_s,
137 u"ACCESS_LOCK"_s,
138 u"ACCOUNT"_s,
139 u"ACOS"_s,
140 u"ACOSH"_s,
141 u"ACTION"_s,
142 u"ADD"_s,
143 u"ADD_MONTHS"_s,
144 u"ADMIN"_s,
145 u"AFTER"_s,
146 u"AGGREGATE"_s,
147 u"ALIAS"_s,
148 u"ALL"_s,
149 u"ALLOCATE"_s,
150 u"ALLOW"_s,
151 u"ALTER"_s,
152 u"ALTERAND"_s,
153 u"AMP"_s,
154 u"ANALYSE"_s,
155 u"ANALYZE"_s,
156 u"AND"_s,
157 u"ANSIDATE"_s,
158 u"ANY"_s,
159 u"ARE"_s,
160 u"ARRAY"_s,
161 u"ARRAY_AGG"_s,
162 u"ARRAY_EXISTS"_s,
163 u"ARRAY_MAX_CARDINALITY"_s,
164 u"AS"_s,
165 u"ASC"_s,
166 u"ASENSITIVE"_s,
167 u"ASIN"_s,
168 u"ASINH"_s,
169 u"ASSERTION"_s,
170 u"ASSOCIATE"_s,
171 u"ASUTIME"_s,
172 u"ASYMMETRIC"_s,
173 u"AT"_s,
174 u"ATAN"_s,
175 u"ATAN2"_s,
176 u"ATANH"_s,
177 u"ATOMIC"_s,
178 u"AUDIT"_s,
179 u"AUTHORIZATION"_s,
180 u"AUX"_s,
181 u"AUXILIARY"_s,
182 u"AVE"_s,
183 u"AVERAGE"_s,
184 u"AVG"_s,
185 u"BACKUP"_s,
186 u"BEFORE"_s,
187 u"BEGIN"_s,
188 u"BEGIN_FRAME"_s,
189 u"BEGIN_PARTITION"_s,
190 u"BETWEEN"_s,
191 u"BIGINT"_s,
192 u"BINARY"_s,
193 u"BIT"_s,
194 u"BLOB"_s,
195 u"BOOLEAN"_s,
196 u"BOTH"_s,
197 u"BREADTH"_s,
198 u"BREAK"_s,
199 u"BROWSE"_s,
200 u"BT"_s,
201 u"BUFFERPOOL"_s,
202 u"BULK"_s,
203 u"BUT"_s,
204 u"BY"_s,
205 u"BYTE"_s,
206 u"BYTEINT"_s,
207 u"BYTES"_s,
208 u"CALL"_s,
209 u"CALLED"_s,
210 u"CAPTURE"_s,
211 u"CARDINALITY"_s,
212 u"CASCADE"_s,
213 u"CASCADED"_s,
214 u"CASE"_s,
215 u"CASE_N"_s,
216 u"CASESPECIFIC"_s,
217 u"CAST"_s,
218 u"CATALOG"_s,
219 u"CCSID"_s,
220 u"CD"_s,
221 u"CEIL"_s,
222 u"CEILING"_s,
223 u"CHANGE"_s,
224 u"CHAR"_s,
225 u"CHAR2HEXINT"_s,
226 u"CHARACTER"_s,
227 u"CHARACTER_LENGTH"_s,
228 u"CHARACTERS"_s,
229 u"CHAR_LENGTH"_s,
230 u"CHARS"_s,
231 u"CHECK"_s,
232 u"CHECKPOINT"_s,
233 u"CLASS"_s,
234 u"CLASSIFIER"_s,
235 u"CLOB"_s,
236 u"CLONE"_s,
237 u"CLOSE"_s,
238 u"CLUSTER"_s,
239 u"CLUSTERED"_s,
240 u"CM"_s,
241 u"COALESCE"_s,
242 u"COLLATE"_s,
243 u"COLLATION"_s,
244 u"COLLECT"_s,
245 u"COLLECTION"_s,
246 u"COLLID"_s,
247 u"COLUMN"_s,
248 u"COLUMN_VALUE"_s,
249 u"COMMENT"_s,
250 u"COMMIT"_s,
251 u"COMPLETION"_s,
252 u"COMPRESS"_s,
253 u"COMPUTE"_s,
254 u"CONCAT"_s,
255 u"CONCURRENTLY"_s,
256 u"CONDITION"_s,
257 u"CONNECT"_s,
258 u"CONNECTION"_s,
259 u"CONSTRAINT"_s,
260 u"CONSTRAINTS"_s,
261 u"CONSTRUCTOR"_s,
262 u"CONTAINS"_s,
263 u"CONTAINSTABLE"_s,
264 u"CONTENT"_s,
265 u"CONTINUE"_s,
266 u"CONVERT"_s,
267 u"CONVERT_TABLE_HEADER"_s,
268 u"COPY"_s,
269 u"CORR"_s,
270 u"CORRESPONDING"_s,
271 u"COS"_s,
272 u"COSH"_s,
273 u"COUNT"_s,
274 u"COVAR_POP"_s,
275 u"COVAR_SAMP"_s,
276 u"CREATE"_s,
277 u"CROSS"_s,
278 u"CS"_s,
279 u"CSUM"_s,
280 u"CT"_s,
281 u"CUBE"_s,
282 u"CUME_DIST"_s,
283 u"CURRENT"_s,
284 u"CURRENT_CATALOG"_s,
285 u"CURRENT_DATE"_s,
286 u"CURRENT_DEFAULT_TRANSFORM_GROUP"_s,
287 u"CURRENT_LC_CTYPE"_s,
288 u"CURRENT_PATH"_s,
289 u"CURRENT_ROLE"_s,
290 u"CURRENT_ROW"_s,
291 u"CURRENT_SCHEMA"_s,
292 u"CURRENT_SERVER"_s,
293 u"CURRENT_TIME"_s,
294 u"CURRENT_TIMESTAMP"_s,
295 u"CURRENT_TIMEZONE"_s,
296 u"CURRENT_TRANSFORM_GROUP_FOR_TYPE"_s,
297 u"CURRENT_USER"_s,
298 u"CURRVAL"_s,
299 u"CURSOR"_s,
300 u"CV"_s,
301 u"CYCLE"_s,
302 u"DATA"_s,
303 u"DATABASE"_s,
304 u"DATABASES"_s,
305 u"DATABLOCKSIZE"_s,
306 u"DATE"_s,
307 u"DATEFORM"_s,
308 u"DAY"_s,
309 u"DAY_HOUR"_s,
310 u"DAY_MICROSECOND"_s,
311 u"DAY_MINUTE"_s,
312 u"DAYS"_s,
313 u"DAY_SECOND"_s,
314 u"DBCC"_s,
315 u"DBINFO"_s,
316 u"DEALLOCATE"_s,
317 u"DEC"_s,
318 u"DECFLOAT"_s,
319 u"DECIMAL"_s,
320 u"DECLARE"_s,
321 u"DEFAULT"_s,
322 u"DEFERRABLE"_s,
323 u"DEFERRED"_s,
324 u"DEFINE"_s,
325 u"DEGREES"_s,
326 u"DEL"_s,
327 u"DELAYED"_s,
328 u"DELETE"_s,
329 u"DENSE_RANK"_s,
330 u"DENY"_s,
331 u"DEPTH"_s,
332 u"DEREF"_s,
333 u"DESC"_s,
334 u"DESCRIBE"_s,
335 u"DESCRIPTOR"_s,
336 u"DESTROY"_s,
337 u"DESTRUCTOR"_s,
338 u"DETERMINISTIC"_s,
339 u"DIAGNOSTIC"_s,
340 u"DIAGNOSTICS"_s,
341 u"DICTIONARY"_s,
342 u"DISABLE"_s,
343 u"DISABLED"_s,
344 u"DISALLOW"_s,
345 u"DISCONNECT"_s,
346 u"DISK"_s,
347 u"DISTINCT"_s,
348 u"DISTINCTROW"_s,
349 u"DISTRIBUTED"_s,
350 u"DIV"_s,
351 u"DO"_s,
352 u"DOCUMENT"_s,
353 u"DOMAIN"_s,
354 u"DOUBLE"_s,
355 u"DROP"_s,
356 u"DSSIZE"_s,
357 u"DUAL"_s,
358 u"DUMP"_s,
359 u"DYNAMIC"_s,
360 u"EACH"_s,
361 u"ECHO"_s,
362 u"EDITPROC"_s,
363 u"ELEMENT"_s,
364 u"ELSE"_s,
365 u"ELSEIF"_s,
366 u"EMPTY"_s,
367 u"ENABLED"_s,
368 u"ENCLOSED"_s,
369 u"ENCODING"_s,
370 u"ENCRYPTION"_s,
371 u"END"_s,
372 u"END-EXEC"_s,
373 u"END_FRAME"_s,
374 u"ENDING"_s,
375 u"END_PARTITION"_s,
376 u"EQ"_s,
377 u"EQUALS"_s,
378 u"ERASE"_s,
379 u"ERRLVL"_s,
380 u"ERROR"_s,
381 u"ERRORFILES"_s,
382 u"ERRORTABLES"_s,
383 u"ESCAPE"_s,
384 u"ESCAPED"_s,
385 u"ET"_s,
386 u"EVERY"_s,
387 u"EXCEPT"_s,
388 u"EXCEPTION"_s,
389 u"EXCLUSIVE"_s,
390 u"EXEC"_s,
391 u"EXECUTE"_s,
392 u"EXISTS"_s,
393 u"EXIT"_s,
394 u"EXP"_s,
395 u"EXPLAIN"_s,
396 u"EXTERNAL"_s,
397 u"EXTRACT"_s,
398 u"FALLBACK"_s,
399 u"FALSE"_s,
400 u"FASTEXPORT"_s,
401 u"FENCED"_s,
402 u"FETCH"_s,
403 u"FIELDPROC"_s,
404 u"FILE"_s,
405 u"FILLFACTOR"_s,
406 u"FILTER"_s,
407 u"FINAL"_s,
408 u"FIRST"_s,
409 u"FIRST_VALUE"_s,
410 u"FLOAT"_s,
411 u"FLOAT4"_s,
412 u"FLOAT8"_s,
413 u"FLOOR"_s,
414 u"FOR"_s,
415 u"FORCE"_s,
416 u"FOREIGN"_s,
417 u"FORMAT"_s,
418 u"FOUND"_s,
419 u"FRAME_ROW"_s,
420 u"FREE"_s,
421 u"FREESPACE"_s,
422 u"FREETEXT"_s,
423 u"FREETEXTTABLE"_s,
424 u"FREEZE"_s,
425 u"FROM"_s,
426 u"FULL"_s,
427 u"FULLTEXT"_s,
428 u"FUNCTION"_s,
429 u"FUSION"_s,
430 u"GE"_s,
431 u"GENERAL"_s,
432 u"GENERATED"_s,
433 u"GET"_s,
434 u"GIVE"_s,
435 u"GLOBAL"_s,
436 u"GO"_s,
437 u"GOTO"_s,
438 u"GRANT"_s,
439 u"GRAPHIC"_s,
440 u"GROUP"_s,
441 u"GROUPING"_s,
442 u"GROUPS"_s,
443 u"GT"_s,
444 u"HANDLER"_s,
445 u"HASH"_s,
446 u"HASHAMP"_s,
447 u"HASHBAKAMP"_s,
448 u"HASHBUCKET"_s,
449 u"HASHROW"_s,
450 u"HAVING"_s,
451 u"HELP"_s,
452 u"HIGH_PRIORITY"_s,
453 u"HOLD"_s,
454 u"HOLDLOCK"_s,
455 u"HOST"_s,
456 u"HOUR"_s,
457 u"HOUR_MICROSECOND"_s,
458 u"HOUR_MINUTE"_s,
459 u"HOURS"_s,
460 u"HOUR_SECOND"_s,
461 u"IDENTIFIED"_s,
462 u"IDENTITY"_s,
463 u"IDENTITYCOL"_s,
464 u"IDENTITY_INSERT"_s,
465 u"IF"_s,
466 u"IGNORE"_s,
467 u"ILIKE"_s,
468 u"IMMEDIATE"_s,
469 u"IN"_s,
470 u"INCLUSIVE"_s,
471 u"INCONSISTENT"_s,
472 u"INCREMENT"_s,
473 u"INDEX"_s,
474 u"INDICATOR"_s,
475 u"INFILE"_s,
476 u"INHERIT"_s,
477 u"INITIAL"_s,
478 u"INITIALIZE"_s,
479 u"INITIALLY"_s,
480 u"INITIATE"_s,
481 u"INNER"_s,
482 u"INOUT"_s,
483 u"INPUT"_s,
484 u"INS"_s,
485 u"INSENSITIVE"_s,
486 u"INSERT"_s,
487 u"INSTEAD"_s,
488 u"INT"_s,
489 u"INT1"_s,
490 u"INT2"_s,
491 u"INT3"_s,
492 u"INT4"_s,
493 u"INT8"_s,
494 u"INTEGER"_s,
495 u"INTEGERDATE"_s,
496 u"INTERSECT"_s,
497 u"INTERSECTION"_s,
498 u"INTERVAL"_s,
499 u"INTO"_s,
500 u"IO_AFTER_GTIDS"_s,
501 u"IO_BEFORE_GTIDS"_s,
502 u"IS"_s,
503 u"ISNULL"_s,
504 u"ISOBID"_s,
505 u"ISOLATION"_s,
506 u"ITERATE"_s,
507 u"JAR"_s,
508 u"JOIN"_s,
509 u"JOURNAL"_s,
510 u"JSON_ARRAY"_s,
511 u"JSON_ARRAYAGG"_s,
512 u"JSON_EXISTS"_s,
513 u"JSON_OBJECT"_s,
514 u"JSON_OBJECTAGG"_s,
515 u"JSON_QUERY"_s,
516 u"JSON_TABLE"_s,
517 u"JSON_TABLE_PRIMITIVE"_s,
518 u"JSON_VALUE"_s,
519 u"KEEP"_s,
520 u"KEY"_s,
521 u"KEYS"_s,
522 u"KILL"_s,
523 u"KURTOSIS"_s,
524 u"LABEL"_s,
525 u"LAG"_s,
526 u"LANGUAGE"_s,
527 u"LARGE"_s,
528 u"LAST"_s,
529 u"LAST_VALUE"_s,
530 u"LATERAL"_s,
531 u"LC_CTYPE"_s,
532 u"LE"_s,
533 u"LEAD"_s,
534 u"LEADING"_s,
535 u"LEAVE"_s,
536 u"LEFT"_s,
537 u"LESS"_s,
538 u"LEVEL"_s,
539 u"LIKE"_s,
540 u"LIKE_REGEX"_s,
541 u"LIMIT"_s,
542 u"LINEAR"_s,
543 u"LINENO"_s,
544 u"LINES"_s,
545 u"LISTAGG"_s,
546 u"LN"_s,
547 u"LOAD"_s,
548 u"LOADING"_s,
549 u"LOCAL"_s,
550 u"LOCALE"_s,
551 u"LOCALTIME"_s,
552 u"LOCALTIMESTAMP"_s,
553 u"LOCATOR"_s,
554 u"LOCATORS"_s,
555 u"LOCK"_s,
556 u"LOCKING"_s,
557 u"LOCKMAX"_s,
558 u"LOCKSIZE"_s,
559 u"LOG"_s,
560 u"LOG10"_s,
561 u"LOGGING"_s,
562 u"LOGON"_s,
563 u"LONG"_s,
564 u"LONGBLOB"_s,
565 u"LONGTEXT"_s,
566 u"LOOP"_s,
567 u"LOWER"_s,
568 u"LOW_PRIORITY"_s,
569 u"LT"_s,
570 u"MACRO"_s,
571 u"MAINTAINED"_s,
572 u"MAP"_s,
573 u"MASTER_BIND"_s,
574 u"MASTER_SSL_VERIFY_SERVER_CERT"_s,
575 u"MATCH"_s,
576 u"MATCHES"_s,
577 u"MATCH_NUMBER"_s,
578 u"MATCH_RECOGNIZE"_s,
579 u"MATERIALIZED"_s,
580 u"MAVG"_s,
581 u"MAX"_s,
582 u"MAXEXTENTS"_s,
583 u"MAXIMUM"_s,
584 u"MAXVALUE"_s,
585 u"MCHARACTERS"_s,
586 u"MDIFF"_s,
587 u"MEDIUMBLOB"_s,
588 u"MEDIUMINT"_s,
589 u"MEDIUMTEXT"_s,
590 u"MEMBER"_s,
591 u"MERGE"_s,
592 u"METHOD"_s,
593 u"MICROSECOND"_s,
594 u"MICROSECONDS"_s,
595 u"MIDDLEINT"_s,
596 u"MIN"_s,
597 u"MINDEX"_s,
598 u"MINIMUM"_s,
599 u"MINUS"_s,
600 u"MINUTE"_s,
601 u"MINUTE_MICROSECOND"_s,
602 u"MINUTES"_s,
603 u"MINUTE_SECOND"_s,
604 u"MLINREG"_s,
605 u"MLOAD"_s,
606 u"MLSLABEL"_s,
607 u"MOD"_s,
608 u"MODE"_s,
609 u"MODIFIES"_s,
610 u"MODIFY"_s,
611 u"MODULE"_s,
612 u"MONITOR"_s,
613 u"MONRESOURCE"_s,
614 u"MONSESSION"_s,
615 u"MONTH"_s,
616 u"MONTHS"_s,
617 u"MSUBSTR"_s,
618 u"MSUM"_s,
619 u"MULTISET"_s,
620 u"NAMED"_s,
621 u"NAMES"_s,
622 u"NATIONAL"_s,
623 u"NATURAL"_s,
624 u"NCHAR"_s,
625 u"NCLOB"_s,
626 u"NE"_s,
627 u"NESTED_TABLE_ID"_s,
628 u"NEW"_s,
629 u"NEW_TABLE"_s,
630 u"NEXT"_s,
631 u"NEXTVAL"_s,
632 u"NO"_s,
633 u"NOAUDIT"_s,
634 u"NOCHECK"_s,
635 u"NOCOMPRESS"_s,
636 u"NONCLUSTERED"_s,
637 u"NONE"_s,
638 u"NORMALIZE"_s,
639 u"NOT"_s,
640 u"NOTNULL"_s,
641 u"NOWAIT"_s,
642 u"NO_WRITE_TO_BINLOG"_s,
643 u"NTH_VALUE"_s,
644 u"NTILE"_s,
645 u"NULL"_s,
646 u"NULLIF"_s,
647 u"NULLIFZERO"_s,
648 u"NULLS"_s,
649 u"NUMBER"_s,
650 u"NUMERIC"_s,
651 u"NUMPARTS"_s,
652 u"OBID"_s,
653 u"OBJECT"_s,
654 u"OBJECTS"_s,
655 u"OCCURRENCES_REGEX"_s,
656 u"OCTET_LENGTH"_s,
657 u"OF"_s,
658 u"OFF"_s,
659 u"OFFLINE"_s,
660 u"OFFSET"_s,
661 u"OFFSETS"_s,
662 u"OLD"_s,
663 u"OLD_TABLE"_s,
664 u"OMIT"_s,
665 u"ON"_s,
666 u"ONE"_s,
667 u"ONLINE"_s,
668 u"ONLY"_s,
669 u"OPEN"_s,
670 u"OPENDATASOURCE"_s,
671 u"OPENQUERY"_s,
672 u"OPENROWSET"_s,
673 u"OPENXML"_s,
674 u"OPERATION"_s,
675 u"OPTIMIZATION"_s,
676 u"OPTIMIZE"_s,
677 u"OPTIMIZER_COSTS"_s,
678 u"OPTION"_s,
679 u"OPTIONALLY"_s,
680 u"OR"_s,
681 u"ORDER"_s,
682 u"ORDINALITY"_s,
683 u"ORGANIZATION"_s,
684 u"OUT"_s,
685 u"OUTER"_s,
686 u"OUTFILE"_s,
687 u"OUTPUT"_s,
688 u"OVER"_s,
689 u"OVERLAPS"_s,
690 u"OVERLAY"_s,
691 u"OVERRIDE"_s,
692 u"PACKAGE"_s,
693 u"PAD"_s,
694 u"PADDED"_s,
695 u"PARAMETER"_s,
696 u"PARAMETERS"_s,
697 u"PART"_s,
698 u"PARTIAL"_s,
699 u"PARTITION"_s,
700 u"PARTITIONED"_s,
701 u"PARTITIONING"_s,
702 u"PASSWORD"_s,
703 u"PATH"_s,
704 u"PATTERN"_s,
705 u"PCTFREE"_s,
706 u"PER"_s,
707 u"PERCENT"_s,
708 u"PERCENTILE_CONT"_s,
709 u"PERCENTILE_DISC"_s,
710 u"PERCENT_RANK"_s,
711 u"PERIOD"_s,
712 u"PERM"_s,
713 u"PERMANENT"_s,
714 u"PIECESIZE"_s,
715 u"PIVOT"_s,
716 u"PLACING"_s,
717 u"PLAN"_s,
718 u"PORTION"_s,
719 u"POSITION"_s,
720 u"POSITION_REGEX"_s,
721 u"POSTFIX"_s,
722 u"POWER"_s,
723 u"PRECEDES"_s,
724 u"PRECISION"_s,
725 u"PREFIX"_s,
726 u"PREORDER"_s,
727 u"PREPARE"_s,
728 u"PRESERVE"_s,
729 u"PREVVAL"_s,
730 u"PRIMARY"_s,
731 u"PRINT"_s,
732 u"PRIOR"_s,
733 u"PRIQTY"_s,
734 u"PRIVATE"_s,
735 u"PRIVILEGES"_s,
736 u"PROC"_s,
737 u"PROCEDURE"_s,
738 u"PROFILE"_s,
739 u"PROGRAM"_s,
740 u"PROPORTIONAL"_s,
741 u"PROTECTION"_s,
742 u"PSID"_s,
743 u"PTF"_s,
744 u"PUBLIC"_s,
745 u"PURGE"_s,
746 u"QUALIFIED"_s,
747 u"QUALIFY"_s,
748 u"QUANTILE"_s,
749 u"QUERY"_s,
750 u"QUERYNO"_s,
751 u"RADIANS"_s,
752 u"RAISERROR"_s,
753 u"RANDOM"_s,
754 u"RANGE"_s,
755 u"RANGE_N"_s,
756 u"RANK"_s,
757 u"RAW"_s,
758 u"READ"_s,
759 u"READS"_s,
760 u"READTEXT"_s,
761 u"READ_WRITE"_s,
762 u"REAL"_s,
763 u"RECONFIGURE"_s,
764 u"RECURSIVE"_s,
765 u"REF"_s,
766 u"REFERENCES"_s,
767 u"REFERENCING"_s,
768 u"REFRESH"_s,
769 u"REGEXP"_s,
770 u"REGR_AVGX"_s,
771 u"REGR_AVGY"_s,
772 u"REGR_COUNT"_s,
773 u"REGR_INTERCEPT"_s,
774 u"REGR_R2"_s,
775 u"REGR_SLOPE"_s,
776 u"REGR_SXX"_s,
777 u"REGR_SXY"_s,
778 u"REGR_SYY"_s,
779 u"RELATIVE"_s,
780 u"RELEASE"_s,
781 u"RENAME"_s,
782 u"REPEAT"_s,
783 u"REPLACE"_s,
784 u"REPLICATION"_s,
785 u"REPOVERRIDE"_s,
786 u"REQUEST"_s,
787 u"REQUIRE"_s,
788 u"RESIGNAL"_s,
789 u"RESOURCE"_s,
790 u"RESTART"_s,
791 u"RESTORE"_s,
792 u"RESTRICT"_s,
793 u"RESULT"_s,
794 u"RESULT_SET_LOCATOR"_s,
795 u"RESUME"_s,
796 u"RET"_s,
797 u"RETRIEVE"_s,
798 u"RETURN"_s,
799 u"RETURNING"_s,
800 u"RETURNS"_s,
801 u"REVALIDATE"_s,
802 u"REVERT"_s,
803 u"REVOKE"_s,
804 u"RIGHT"_s,
805 u"RIGHTS"_s,
806 u"RLIKE"_s,
807 u"ROLE"_s,
808 u"ROLLBACK"_s,
809 u"ROLLFORWARD"_s,
810 u"ROLLUP"_s,
811 u"ROUND_CEILING"_s,
812 u"ROUND_DOWN"_s,
813 u"ROUND_FLOOR"_s,
814 u"ROUND_HALF_DOWN"_s,
815 u"ROUND_HALF_EVEN"_s,
816 u"ROUND_HALF_UP"_s,
817 u"ROUND_UP"_s,
818 u"ROUTINE"_s,
819 u"ROW"_s,
820 u"ROWCOUNT"_s,
821 u"ROWGUIDCOL"_s,
822 u"ROWID"_s,
823 u"ROWNUM"_s,
824 u"ROW_NUMBER"_s,
825 u"ROWS"_s,
826 u"ROWSET"_s,
827 u"RULE"_s,
828 u"RUN"_s,
829 u"RUNNING"_s,
830 u"SAMPLE"_s,
831 u"SAMPLEID"_s,
832 u"SAVE"_s,
833 u"SAVEPOINT"_s,
834 u"SCHEMA"_s,
835 u"SCHEMAS"_s,
836 u"SCOPE"_s,
837 u"SCRATCHPAD"_s,
838 u"SCROLL"_s,
839 u"SEARCH"_s,
840 u"SECOND"_s,
841 u"SECOND_MICROSECOND"_s,
842 u"SECONDS"_s,
843 u"SECQTY"_s,
844 u"SECTION"_s,
845 u"SECURITY"_s,
846 u"SECURITYAUDIT"_s,
847 u"SEEK"_s,
848 u"SEL"_s,
849 u"SELECT"_s,
850 u"SEMANTICKEYPHRASETABLE"_s,
851 u"SEMANTICSIMILARITYDETAILSTABLE"_s,
852 u"SEMANTICSIMILARITYTABLE"_s,
853 u"SENSITIVE"_s,
854 u"SEPARATOR"_s,
855 u"SEQUENCE"_s,
856 u"SESSION"_s,
857 u"SESSION_USER"_s,
858 u"SET"_s,
859 u"SETRESRATE"_s,
860 u"SETS"_s,
861 u"SETSESSRATE"_s,
862 u"SETUSER"_s,
863 u"SHARE"_s,
864 u"SHOW"_s,
865 u"SHUTDOWN"_s,
866 u"SIGNAL"_s,
867 u"SIMILAR"_s,
868 u"SIMPLE"_s,
869 u"SIN"_s,
870 u"SINH"_s,
871 u"SIZE"_s,
872 u"SKEW"_s,
873 u"SKIP"_s,
874 u"SMALLINT"_s,
875 u"SOME"_s,
876 u"SOUNDEX"_s,
877 u"SOURCE"_s,
878 u"SPACE"_s,
879 u"SPATIAL"_s,
880 u"SPECIFIC"_s,
881 u"SPECIFICTYPE"_s,
882 u"SPOOL"_s,
883 u"SQL"_s,
884 u"SQL_BIG_RESULT"_s,
885 u"SQL_CALC_FOUND_ROWS"_s,
886 u"SQLEXCEPTION"_s,
887 u"SQL_SMALL_RESULT"_s,
888 u"SQLSTATE"_s,
889 u"SQLTEXT"_s,
890 u"SQLWARNING"_s,
891 u"SQRT"_s,
892 u"SS"_s,
893 u"SSL"_s,
894 u"STANDARD"_s,
895 u"START"_s,
896 u"STARTING"_s,
897 u"STARTUP"_s,
898 u"STATE"_s,
899 u"STATEMENT"_s,
900 u"STATIC"_s,
901 u"STATISTICS"_s,
902 u"STAY"_s,
903 u"STDDEV_POP"_s,
904 u"STDDEV_SAMP"_s,
905 u"STEPINFO"_s,
906 u"STOGROUP"_s,
907 u"STORED"_s,
908 u"STORES"_s,
909 u"STRAIGHT_JOIN"_s,
910 u"STRING_CS"_s,
911 u"STRUCTURE"_s,
912 u"STYLE"_s,
913 u"SUBMULTISET"_s,
914 u"SUBSCRIBER"_s,
915 u"SUBSET"_s,
916 u"SUBSTR"_s,
917 u"SUBSTRING"_s,
918 u"SUBSTRING_REGEX"_s,
919 u"SUCCEEDS"_s,
920 u"SUCCESSFUL"_s,
921 u"SUM"_s,
922 u"SUMMARY"_s,
923 u"SUSPEND"_s,
924 u"SYMMETRIC"_s,
925 u"SYNONYM"_s,
926 u"SYSDATE"_s,
927 u"SYSTEM"_s,
928 u"SYSTEM_TIME"_s,
929 u"SYSTEM_USER"_s,
930 u"SYSTIMESTAMP"_s,
931 u"TABLE"_s,
932 u"TABLESAMPLE"_s,
933 u"TABLESPACE"_s,
934 u"TAN"_s,
935 u"TANH"_s,
936 u"TBL_CS"_s,
937 u"TEMPORARY"_s,
938 u"TERMINATE"_s,
939 u"TERMINATED"_s,
940 u"TEXTSIZE"_s,
941 u"THAN"_s,
942 u"THEN"_s,
943 u"THRESHOLD"_s,
944 u"TIME"_s,
945 u"TIMESTAMP"_s,
946 u"TIMEZONE_HOUR"_s,
947 u"TIMEZONE_MINUTE"_s,
948 u"TINYBLOB"_s,
949 u"TINYINT"_s,
950 u"TINYTEXT"_s,
951 u"TITLE"_s,
952 u"TO"_s,
953 u"TOP"_s,
954 u"TRACE"_s,
955 u"TRAILING"_s,
956 u"TRAN"_s,
957 u"TRANSACTION"_s,
958 u"TRANSLATE"_s,
959 u"TRANSLATE_CHK"_s,
960 u"TRANSLATE_REGEX"_s,
961 u"TRANSLATION"_s,
962 u"TREAT"_s,
963 u"TRIGGER"_s,
964 u"TRIM"_s,
965 u"TRIM_ARRAY"_s,
966 u"TRUE"_s,
967 u"TRUNCATE"_s,
968 u"TRY_CONVERT"_s,
969 u"TSEQUAL"_s,
970 u"TYPE"_s,
971 u"UC"_s,
972 u"UESCAPE"_s,
973 u"UID"_s,
974 u"UNDEFINED"_s,
975 u"UNDER"_s,
976 u"UNDO"_s,
977 u"UNION"_s,
978 u"UNIQUE"_s,
979 u"UNKNOWN"_s,
980 u"UNLOCK"_s,
981 u"UNNEST"_s,
982 u"UNPIVOT"_s,
983 u"UNSIGNED"_s,
984 u"UNTIL"_s,
985 u"UPD"_s,
986 u"UPDATE"_s,
987 u"UPDATETEXT"_s,
988 u"UPPER"_s,
989 u"UPPERCASE"_s,
990 u"USAGE"_s,
991 u"USE"_s,
992 u"USER"_s,
993 u"USING"_s,
994 u"UTC_DATE"_s,
995 u"UTC_TIME"_s,
996 u"UTC_TIMESTAMP"_s,
997 u"VALIDATE"_s,
998 u"VALIDPROC"_s,
999 u"VALUE"_s,
1000 u"VALUE_OF"_s,
1001 u"VALUES"_s,
1002 u"VARBINARY"_s,
1003 u"VARBYTE"_s,
1004 u"VARCHAR"_s,
1005 u"VARCHAR2"_s,
1006 u"VARCHARACTER"_s,
1007 u"VARGRAPHIC"_s,
1008 u"VARIABLE"_s,
1009 u"VARIADIC"_s,
1010 u"VARIANT"_s,
1011 u"VAR_POP"_s,
1012 u"VAR_SAMP"_s,
1013 u"VARYING"_s,
1014 u"VCAT"_s,
1015 u"VERBOSE"_s,
1016 u"VERSIONING"_s,
1017 u"VIEW"_s,
1018 u"VIRTUAL"_s,
1019 u"VOLATILE"_s,
1020 u"VOLUMES"_s,
1021 u"WAIT"_s,
1022 u"WAITFOR"_s,
1023 u"WHEN"_s,
1024 u"WHENEVER"_s,
1025 u"WHERE"_s,
1026 u"WHILE"_s,
1027 u"WIDTH_BUCKET"_s,
1028 u"WINDOW"_s,
1029 u"WITH"_s,
1030 u"WITHIN"_s,
1031 u"WITHIN_GROUP"_s,
1032 u"WITHOUT"_s,
1033 u"WLM"_s,
1034 u"WORK"_s,
1035 u"WRITE"_s,
1036 u"WRITETEXT"_s,
1037 u"XMLCAST"_s,
1038 u"XMLEXISTS"_s,
1039 u"XMLNAMESPACES"_s,
1040 u"XOR"_s,
1041 u"YEAR"_s,
1042 u"YEAR_MONTH"_s,
1043 u"YEARS"_s,
1044 u"ZEROFILL"_s,
1045 u"ZEROIFNULL"_s,
1046 u"ZONE"_s,
1047 }
1048 }
1049 };
1050}
1051
1056
1058{
1059 return u"pk"_s;
1060}
1061
1063{
1064 return u"geom"_s;
1065}
1066
1068{
1069 return {};
1070}
1071
1073{
1074 return {};
1075}
1076
1078{
1079 return {};
1080}
1081
1086
1088{
1089 return {};
1090}
1091
1096
1098 const QString &name,
1099 const QgsFields &fields,
1100 Qgis::WkbType wkbType,
1102 bool overwrite,
1103 const QMap<QString, QVariant> *
1104 options ) const
1105{
1106 Q_UNUSED( schema );
1107 Q_UNUSED( name );
1108 Q_UNUSED( fields );
1109 Q_UNUSED( srs );
1110 Q_UNUSED( overwrite );
1111 Q_UNUSED( options );
1112 Q_UNUSED( wkbType );
1113 throw QgsProviderConnectionException( QObject::tr( "Operation 'createVectorTable' is not supported" ) );
1114}
1115
1116void QgsAbstractDatabaseProviderConnection::renameVectorTable( const QString &, const QString &, const QString & ) const
1117{
1118 checkCapability( Capability::RenameVectorTable );
1119}
1120
1121
1127
1128void QgsAbstractDatabaseProviderConnection::renameRasterTable( const QString &, const QString &, const QString & ) const
1129{
1130 checkCapability( Capability::RenameRasterTable );
1131}
1132
1133void QgsAbstractDatabaseProviderConnection::dropVectorTable( const QString &, const QString & ) const
1134{
1135 checkCapability( Capability::DropVectorTable );
1136}
1137
1138bool QgsAbstractDatabaseProviderConnection::tableExists( const QString &schema, const QString &name ) const
1139{
1140 checkCapability( Capability::TableExists );
1141 const QList<QgsAbstractDatabaseProviderConnection::TableProperty> constTables { tables( schema ) };
1142 for ( const auto &t : constTables )
1143 {
1144 if ( t.tableName() == name )
1145 {
1146 return true;
1147 }
1148 }
1149 return false;
1150}
1151
1152
1153QList<QgsLayerMetadataProviderResult> QgsAbstractDatabaseProviderConnection::searchLayerMetadata( const QgsMetadataSearchContext &searchContext, const QString &searchString, const QgsRectangle &geographicExtent, QgsFeedback *feedback ) const
1154{
1155 Q_UNUSED( feedback );
1156 Q_UNUSED( searchContext );
1157 Q_UNUSED( searchString );
1158 Q_UNUSED( geographicExtent );
1159 throw QgsNotSupportedException( QObject::tr( "Provider %1 has no %2 method" ).arg( providerKey(), u"searchLayerMetadata"_s ) );
1160}
1161
1162void QgsAbstractDatabaseProviderConnection::dropRasterTable( const QString &, const QString & ) const
1163{
1164 checkCapability( Capability::DropRasterTable );
1165}
1166
1168{
1169 checkCapability( Capability::CreateSchema );
1170}
1171
1172void QgsAbstractDatabaseProviderConnection::dropSchema( const QString &, bool ) const
1173{
1174 checkCapability( Capability::DropSchema );
1175}
1176
1177void QgsAbstractDatabaseProviderConnection::renameSchema( const QString &, const QString & ) const
1178{
1179 checkCapability( Capability::RenameSchema );
1180}
1181
1182QList<QList<QVariant>> QgsAbstractDatabaseProviderConnection::executeSql( const QString &sql, QgsFeedback *feedback ) const
1183{
1184 return execSql( sql, feedback ).rows();
1185}
1186
1187
1193
1194
1195void QgsAbstractDatabaseProviderConnection::vacuum( const QString &, const QString & ) const
1196{
1197 checkCapability( Capability::Vacuum );
1198}
1199
1204
1206{
1207 checkCapability( Capability::SqlLayers );
1208 return nullptr;
1209}
1210
1212{
1213 checkCapability( Capability::SqlLayers );
1214 return true;
1215}
1216
1217void QgsAbstractDatabaseProviderConnection::deleteSpatialIndex( const QString &, const QString &, const QString & ) const
1218{
1219 checkCapability( Capability::DeleteSpatialIndex );
1220}
1221
1222bool QgsAbstractDatabaseProviderConnection::spatialIndexExists( const QString &, const QString &, const QString & ) const
1223{
1224 checkCapability( Capability::SpatialIndexExists );
1225 return false;
1226}
1227
1228void QgsAbstractDatabaseProviderConnection::deleteField( const QString &fieldName, const QString &schema, const QString &tableName, bool ) const
1229{
1230 checkCapability( Capability::DeleteField );
1231
1232 QgsVectorLayer::LayerOptions options { false, false };
1233 options.skipCrsValidation = true;
1234 std::unique_ptr<QgsVectorLayer> vl { std::make_unique<QgsVectorLayer>( tableUri( schema, tableName ), u"temp_layer"_s, mProviderKey, options ) };
1235 if ( ! vl->isValid() )
1236 {
1237 throw QgsProviderConnectionException( QObject::tr( "Could not create a vector layer for table '%1' in schema '%2'" )
1238 .arg( tableName, schema ) );
1239 }
1240 if ( vl->fields().lookupField( fieldName ) == -1 )
1241 {
1242 throw QgsProviderConnectionException( QObject::tr( "Could not find field '%1' in table '%2' in schema '%3'" )
1243 .arg( fieldName, tableName, schema ) );
1244
1245 }
1246 if ( ! vl->dataProvider()->deleteAttributes( { vl->fields().lookupField( fieldName ) } ) )
1247 {
1248 throw QgsProviderConnectionException( QObject::tr( "Unknown error deleting field '%1' in table '%2' in schema '%3'" )
1249 .arg( fieldName, tableName, schema ) );
1250 }
1251}
1252
1253void QgsAbstractDatabaseProviderConnection::addField( const QgsField &field, const QString &schema, const QString &tableName ) const
1254{
1255 checkCapability( Capability::AddField );
1256
1257 QgsVectorLayer::LayerOptions options { false, false };
1258 options.skipCrsValidation = true;
1259 auto vl = std::make_unique<QgsVectorLayer>( tableUri( schema, tableName ), u"temp_layer"_s, mProviderKey, options ) ;
1260 if ( ! vl->isValid() )
1261 {
1262 throw QgsProviderConnectionException( QObject::tr( "Could not create a vector layer for table '%1' in schema '%2'" )
1263 .arg( tableName, schema ) );
1264 }
1265 if ( vl->fields().lookupField( field.name() ) != -1 )
1266 {
1267 throw QgsProviderConnectionException( QObject::tr( "Field '%1' in table '%2' in schema '%3' already exists" )
1268 .arg( field.name(), tableName, schema ) );
1269
1270 }
1271 if ( ! vl->dataProvider()->addAttributes( { field } ) )
1272 {
1273 throw QgsProviderConnectionException( QObject::tr( "Unknown error adding field '%1' in table '%2' in schema '%3'" )
1274 .arg( field.name(), tableName, schema ) );
1275 }
1276}
1277
1278void QgsAbstractDatabaseProviderConnection::renameField( const QString &schema, const QString &tableName, const QString &name, const QString &newName ) const
1279{
1280 checkCapability( Capability::RenameField );
1281
1282 QgsVectorLayer::LayerOptions options { false, false };
1283 options.skipCrsValidation = true;
1284 auto vl = std::make_unique<QgsVectorLayer>( tableUri( schema, tableName ), u"temp_layer"_s, mProviderKey, options ) ;
1285 if ( ! vl->isValid() )
1286 {
1287 throw QgsProviderConnectionException( QObject::tr( "Could not create a vector layer for table '%1' in schema '%2'" )
1288 .arg( tableName, schema ) );
1289 }
1290 int existingIndex = vl->fields().lookupField( name );
1291 if ( existingIndex == -1 )
1292 {
1293 throw QgsProviderConnectionException( QObject::tr( "Field '%1' in table '%2' in does not exist" )
1294 .arg( name, tableName ) );
1295
1296 }
1297 if ( vl->fields().lookupField( newName ) != -1 )
1298 {
1299 throw QgsProviderConnectionException( QObject::tr( "A field with name '%1' already exists in table '%2'" )
1300 .arg( newName, tableName ) );
1301
1302 }
1303 if ( ! vl->dataProvider()->renameAttributes( {{existingIndex, newName}} ) )
1304 {
1305 throw QgsProviderConnectionException( QObject::tr( "Unknown error renaming field '%1' in table '%2' to '%3'" )
1306 .arg( name, tableName, newName ) );
1307 }
1308}
1309
1310QList<QgsAbstractDatabaseProviderConnection::TableProperty> QgsAbstractDatabaseProviderConnection::tables( const QString &, const QgsAbstractDatabaseProviderConnection::TableFlags &, QgsFeedback * ) const
1311{
1312 checkCapability( Capability::Tables );
1313 return QList<QgsAbstractDatabaseProviderConnection::TableProperty>();
1314}
1315
1316
1318{
1319 checkCapability( Capability::Tables );
1320 const QList<QgsAbstractDatabaseProviderConnection::TableProperty> constTables { tables( schema, TableFlags(), feedback ) };
1321 for ( const auto &t : constTables )
1322 {
1323 if ( t.tableName() == name )
1324 {
1325 return t;
1326 }
1327 }
1328 throw QgsProviderConnectionException( QObject::tr( "Table '%1' was not found in schema '%2'" )
1329 .arg( name, schema ) );
1330}
1331
1332QList<QgsAbstractDatabaseProviderConnection::TableProperty> QgsAbstractDatabaseProviderConnection::tablesInt( const QString &schema, const int flags ) const
1333{
1334 return tables( schema, static_cast<QgsAbstractDatabaseProviderConnection::TableFlags>( flags ) );
1335}
1336
1337
1339{
1340 checkCapability( Capability::Schemas );
1341 return QStringList();
1342}
1343
1345{
1346 return mTableName;
1347}
1348
1350{
1351 mTableName = name;
1352}
1353
1355{
1356 // Do not add the type if it's already present
1358 for ( const auto &t : std::as_const( mGeometryColumnTypes ) )
1359 {
1360 if ( t == toAdd )
1361 {
1362 return;
1363 }
1364 }
1365 mGeometryColumnTypes.push_back( toAdd );
1366}
1367
1368QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType> QgsAbstractDatabaseProviderConnection::TableProperty::geometryColumnTypes() const
1369{
1370 return mGeometryColumnTypes;
1371}
1372
1373
1374QgsFields QgsAbstractDatabaseProviderConnection::fields( const QString &schema, const QString &tableName, QgsFeedback * ) const
1375{
1376 QgsVectorLayer::LayerOptions options { false, true };
1377 options.skipCrsValidation = true;
1378 QgsVectorLayer vl { tableUri( schema, tableName ), u"temp_layer"_s, mProviderKey, options };
1379 if ( vl.isValid() )
1380 {
1381 // Note: this implementation works for providers that do not hide any "special" field (geometry or PKs)
1382 return vl.fields();
1383 }
1384 else
1385 {
1386 throw QgsProviderConnectionException( QObject::tr( "Error retrieving fields information for uri: %1" ).arg( vl.publicSource() ) );
1387 }
1388}
1389
1391{
1392 checkCapability( Capability::ListFieldDomains );
1393 return QStringList();
1394}
1395
1397{
1398 checkCapability( Capability::RetrieveFieldDomain );
1399 return nullptr;
1400}
1401
1402void QgsAbstractDatabaseProviderConnection::setFieldDomainName( const QString &, const QString &, const QString &, const QString & ) const
1403{
1404 checkCapability( Capability::SetFieldDomain );
1405}
1406
1408{
1409 checkCapability( Capability::AddFieldDomain );
1410}
1411
1416
1417void QgsAbstractDatabaseProviderConnection::deleteFieldDomain( const QString &, const QString & ) const
1418{
1420}
1421
1422void QgsAbstractDatabaseProviderConnection::setFieldAlias( const QString &, const QString &, const QString &, const QString & ) const
1423{
1425}
1426
1427void QgsAbstractDatabaseProviderConnection::setTableComment( const QString &, const QString &, const QString & ) const
1428{
1430}
1431
1432void QgsAbstractDatabaseProviderConnection::setFieldComment( const QString &, const QString &, const QString &, const QString & ) const
1433{
1435}
1436
1437QList< QgsWeakRelation > QgsAbstractDatabaseProviderConnection::relationships( const QString &, const QString & ) const
1438{
1439 checkCapability( Capability::RetrieveRelationships );
1440 return {};
1441}
1442
1447
1452
1457
1459{
1460 QString n = mTableName;
1461 if ( mGeometryColumnCount > 1 ) n += '.' + mGeometryColumn;
1462 return n;
1463}
1464
1465void QgsAbstractDatabaseProviderConnection::moveTableToSchema( const QString &schema, const QString &tableName, const QString &targetSchema ) const
1466{
1467 Q_UNUSED( schema );
1468 Q_UNUSED( tableName );
1469 Q_UNUSED( targetSchema );
1470 checkCapability( Capability::MoveTableToSchema );
1471}
1472
1474{
1475 TableProperty property;
1476
1477 Q_ASSERT( index >= 0 && index < mGeometryColumnTypes.size() );
1478
1479 property.mGeometryColumnTypes << mGeometryColumnTypes[ index ];
1480 property.mSchema = mSchema;
1481 property.mTableName = mTableName;
1482 property.mGeometryColumn = mGeometryColumn;
1483 property.mPkColumns = mPkColumns;
1484 property.mGeometryColumnCount = mGeometryColumnCount;
1485 property.mFlags = mFlags;
1486 property.mComment = mComment;
1487 property.mInfo = mInfo;
1488 return property;
1489}
1490
1495
1497{
1498 int res = 0;
1499 for ( const TableProperty::GeometryColumnType &ct : std::as_const( mGeometryColumnTypes ) )
1500 {
1501 res = std::max( res, QgsWkbTypes::coordDimensions( ct.wkbType ) );
1502 }
1503 return res;
1504}
1505
1507{
1508 return mSchema == other.mSchema &&
1509 mTableName == other.mTableName &&
1510 mGeometryColumn == other.mGeometryColumn &&
1511 mGeometryColumnCount == other.mGeometryColumnCount &&
1512 mPkColumns == other.mPkColumns &&
1513 mFlags == other.mFlags &&
1514 mComment == other.mComment &&
1515 mInfo == other.mInfo;
1516}
1517
1518
1519void QgsAbstractDatabaseProviderConnection::TableProperty::setGeometryColumnTypes( const QList<QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType> &columnTypes )
1520{
1521 mGeometryColumnTypes = columnTypes;
1522}
1523
1524
1526{
1527 return mGeometryColumnCount;
1528}
1529
1534
1536{
1537 return mInfo;
1538}
1539
1541{
1542 mInfo = info;
1543}
1544
1546{
1547 return mComment;
1548}
1549
1554
1559
1564
1565QList<QgsCoordinateReferenceSystem> QgsAbstractDatabaseProviderConnection::TableProperty::crsList() const
1566{
1567 QList<QgsCoordinateReferenceSystem> crss;
1568 for ( const auto &t : std::as_const( mGeometryColumnTypes ) )
1569 {
1570 crss.push_back( t.crs );
1571 }
1572 return crss;
1573}
1574
1576{
1577 return mPkColumns;
1578}
1579
1581{
1582 mPkColumns = pkColumns;
1583}
1584
1586{
1587 return mGeometryColumn;
1588}
1589
1594
1596{
1597 return mSchema;
1598}
1599
1601{
1602 mSchema = schema;
1603}
1604
1606
1608{
1609 return mColumns;
1610}
1611
1613{
1614
1615 QList<QList<QVariant> > rows;
1616
1617 while ( mResultIterator &&
1618 mResultIterator->hasNextRow() &&
1619 ( ! feedback || ! feedback->isCanceled() ) )
1620 {
1621 const QVariantList row( mResultIterator->nextRow() );
1622 if ( row.isEmpty() )
1623 {
1624 break;
1625 }
1626 else
1627 {
1628 rows.push_back( row );
1629 }
1630 }
1631 return rows;
1632}
1633
1635{
1636 if ( ! mResultIterator )
1637 {
1638 return QList<QVariant>();
1639 }
1640 return mResultIterator->nextRow();
1641}
1642
1643
1645{
1646 if ( ! mResultIterator )
1647 {
1648 return 0;
1649 }
1650 return mResultIterator->fetchedRowCount();
1651}
1652
1654{
1655 if ( ! mResultIterator )
1656 {
1657 return static_cast<long long>( Qgis::FeatureCountState::UnknownCount );
1658 }
1659 return mResultIterator->rowCount();
1660}
1661
1662bool QgsAbstractDatabaseProviderConnection::splitSimpleQuery( const QString &sql, QStringList &columns, QStringList &tables, QString &where )
1663{
1664 const QgsSQLStatement statement { sql };
1665 if ( statement.hasParserError() )
1666 {
1667 return false;
1668 }
1669
1670 const QgsSQLStatement::NodeSelect *nodeSelect = dynamic_cast<const QgsSQLStatement::NodeSelect *>( statement.rootNode() );
1671
1672 if ( !nodeSelect || !nodeSelect->joins().empty() || !nodeSelect->orderBy().empty() )
1673 {
1674 return false;
1675 }
1676
1677 const QList<QgsSQLStatement::NodeTableDef *> tablesList { nodeSelect->tables() };
1678
1679 if ( tablesList.empty() )
1680 {
1681 return false;
1682 }
1683
1684 for ( const QgsSQLStatement::NodeTableDef *tableDef : tablesList )
1685 {
1686 tables.append( tableDef->name() );
1687 }
1688
1689 const QList<QgsSQLStatement::NodeSelectedColumn *> columnsList { nodeSelect->columns() };
1690
1691 if ( columnsList.empty() )
1692 {
1693 return false;
1694 }
1695
1696 for ( const QgsSQLStatement::NodeSelectedColumn *colDef : columnsList )
1697 {
1698 columns.append( colDef->dump() );
1699 }
1700
1701 if ( nodeSelect->where() )
1702 {
1703 where = nodeSelect->where()->dump();
1704 }
1705
1706 return true;
1707}
1708
1709
1711{
1712 if ( ! mResultIterator )
1713 {
1714 return false;
1715 }
1716 return mResultIterator->hasNextRow();
1717}
1718
1719void QgsAbstractDatabaseProviderConnection::QueryResult::appendColumn( const QString &columnName )
1720{
1721 mColumns.push_back( columnName );
1722}
1723
1724QgsAbstractDatabaseProviderConnection::QueryResult::QueryResult( std::shared_ptr<QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator> iterator )
1725 : mResultIterator( std::move( iterator ) )
1726{}
1727
1728double QgsAbstractDatabaseProviderConnection::QueryResult::queryExecutionTime() const
1729{
1730 return mQueryExecutionTime;
1731}
1732
1733void QgsAbstractDatabaseProviderConnection::QueryResult::setQueryExecutionTime( double queryExecutionTime )
1734{
1735 mQueryExecutionTime = queryExecutionTime;
1736}
1737
1738
1739QVariantList QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::nextRow()
1740{
1741 QMutexLocker lock( &mMutex );
1742 const QVariantList row = nextRowPrivate();
1743 if ( ! row.isEmpty() )
1744 {
1745 mFetchedRowCount++;
1746 }
1747 return row;
1748}
1749
1750bool QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::hasNextRow() const
1751{
1752 QMutexLocker lock( &mMutex );
1753 return hasNextRowPrivate();
1754}
1755
1756long long QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::fetchedRowCount()
1757{
1758 QMutexLocker lock( &mMutex );
1759 return mFetchedRowCount;
1760}
1761
1762long long QgsAbstractDatabaseProviderConnection::QueryResult::QueryResultIterator::rowCount()
1763{
1764 QMutexLocker lock( &mMutex );
1765 return rowCountPrivate();
1766}
1767
1769
DatabaseProviderConnectionCapability2
The Capability enum represents the extended operations supported by the connection.
Definition qgis.h:5656
@ SetTableComment
Can set comments for tables via setTableComment().
Definition qgis.h:5659
@ DeleteFieldDomain
Can delete existing field domain.
Definition qgis.h:5661
@ SetFieldComment
Can set comments for fields via setFieldComment().
Definition qgis.h:5657
@ EditFieldDomain
Can edit existing field domain.
Definition qgis.h:5660
@ SetFieldAlias
Can set aliases for fields via setFieldAlias().
Definition qgis.h:5658
@ Keyword
SQL keyword.
Definition qgis.h:1128
@ Constant
SQL constant.
Definition qgis.h:1129
QFlags< RelationshipCapability > RelationshipCapabilities
Relationship capabilities.
Definition qgis.h:4502
QFlags< DatabaseProviderConnectionCapability2 > DatabaseProviderConnectionCapabilities2
Definition qgis.h:5664
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
QFlags< SqlLayerDefinitionCapability > SqlLayerDefinitionCapabilities
SQL layer definition capabilities.
Definition qgis.h:1118
virtual QString defaultGeometryColumnName() const
Returns the default name to use for a geometry column for the connection.
virtual void setFieldComment(const QString &fieldName, const QString &schema, const QString &tableName, const QString &comment) const
Sets the comment for the existing field with the specified name.
virtual QList< QgsWeakRelation > relationships(const QString &schema=QString(), const QString &tableName=QString()) const
Returns a list of relationships detected in the database.
virtual void createVectorTable(const QString &schema, const QString &name, const QgsFields &fields, Qgis::WkbType wkbType, const QgsCoordinateReferenceSystem &srs, bool overwrite, const QMap< QString, QVariant > *options) const
Creates an empty table with name in the given schema (schema is ignored if not supported by the backe...
virtual QgsVectorLayer * createSqlVectorLayer(const SqlVectorLayerOptions &options) const
Creates and returns a (possibly invalid) vector layer based on a SQL statement and options.
virtual bool tableExists(const QString &schema, const QString &name) const
Checks whether a table name exists in the given schema.
QList< QgsAbstractDatabaseProviderConnection::TableProperty > tablesInt(const QString &schema=QString(), const int flags=0) const
Returns information on the tables in the given schema.
virtual void updateRelationship(const QgsWeakRelation &relationship) const
Updates an existing relationship in the database.
virtual void renameField(const QString &schema, const QString &tableName, const QString &name, const QString &newName) const
Renames an existing field.
virtual void deleteFieldDomain(const QString &name, const QString &schema) const
Deletes the field domain with the specified name from the provider.
virtual void dropSchema(const QString &name, bool force=false) const
Drops an entire schema with the specified name.
Qgis::SqlLayerDefinitionCapabilities mSqlLayerDefinitionCapabilities
virtual void addField(const QgsField &field, const QString &schema, const QString &tableName) const
Adds a field.
virtual QList< QgsAbstractDatabaseProviderConnection::TableProperty > tables(const QString &schema=QString(), const QgsAbstractDatabaseProviderConnection::TableFlags &flags=QgsAbstractDatabaseProviderConnection::TableFlags(), QgsFeedback *feedback=nullptr) const
Returns information on the tables in the given schema.
Qgis::DatabaseProviderConnectionCapabilities2 mCapabilities2
virtual void vacuum(const QString &schema, const QString &name) const
Vacuum the database table with given schema and name (schema is ignored if not supported by the backe...
virtual QList< Qgis::FieldDomainType > supportedFieldDomainTypes() const
Returns a list of field domain types which are supported by the provider.
virtual void renameVectorTable(const QString &schema, const QString &name, const QString &newName) const
Renames a vector or aspatial table with given schema (schema is ignored if not supported by the backe...
virtual void createSchema(const QString &name) const
Creates a new schema with the specified name.
virtual void deleteSpatialIndex(const QString &schema, const QString &name, const QString &geometryColumn) const
Deletes the existing spatial index for the database table with given schema, name and geometryColumn ...
virtual void dropRasterTable(const QString &schema, const QString &name) const
Drops a raster table with given schema (schema is ignored if not supported by the backend) and name.
Qgis::DatabaseProviderConnectionCapabilities2 capabilities2() const
Returns extended connection capabilities.
virtual QueryResult execSql(const QString &sql, QgsFeedback *feedback=nullptr) const
Executes raw sql and returns the (possibly empty) query results, optionally feedback can be provided.
virtual QgsProviderSqlQueryBuilder * queryBuilder() const
Returns a SQL query builder for the connection, which provides an interface for provider-specific cre...
virtual void setFieldDomainName(const QString &fieldName, const QString &schema, const QString &tableName, const QString &domainName) const
Sets the field domain name for the existing field with the specified name.
virtual void deleteField(const QString &fieldName, const QString &schema, const QString &tableName, bool force=false) const
Deletes the field with the specified name.
virtual QString tableUri(const QString &schema, const QString &name) const
Returns the URI string for the given table and schema.
QFlags< GeometryColumnCapability > GeometryColumnCapabilities
virtual void deleteRelationship(const QgsWeakRelation &relationship) const
Deletes an existing relationship in the database.
Capability
The Capability enum represents the operations supported by the connection.
@ RetrieveFieldDomain
Can retrieve field domain details from provider via fieldDomain().
@ CreateSpatialIndex
The connection can create spatial indices.
@ AddRelationship
Can add new relationships to the database via addRelationship().
@ SqlLayers
Can create vector layers from SQL SELECT queries.
@ DropVectorTable
Can DROP a vector (or aspatial) table/layer.
@ DeleteSpatialIndex
The connection can delete spatial indices for tables.
@ RetrieveRelationships
Can retrieve relationships from the database.
@ SetFieldDomain
Can set the domain for an existing field via setFieldDomainName().
@ AddFieldDomain
Can add new field domains to the database via addFieldDomain().
@ DeleteRelationship
Can delete existing relationships from the database via deleteRelationship().
@ RenameVectorTable
Can RENAME a vector (or aspatial) table/layer.
@ RenameField
Can rename existing fields via renameField().
@ MoveTableToSchema
Can move table to another schema via moveTableToAnotherSchema().
@ ExecuteSql
Can execute raw SQL queries (without returning results).
@ UpdateRelationship
Can update existing relationships in the database via updateRelationship().
@ SpatialIndexExists
The connection can determine if a spatial index exists.
@ ListFieldDomains
Can return a list of field domain names via fieldDomainNames().
@ Schemas
Can list schemas (if not set, the connection does not support schemas).
virtual void createSpatialIndex(const QString &schema, const QString &name, const QgsAbstractDatabaseProviderConnection::SpatialIndexOptions &options=QgsAbstractDatabaseProviderConnection::SpatialIndexOptions()) const
Creates a spatial index for the database table with given schema and name (schema is ignored if not s...
virtual QStringList relatedTableTypes() const
Returns a list of the related table types supported by the database format.
static bool splitSimpleQuery(const QString &sql, QStringList &columns, QStringList &tables, QString &where)
Splits a simple query in the form "SELECT column(s) FROM table(s) [WHERE ...]" into its components.
virtual GeometryColumnCapabilities geometryColumnCapabilities()
Returns connection geometry column capabilities (Z, M, SinglePart, Curves).
virtual Qgis::SqlLayerDefinitionCapabilities sqlLayerDefinitionCapabilities()
Returns SQL layer definition capabilities (Filters, GeometryColumn, PrimaryKeys).
virtual void renameRasterTable(const QString &schema, const QString &name, const QString &newName) const
Renames a raster table with given schema (schema is ignored if not supported by the backend) and name...
virtual void dropVectorTable(const QString &schema, const QString &name) const
Drops a vector (or aspatial) table with given schema (schema is ignored if not supported by the backe...
virtual QStringList fieldDomainNames() const
Returns a list of field domain names present on the provider.
virtual void setFieldAlias(const QString &fieldName, const QString &schema, const QString &tableName, const QString &alias) const
Sets the alias for the existing field with the specified name.
virtual void renameSchema(const QString &name, const QString &newName) const
Renames a schema with the specified name.
virtual void addFieldDomain(const QgsFieldDomain &domain, const QString &schema) const
Adds a new field domain to the database.
virtual QList< QList< QVariant > > executeSql(const QString &sql, QgsFeedback *feedback=nullptr) const
Executes raw sql and returns the (possibly empty) list of results in a multi-dimensional array,...
virtual bool spatialIndexExists(const QString &schema, const QString &name, const QString &geometryColumn) const
Determines whether a spatial index exists for the database table with given schema,...
virtual QgsAbstractDatabaseProviderConnection::TableProperty table(const QString &schema, const QString &table, QgsFeedback *feedback=nullptr) const
Returns information on a table in the given schema.
virtual QMultiMap< Qgis::SqlKeywordCategory, QStringList > sqlDictionary()
Returns a dictionary of SQL keywords supported by the provider.
virtual Qgis::RelationshipCapabilities supportedRelationshipCapabilities() const
Returns the relationship capabilities supported by the provider.
virtual SqlVectorLayerOptions sqlOptions(const QString &layerSource)
Returns the SQL layer options from a layerSource.
virtual QSet< QString > illegalFieldNames() const
Returns a list of field names which are considered illegal by the connection and should not be used w...
virtual QStringList schemas() const
Returns information about the existing schemas.
virtual QList< Qgis::RelationshipCardinality > supportedRelationshipCardinalities() const
Returns a list of relationship cardinalities which are supported by the provider.
virtual QString createVectorLayerExporterDestinationUri(const QgsAbstractDatabaseProviderConnection::VectorLayerExporterOptions &options, QVariantMap &providerOptions) const
Creates a URI for use with QgsVectorLayerExporter corresponding to given destination table options fo...
virtual void moveTableToSchema(const QString &sourceSchema, const QString &tableName, const QString &targetSchema) const
Move table to a different schema.
virtual QList< Qgis::RelationshipStrength > supportedRelationshipStrengths() const
Returns a list of relationship strengths which are supported by the provider.
virtual QList< QgsLayerMetadataProviderResult > searchLayerMetadata(const QgsMetadataSearchContext &searchContext, const QString &searchString=QString(), const QgsRectangle &geographicExtent=QgsRectangle(), QgsFeedback *feedback=nullptr) const
Search the stored layer metadata in the connection, optionally limiting the search to the metadata id...
virtual void addRelationship(const QgsWeakRelation &relationship) const
Adds a new field relationship to the database.
virtual void updateFieldDomain(QgsFieldDomain *domain, const QString &schema) const
Update an existing field domain in the database, the domain is identified by name.
virtual QgsFieldDomain * fieldDomain(const QString &name) const
Returns the field domain with the specified name from the provider.
QgsAbstractDatabaseProviderConnection(const QString &name)
Creates a new connection with name by reading its configuration from the settings.
virtual void setTableComment(const QString &schema, const QString &tableName, const QString &comment) const
Sets the comment for the existing table with the specified name.
virtual QString defaultPrimaryKeyColumnName() const
Returns the default name to use for a primary key column for the connection.
virtual bool validateSqlVectorLayer(const SqlVectorLayerOptions &options, QString &message) const
Validates the SQL query options to determine if it is possible to create a vector layer based on a SQ...
Capabilities capabilities() const
Returns connection capabilities.
virtual QgsFields fields(const QString &schema, const QString &table, QgsFeedback *feedback=nullptr) const
Returns the fields of a table and schema.
QVariantMap configuration() const
Returns the connection configuration parameters.
QgsAbstractProviderConnection(const QString &name)
Creates a new connection with name by reading its configuration from the settings.
QString uri() const
Returns the connection data source URI string representation.
Represents a coordinate reference system (CRS).
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:55
Base class for field domains.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
QString name
Definition qgsfield.h:65
Container of fields for a vector layer.
Definition qgsfields.h:46
QString publicSource(bool hidePassword=false) const
Gets a version of the internal layer definition that has sensitive bits removed (for example,...
Custom exception class which is raised when an operation is not supported.
Custom exception class for provider connection related exceptions.
Provides an interface for provider-specific creation of SQL queries.
A rectangle specified with double values.
QList< QgsSQLStatement::NodeColumnSorted * > orderBy() const
Returns the list of order by columns.
QList< QgsSQLStatement::NodeSelectedColumn * > columns() const
Returns the list of columns.
QList< QgsSQLStatement::NodeJoin * > joins() const
Returns the list of joins.
QgsSQLStatement::Node * where() const
Returns the where clause.
QList< QgsSQLStatement::NodeTableDef * > tables() const
Returns the list of tables.
virtual QString dump() const =0
Abstract virtual dump method.
bool hasParserError() const
Returns true if an error occurred when parsing the input statement.
const QgsSQLStatement::Node * rootNode() const
Returns the root node of the statement.
Represents a vector layer which manages a vector based dataset.
Represent a QgsRelation with possibly unresolved layers or unmatched fields.
static Q_INVOKABLE int coordDimensions(Qgis::WkbType type)
Returns the coordinate dimension of the geometry type as an integer.
@ UnknownCount
Provider returned an unknown feature count.
Definition qgis.h:566
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
Definition qgis.h:7091
The QueryResult class represents the result of a query executed by execSql().
QList< QList< QVariant > > rows(QgsFeedback *feedback=nullptr)
Returns the result rows by calling the iterator internally and fetching all the rows,...
long long fetchedRowCount() const
Returns the number of fetched rows.
bool hasNextRow() const
Returns true if there are more rows to fetch.
QList< QVariant > nextRow() const
Returns the next result row or an empty row if there are no rows left.
long long rowCount() const
Returns the number of rows returned by a SELECT query or Qgis::FeatureCountState::UnknownCount if unk...
QStringList columns() const
Returns the column names.
The SpatialIndexOptions contains extra options relating to spatial index creation.
The SqlVectorLayerOptions stores all information required to create a SQL (query) layer.
The GeometryColumnType struct represents the combination of geometry type and CRS for the table geome...
The TableProperty class represents a database table or view.
void setTableName(const QString &name)
Sets the table name to name.
bool operator==(const QgsAbstractDatabaseProviderConnection::TableProperty &other) const
void setPrimaryKeyColumns(const QStringList &primaryKeyColumns)
Sets the primary key column names to primaryKeyColumns.
QString defaultName() const
Returns the default name for the table entry.
QList< QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType > geometryColumnTypes() const
Returns the list of geometry column types and CRSs.
void setGeometryColumn(const QString &geometryColumn)
Sets the geometry column name to geometryColumn.
TableProperty at(int index) const
Returns the table property corresponding to the geometry type at the given index.
int maxCoordinateDimensions() const
Returns the maximum coordinate dimensions of the geometries of a vector table.
int geometryColumnCount() const
Returns the number of geometry columns in the original table this entry refers to.
QList< QgsCoordinateReferenceSystem > crsList() const
Returns the list of CRSs supported by the geometry column.
QVariantMap info() const
Returns additional information about the table.
void setInfo(const QVariantMap &info)
Sets additional information about the table to info.
QStringList primaryKeyColumns() const
Returns the list of primary key column names.
void setGeometryColumnTypes(const QList< QgsAbstractDatabaseProviderConnection::TableProperty::GeometryColumnType > &geometryColumnTypes)
Sets the geometry column types to geometryColumnTypes.
QString schema() const
Returns the schema or an empty string for backends that do not support a schema.
void setGeometryColumnCount(int geometryColumnCount)
Sets the geometryColumnCount.
void addGeometryColumnType(Qgis::WkbType type, const QgsCoordinateReferenceSystem &crs)
Appends the geometry column type with the given srid to the geometry column types list.
Stores all information required to create a QgsVectorLayerExporter for the backend.
Setting options for loading vector layers.
bool skipCrsValidation
Controls whether the layer is allowed to have an invalid/unknown CRS.