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