Changeset View
Changeset View
Standalone View
Standalone View
src/KDbQuerySchema.h
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Line(s) | 45 | public: | |||
---|---|---|---|---|---|
59 | We consider that query schema based on @a table is not (a least yet) stored | 59 | We consider that query schema based on @a table is not (a least yet) stored | ||
60 | in a system table, so query connection is set to @c nullptr | 60 | in a system table, so query connection is set to @c nullptr | ||
61 | (even if @a tableSchema's connection is not @c nullptr). | 61 | (even if @a tableSchema's connection is not @c nullptr). | ||
62 | Id of the created query is set to 0. */ | 62 | Id of the created query is set to 0. */ | ||
63 | explicit KDbQuerySchema(KDbTableSchema *tableSchema); | 63 | explicit KDbQuerySchema(KDbTableSchema *tableSchema); | ||
64 | 64 | | |||
65 | /*! Copy constructor. Creates deep copy of @a querySchema. | 65 | /*! Copy constructor. Creates deep copy of @a querySchema. | ||
66 | KDbQueryAsterisk objects are deeply copied while only pointers to KDbField objects are copied. */ | 66 | KDbQueryAsterisk objects are deeply copied while only pointers to KDbField objects are copied. */ | ||
67 | KDbQuerySchema(const KDbQuerySchema& querySchema); | 67 | KDbQuerySchema(const KDbQuerySchema& querySchema, KDbConnection *conn); | ||
68 | 68 | | |||
69 | ~KDbQuerySchema() override; | 69 | ~KDbQuerySchema() override; | ||
70 | 70 | | |||
71 | /*! Inserts @a field to the columns list at @a position. | 71 | /*! Inserts @a field to the columns list at @a position. | ||
72 | Inserted field will not be owned by this KDbQuerySchema object, | 72 | Inserted field will not be owned by this KDbQuerySchema object, | ||
73 | but by the corresponding KDbTableSchema. | 73 | but by the corresponding KDbTableSchema. | ||
74 | 74 | | |||
75 | KDbQueryAsterisk can be also passed as @a field. See the KDbQueryAsterisk class | 75 | KDbQueryAsterisk can be also passed as @a field. See the KDbQueryAsterisk class | ||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Line(s) | |||||
186 | 186 | | |||
187 | /*! Removes all columns and their aliases from the columns list, | 187 | /*! Removes all columns and their aliases from the columns list, | ||
188 | removes all tables and their aliases from the tables list within this query. | 188 | removes all tables and their aliases from the tables list within this query. | ||
189 | Sets master table information to @c nullptr. | 189 | Sets master table information to @c nullptr. | ||
190 | Does not destroy any objects though. Clears name and all other properties. | 190 | Does not destroy any objects though. Clears name and all other properties. | ||
191 | @see KDbFieldList::clear() */ | 191 | @see KDbFieldList::clear() */ | ||
192 | void clear() override; | 192 | void clear() override; | ||
193 | 193 | | |||
194 | /*! If query was created using a connection, | | |||
195 | returns this connection object, otherwise @c nullptr. */ | | |||
196 | KDbConnection* connection() const; | | |||
197 | | ||||
198 | /*! @return table that is master to this query. | 194 | /*! @return table that is master to this query. | ||
199 | All potentially-editable columns within this query belong just to this table. | 195 | All potentially-editable columns within this query belong just to this table. | ||
200 | This method also can return @c nullptr if there are no tables at all, | 196 | This method also can return @c nullptr if there are no tables at all, | ||
201 | or if previously assigned master table schema has been removed | 197 | or if previously assigned master table schema has been removed | ||
202 | with removeTable(). | 198 | with removeTable(). | ||
203 | Every query that has at least one table defined, should have | 199 | Every query that has at least one table defined, should have | ||
204 | assigned a master table. | 200 | assigned a master table. | ||
205 | If no master table is assigned explicitly, but only one table used in this query, | 201 | If no master table is assigned explicitly, but only one table used in this query, | ||
▲ Show 20 Lines • Show All 164 Lines • ▼ Show 20 Line(s) | |||||
370 | If one of the fields are primary keys, it will be detected | 366 | If one of the fields are primary keys, it will be detected | ||
371 | and appropriate master-detail relation will be established. | 367 | and appropriate master-detail relation will be established. | ||
372 | This functiuon does nothing if the arguments are invalid. */ | 368 | This functiuon does nothing if the arguments are invalid. */ | ||
373 | KDbRelationship* addRelationship(KDbField *field1, KDbField *field2); | 369 | KDbRelationship* addRelationship(KDbField *field1, KDbField *field2); | ||
374 | 370 | | |||
375 | /*! @return list of KDbQueryAsterisk objects defined for this query */ | 371 | /*! @return list of KDbQueryAsterisk objects defined for this query */ | ||
376 | KDbField::List* asterisks() const; | 372 | KDbField::List* asterisks() const; | ||
377 | 373 | | |||
374 | //! Mode for field() and columnInfo() | ||||
375 | //! @since 3.1 | ||||
376 | enum class ExpandMode { | ||||
377 | Unexpanded, //!< All fields are returned even if duplicated | ||||
378 | Expanded //!< Expanded list of the query fields is computed so queries with asterisks | ||||
379 | //!< are processed well | ||||
380 | }; | ||||
381 | | ||||
378 | /*! @return field for @a identifier or @c nullptr if no field for this name | 382 | /*! @return field for @a identifier or @c nullptr if no field for this name | ||
379 | was found within the query. fieldsExpanded() method is used | 383 | was found within the query. fieldsExpanded() method is used | ||
380 | to lookup expanded list of the query fields, so queries with asterisks | 384 | to lookup expanded list of the query fields, so queries with asterisks | ||
381 | are processed well. | 385 | are processed well. | ||
382 | If a field has alias defined, name is not taken into account, | 386 | If a field has alias defined, name is not taken into account, | ||
383 | but only its alias. If a field has no alias: | 387 | but only its alias. If a field has no alias: | ||
384 | - field's name is checked | 388 | - field's name is checked | ||
385 | - field's table and field's name are checked in a form of "tablename.fieldname", | 389 | - field's table and field's name are checked in a form of "tablename.fieldname", | ||
Show All 10 Lines | |||||
396 | Expanded list of columns for the query is: T.B AS X, T.A, T.B, T.C. | 400 | Expanded list of columns for the query is: T.B AS X, T.A, T.B, T.C. | ||
397 | - Calling field("B") will return a pointer to third query column (not the first, | 401 | - Calling field("B") will return a pointer to third query column (not the first, | ||
398 | because it is covered by "X" alias). Additionally, calling field("X") | 402 | because it is covered by "X" alias). Additionally, calling field("X") | ||
399 | will return the same pointer. | 403 | will return the same pointer. | ||
400 | - Calling field("T.A") will return the same pointer as field("A"). | 404 | - Calling field("T.A") will return the same pointer as field("A"). | ||
401 | 405 | | |||
402 | This method is also a product of inheritance from KDbFieldList. | 406 | This method is also a product of inheritance from KDbFieldList. | ||
403 | */ | 407 | */ | ||
404 | const KDbField* field(const QString& identifier) const override; | 408 | const KDbField *field(KDbConnection *conn, const QString &identifier, | ||
405 | 409 | ExpandMode mode = ExpandMode::Expanded) const; | |||
406 | /** | | |||
407 | * @overload const KDbField* field(const QString& identifier) const | | |||
408 | */ | | |||
409 | KDbField* field(const QString& identifier) override; | | |||
410 | 410 | | |||
411 | /** | 411 | /** | ||
412 | * An overloaded method KDbField* field(const QString& identifier) | 412 | * @overload | ||
413 | * where unexpanded list of fields is used to find a field. | | |||
414 | */ | 413 | */ | ||
415 | const KDbField* unexpandedField(const QString& identifier) const; | 414 | KDbField *field(KDbConnection *conn, const QString &identifier, | ||
416 | 415 | ExpandMode mode = ExpandMode::Expanded); | |||
417 | /** | | |||
418 | * @overload const KDbField* unexpandedField(const QString& identifier) const | | |||
419 | */ | | |||
420 | KDbField* unexpandedField(const QString& identifier); | | |||
421 | 416 | | |||
422 | /*! @return field id or @c nullptr if there is no such a field. */ | 417 | /*! @return field id or @c nullptr if there is no such a field. */ | ||
423 | KDbField* field(int id) override; | 418 | KDbField* field(int id) override; | ||
424 | 419 | | |||
420 | using KDbFieldList::field; | ||||
421 | | ||||
425 | /*! @overload KDbField* field(int id) */ | 422 | /*! @overload KDbField* field(int id) */ | ||
426 | const KDbField* field(int id) const override; | 423 | const KDbField* field(int id) const override; | ||
427 | 424 | | |||
428 | /*! Like KDbQuerySchema::field(const QString& name) but returns not only KDbField | 425 | /*! Like KDbQuerySchema::field(const QString& name) but returns not only KDbField | ||
429 | object for @a identifier but entire KDbQueryColumnInfo object. | 426 | object for @a identifier but entire KDbQueryColumnInfo object. | ||
430 | @a identifier can be: | 427 | @a identifier can be: | ||
431 | - a fieldname | 428 | - a fieldname | ||
432 | - an aliasname | 429 | - an aliasname | ||
433 | - a tablename.fieldname | 430 | - a tablename.fieldname | ||
434 | - a tablename.aliasname | 431 | - a tablename.aliasname | ||
435 | Note that if there are two occurrrences of the same name, | 432 | Note that if there are two occurrrences of the same name, | ||
436 | only the first is accessible using this method. For instance, | 433 | only the first is accessible using this method. For instance, | ||
437 | calling columnInfo("name") for "SELECT t1.name, t2.name FROM t1, t2" statement | 434 | calling columnInfo("name") for "SELECT t1.name, t2.name FROM t1, t2" statement | ||
438 | will only return the column related to t1.name and not t2.name, so you'll need to | 435 | will only return the column related to t1.name and not t2.name, so you'll need to | ||
439 | explicitly specify "t2.name" as the identifier to get the second column. */ | 436 | explicitly specify "t2.name" as the identifier to get the second column. */ | ||
440 | KDbQueryColumnInfo* columnInfo(const QString& identifier, bool expanded = true) const; | 437 | KDbQueryColumnInfo *columnInfo(KDbConnection *conn, const QString &identifier, | ||
438 | ExpandMode mode = ExpandMode::Expanded) const; | ||||
441 | 439 | | |||
442 | /*! Options used in fieldsExpanded() and visibleFieldsExpanded(). */ | 440 | //! Mode for fieldsExpanded() and visibleFieldsExpanded() | ||
443 | enum FieldsExpandedOptions { | 441 | //! @since 3.1 | ||
442 | enum class FieldsExpandedMode { | ||||
444 | Default, //!< All fields are returned even if duplicated | 443 | Default, //!< All fields are returned even if duplicated | ||
445 | Unique, //!< Unique list of fields is returned | 444 | Unique, //!< Unique list of fields is returned | ||
446 | WithInternalFields, //!< Like Default but internal fields (for lookup) are appended | 445 | WithInternalFields, //!< Like Default but internal fields (for lookup) are appended | ||
447 | WithInternalFieldsAndRecordId //!< Like WithInternalFields but record ID (big int type) field | 446 | WithInternalFieldsAndRecordId //!< Like WithInternalFields but record ID (big int type) field | ||
448 | //!< is appended after internal fields | 447 | //!< is appended after internal fields | ||
449 | }; | 448 | }; | ||
450 | 449 | | |||
451 | /*! @return fully expanded list of fields. | 450 | /*! @return fully expanded list of fields. | ||
Show All 33 Lines | |||||
485 | if there are multiple occurrences of one or more (options == Default). | 484 | if there are multiple occurrences of one or more (options == Default). | ||
486 | 485 | | |||
487 | Note: You should assign the resulted vector in your space - it will be shared | 486 | Note: You should assign the resulted vector in your space - it will be shared | ||
488 | and implicity copied on any modification. | 487 | and implicity copied on any modification. | ||
489 | This method's result is cached by KDbQuerySchema object. | 488 | This method's result is cached by KDbQuerySchema object. | ||
490 | @todo js: UPDATE CACHE! | 489 | @todo js: UPDATE CACHE! | ||
491 | */ | 490 | */ | ||
492 | inline KDbQueryColumnInfo::Vector fieldsExpanded( | 491 | inline KDbQueryColumnInfo::Vector fieldsExpanded( | ||
493 | FieldsExpandedOptions options = Default) const | 492 | KDbConnection *conn, FieldsExpandedMode mode = FieldsExpandedMode::Default) const | ||
494 | { | 493 | { | ||
495 | return fieldsExpandedInternal(options, false); | 494 | return fieldsExpandedInternal(conn, mode, false); | ||
496 | } | 495 | } | ||
497 | 496 | | |||
498 | /*! Like fieldsExpanded() but returns only visible fields. */ | 497 | /*! Like fieldsExpanded() but returns only visible fields. */ | ||
499 | inline KDbQueryColumnInfo::Vector visibleFieldsExpanded( | 498 | inline KDbQueryColumnInfo::Vector visibleFieldsExpanded( | ||
500 | FieldsExpandedOptions options = Default) const | 499 | KDbConnection *conn, FieldsExpandedMode options = FieldsExpandedMode::Default) const | ||
501 | { | 500 | { | ||
502 | return fieldsExpandedInternal(options, true); | 501 | return fieldsExpandedInternal(conn, options, true); | ||
503 | } | 502 | } | ||
504 | 503 | | |||
505 | /*! @return list of internal fields used for lookup columns. */ | 504 | /*! @return list of internal fields used for lookup columns. */ | ||
506 | KDbQueryColumnInfo::Vector internalFields() const; | 505 | KDbQueryColumnInfo::Vector internalFields(KDbConnection *conn) const; | ||
507 | 506 | | |||
508 | /*! @return info for expanded of internal field at index @a index. | 507 | /*! @return info for expanded of internal field at index @a index. | ||
509 | The returned field can be either logical or internal (for lookup), | 508 | The returned field can be either logical or internal (for lookup), | ||
510 | the latter case is @c true if @a index >= fieldsExpanded().count(). | 509 | the latter case is @c true if @a index >= fieldsExpanded().count(). | ||
511 | Equivalent of KDbQuerySchema::fieldsExpanded(WithInternalFields).at(index). */ | 510 | Equivalent of KDbQuerySchema::fieldsExpanded(WithInternalFields).at(index). */ | ||
512 | KDbQueryColumnInfo* expandedOrInternalField(int index) const; | 511 | KDbQueryColumnInfo* expandedOrInternalField(KDbConnection *conn, int index) const; | ||
513 | 512 | | |||
514 | /*! Options used in columnsOrder(). */ | 513 | //! Mode for columnsOrder() | ||
515 | enum ColumnsOrderOptions { | 514 | //! @since 3.1 | ||
515 | enum class ColumnsOrderMode { | ||||
516 | UnexpandedList, //!< A map for unexpanded list is created | 516 | UnexpandedList, //!< A map for unexpanded list is created | ||
517 | UnexpandedListWithoutAsterisks, //!< A map for unexpanded list is created, with asterisks skipped | 517 | UnexpandedListWithoutAsterisks, //!< A map for unexpanded list is created, with asterisks skipped | ||
518 | ExpandedList //!< A map for expanded list is created | 518 | ExpandedList //!< A map for expanded list is created | ||
519 | }; | 519 | }; | ||
520 | 520 | | |||
521 | /*! @return a hash for fast lookup of query columns' order. | 521 | /*! @return a hash for fast lookup of query columns' order. | ||
522 | - If @a options is UnexpandedList, each KDbQueryColumnInfo pointer is mapped to the index | 522 | - If @a options is UnexpandedList, each KDbQueryColumnInfo pointer is mapped to the index | ||
523 | within (unexpanded) list of fields, i.e. "*" or "table.*" asterisks are considered | 523 | within (unexpanded) list of fields, i.e. "*" or "table.*" asterisks are considered | ||
Show All 18 Lines | 541 | - columnsOrder(ExpandedList) will return the following map: KDbQueryColumnInfo(id)->0, | |||
542 | KDbQueryColumnInfo(name)->1, KDbQueryColumnInfo(surname)->2. | 542 | KDbQueryColumnInfo(name)->1, KDbQueryColumnInfo(surname)->2. | ||
543 | - columnsOrder(UnexpandedList) will return the following map: KDbQueryColumnInfo(id)->0, | 543 | - columnsOrder(UnexpandedList) will return the following map: KDbQueryColumnInfo(id)->0, | ||
544 | KDbQueryColumnInfo(name)->0, KDbQueryColumnInfo(surname)->0 because the column | 544 | KDbQueryColumnInfo(name)->0, KDbQueryColumnInfo(surname)->0 because the column | ||
545 | list is not expanded. This way you can use the returned index to get KDbField* | 545 | list is not expanded. This way you can use the returned index to get KDbField* | ||
546 | pointer using field(int) method of KDbFieldList superclass. | 546 | pointer using field(int) method of KDbFieldList superclass. | ||
547 | - columnsOrder(UnexpandedListWithoutAsterisks) will return the following map: | 547 | - columnsOrder(UnexpandedListWithoutAsterisks) will return the following map: | ||
548 | KDbQueryColumnInfo(id)->0, | 548 | KDbQueryColumnInfo(id)->0, | ||
549 | */ | 549 | */ | ||
550 | QHash<KDbQueryColumnInfo*, int> columnsOrder(ColumnsOrderOptions options = ExpandedList) const; | 550 | QHash<KDbQueryColumnInfo *, int> columnsOrder(KDbConnection *conn, | ||
551 | ColumnsOrderMode mode = ColumnsOrderMode::ExpandedList) const; | ||||
551 | 552 | | |||
552 | /*! @return table describing order of primary key (PKEY) fields within the query. | 553 | /*! @return table describing order of primary key (PKEY) fields within the query. | ||
553 | Indexing is performed against vector returned by fieldsExpanded(). | 554 | Indexing is performed against vector returned by fieldsExpanded(). | ||
554 | It is usable for e.g. Connection::updateRecord(), when we need | 555 | It is usable for e.g. Connection::updateRecord(), when we need | ||
555 | to locate each primary key's field in a constant time. | 556 | to locate each primary key's field in a constant time. | ||
556 | 557 | | |||
557 | Returned vector is owned and cached by KDbQuerySchema object. When you assign it, | 558 | Returned vector is owned and cached by KDbQuerySchema object. When you assign it, | ||
558 | it is implicity shared. Its size is equal to number of primary key | 559 | it is implicity shared. Its size is equal to number of primary key | ||
559 | fields defined for master table (masterTable()->primaryKey()->fieldCount()). | 560 | fields defined for master table (masterTable()->primaryKey()->fieldCount()). | ||
560 | 561 | | |||
561 | Each element of the returned vector: | 562 | Each element of the returned vector: | ||
562 | - can belong to [0..fieldsExpanded().count()-1] if there is such | 563 | - can belong to [0..fieldsExpanded().count()-1] if there is such | ||
563 | primary key's field in the fieldsExpanded() list. | 564 | primary key's field in the fieldsExpanded() list. | ||
564 | - can be equal to -1 if there is no such primary key's field | 565 | - can be equal to -1 if there is no such primary key's field | ||
565 | in the fieldsExpanded() list. | 566 | in the fieldsExpanded() list. | ||
566 | 567 | | |||
567 | If there are more than one primary key's field included in the query, | 568 | If there are more than one primary key's field included in the query, | ||
568 | only first-found column (oin the fieldsExpanded() list) for each pkey's field is included. | 569 | only first-found column (oin the fieldsExpanded() list) for each pkey's field is included. | ||
569 | 570 | | |||
570 | Returns empty vector if there is no master table or no master table's pkey. | 571 | Returns empty vector if there is no master table or no master table's pkey. | ||
571 | @see example for pkeyFieldCount(). | 572 | @see example for pkeyFieldCount(). | ||
572 | @todo js: UPDATE CACHE! | 573 | @todo js: UPDATE CACHE! | ||
573 | */ | 574 | */ | ||
574 | QVector<int> pkeyFieldsOrder() const; | 575 | QVector<int> pkeyFieldsOrder(KDbConnection *conn) const; | ||
575 | 576 | | |||
576 | /*! @return number of master table's primary key fields included in this query. | 577 | /*! @return number of master table's primary key fields included in this query. | ||
577 | This method is useful to quickly check whether the vector returned by pkeyFieldsOrder() | 578 | This method is useful to quickly check whether the vector returned by pkeyFieldsOrder() | ||
578 | if filled completely. | 579 | if filled completely. | ||
579 | 580 | | |||
580 | User e.g. in KDbConnection::updateRecord() to check if entire primary | 581 | User e.g. in KDbConnection::updateRecord() to check if entire primary | ||
581 | key information is specified. | 582 | key information is specified. | ||
582 | 583 | | |||
583 | Examples: let table T has (ID1 INTEGER, ID2 INTEGER, A INTEGER) fields, | 584 | Examples: let table T has (ID1 INTEGER, ID2 INTEGER, A INTEGER) fields, | ||
584 | and let (ID1, ID2) is T's primary key. | 585 | and let (ID1, ID2) is T's primary key. | ||
585 | -# The query defined by "SELECT * FROM T" statement contains all T's | 586 | -# The query defined by "SELECT * FROM T" statement contains all T's | ||
586 | primary key's fields as T is the master table, and thus pkeyFieldCount() | 587 | primary key's fields as T is the master table, and thus pkeyFieldCount() | ||
587 | will return 2 (both primary key's fields are in the fieldsExpanded() list), | 588 | will return 2 (both primary key's fields are in the fieldsExpanded() list), | ||
588 | and pkeyFieldsOrder() will return vector {0, 1}. | 589 | and pkeyFieldsOrder() will return vector {0, 1}. | ||
589 | -# The query defined by "SELECT A, ID2 FROM T" statement, and thus pkeyFieldCount() | 590 | -# The query defined by "SELECT A, ID2 FROM T" statement, and thus pkeyFieldCount() | ||
590 | will return 1 (only one primary key's field is in the fieldsExpanded() list), | 591 | will return 1 (only one primary key's field is in the fieldsExpanded() list), | ||
591 | and pkeyFieldsOrder() will return vector {-1, 1}, as second primary key's field | 592 | and pkeyFieldsOrder() will return vector {-1, 1}, as second primary key's field | ||
592 | is at position #1 and first field is not specified at all within the query. | 593 | is at position #1 and first field is not specified at all within the query. | ||
593 | */ | 594 | */ | ||
594 | int pkeyFieldCount(); | 595 | int pkeyFieldCount(KDbConnection *conn); | ||
595 | 596 | | |||
596 | /*! @return a list of field infos for all auto-incremented fields | 597 | /*! @return a list of field infos for all auto-incremented fields | ||
597 | from master table of this query. This result is cached for efficiency. | 598 | from master table of this query. This result is cached for efficiency. | ||
598 | fieldsExpanded() is used for that. | 599 | fieldsExpanded() is used for that. | ||
599 | */ | 600 | */ | ||
600 | KDbQueryColumnInfo::List* autoIncrementFields() const; | 601 | KDbQueryColumnInfo::List* autoIncrementFields(KDbConnection *conn) const; | ||
601 | 602 | | |||
602 | /*! @return a preset statement (if any). */ | 603 | /*! @return a preset statement (if any). */ | ||
603 | KDbEscapedString statement() const; | 604 | KDbEscapedString statement() const; | ||
604 | 605 | | |||
605 | /*! Forces a raw SQL statement @a sql for the query. This means that no statement is composed | 606 | /*! Forces a raw SQL statement @a sql for the query. This means that no statement is composed | ||
606 | * from KDbQuerySchema's content. */ | 607 | * from KDbQuerySchema's content. */ | ||
607 | void setStatement(const KDbEscapedString& sql); | 608 | void setStatement(const KDbEscapedString& sql); | ||
608 | 609 | | |||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | |||||
676 | Read notes for @ref setOrderByColumnList(). */ | 677 | Read notes for @ref setOrderByColumnList(). */ | ||
677 | KDbOrderByColumnList* orderByColumnList(); | 678 | KDbOrderByColumnList* orderByColumnList(); | ||
678 | 679 | | |||
679 | /*! @see orderByColumnList() */ | 680 | /*! @see orderByColumnList() */ | ||
680 | const KDbOrderByColumnList* orderByColumnList() const; | 681 | const KDbOrderByColumnList* orderByColumnList() const; | ||
681 | 682 | | |||
682 | /*! @return query schema parameters. These are taked from the WHERE section | 683 | /*! @return query schema parameters. These are taked from the WHERE section | ||
683 | (a tree of expression items). */ | 684 | (a tree of expression items). */ | ||
684 | QList<KDbQuerySchemaParameter> parameters() const; | 685 | QList<KDbQuerySchemaParameter> parameters(KDbConnection *conn) const; | ||
685 | 686 | | |||
686 | //! @return @c true if this query is valid | 687 | //! @return @c true if this query is valid | ||
687 | /*! Detailed validation is performed in the same way as parsing of query statements | 688 | /*! Detailed validation is performed in the same way as parsing of query statements | ||
688 | * by the KDbParser. | 689 | * by the KDbParser. | ||
689 | * Example :Let the query be "SELECT <fields> FROM <tables> WHERE <whereExpression>". | 690 | * Example :Let the query be "SELECT <fields> FROM <tables> WHERE <whereExpression>". | ||
690 | * First each field from <fields> (@see fields()) is validated using | 691 | * First each field from <fields> (@see fields()) is validated using | ||
691 | * KDbField::expression().validate(). Then the <whereExpression> (@see | 692 | * KDbField::expression().validate(). Then the <whereExpression> (@see | ||
692 | * whereExpression()) | 693 | * whereExpression()) | ||
693 | * is validated using KDbExpression::validate(). | 694 | * is validated using KDbExpression::validate(). | ||
694 | * | 695 | * | ||
695 | * On error a string pointed by @a errorMessage (if provided) is set to a general | 696 | * On error a string pointed by @a errorMessage (if provided) is set to a general | ||
696 | * error message and a string pointed by @a errorDescription (if provided) is set to a | 697 | * error message and a string pointed by @a errorDescription (if provided) is set to a | ||
697 | * detailed description of the error. | 698 | * detailed description of the error. | ||
698 | */ | 699 | */ | ||
699 | //! @todo add tests | 700 | //! @todo add tests | ||
700 | bool validate(QString *errorMessage = nullptr, QString *errorDescription = nullptr); | 701 | bool validate(QString *errorMessage = nullptr, QString *errorDescription = nullptr); | ||
701 | 702 | | |||
702 | class Private; // Protected not private because of the parser | 703 | class Private; // Protected not private because of the parser | ||
703 | 704 | | |||
704 | protected: | 705 | protected: | ||
705 | //! @internal associates @a conn with this query so it's possible to find tables | 706 | void computeFieldsExpanded(KDbConnection *conn) const; | ||
706 | explicit KDbQuerySchema(KDbConnection *conn); | | |||
707 | | ||||
708 | void computeFieldsExpanded() const; | | |||
709 | 707 | | |||
710 | //! Used by fieldsExpanded(FieldsExpandedOptions) | 708 | //! Used by fieldsExpanded(KDbConnection*, FieldsExpandedMode) | ||
711 | //! and visibleFieldsExpanded(FieldsExpandedOptions options). | 709 | //! and visibleFieldsExpanded(KDbConnection*, FieldsExpandedMode). | ||
712 | KDbQueryColumnInfo::Vector fieldsExpandedInternal(FieldsExpandedOptions options, | 710 | KDbQueryColumnInfo::Vector fieldsExpandedInternal(KDbConnection *conn, | ||
711 | FieldsExpandedMode mode, | ||||
713 | bool onlyVisible) const; | 712 | bool onlyVisible) const; | ||
714 | 713 | | |||
715 | /** Internal method used by all insert*Field methods. | 714 | /** Internal method used by all insert*Field methods. | ||
716 | * The new column can also be explicitly bound to a specific position on tables list. | 715 | * The new column can also be explicitly bound to a specific position on tables list. | ||
717 | * @a bindToTable is a table index within the query for which the field should be bound. | 716 | * @a bindToTable is a table index within the query for which the field should be bound. | ||
718 | * If @a bindToTable is -1, no particular table will be bound. | 717 | * If @a bindToTable is -1, no particular table will be bound. | ||
719 | * @see tableBoundToColumn(int columnPosition) | 718 | * @see tableBoundToColumn(int columnPosition) | ||
720 | */ | 719 | */ | ||
Show All 9 Lines | |||||
730 | * Appends expression @a expr at the and of columns list, sets visibility. | 729 | * Appends expression @a expr at the and of columns list, sets visibility. | ||
731 | */ | 730 | */ | ||
732 | bool addExpressionInternal(const KDbExpression& expr, bool visible); | 731 | bool addExpressionInternal(const KDbExpression& expr, bool visible); | ||
733 | 732 | | |||
734 | /** Internal method used by a query parser. | 733 | /** Internal method used by a query parser. | ||
735 | */ | 734 | */ | ||
736 | void setWhereExpressionInternal(const KDbExpression &expr); | 735 | void setWhereExpressionInternal(const KDbExpression &expr); | ||
737 | 736 | | |||
737 | Q_DISABLE_COPY(KDbQuerySchema) | ||||
738 | Private * const d; | 738 | Private * const d; | ||
739 | }; | 739 | }; | ||
740 | 740 | | |||
741 | //! Sends query schema information @a query to debug output @a dbg. | 741 | //! A pair (connection, table-or-schema) for QDebug operator<< | ||
742 | KDB_EXPORT QDebug operator<<(QDebug dbg, const KDbQuerySchema& query); | 742 | //! @since 3.1 | ||
743 | typedef std::tuple<KDbConnection*, const KDbQuerySchema&> KDbConnectionAndQuerySchema; | ||||
744 | | ||||
745 | //! Sends connection and query schema information @a connectionAndSchema to debug output @a dbg. | ||||
746 | //! @since 3.1 | ||||
747 | KDB_EXPORT QDebug operator<<(QDebug dbg, | ||||
748 | const KDbConnectionAndQuerySchema &connectionAndSchema); | ||||
743 | 749 | | |||
744 | #endif | 750 | #endif |