KexiDB::QuerySchema Class Reference
#include <queryschema.h>
Inheritance diagram for KexiDB::QuerySchema:

Detailed Description
KexiDB::QuerySchema provides information about database query.The query that can be executed using KexiDB-compatible SQL database engine or used as an introspection tool. KexiDB parser builds QuerySchema objects by parsing SQL statements.
Definition at line 221 of file queryschema.h.
Public Types | |
| enum | FieldsExpandedOptions { Default, Unique, WithInternalFields, WithInternalFieldsAndRowID } |
| enum | ColumnsOrderOptions { UnexpandedList, UnexpandedListWithoutAsterisks, ExpandedList } |
Public Member Functions | |
| QuerySchema () | |
| QuerySchema (TableSchema *tableSchema) | |
| virtual | ~QuerySchema () |
| virtual FieldList & | insertField (uint position, Field *field) |
| FieldList & | insertField (uint position, Field *field, bool visible) |
| FieldList & | insertField (uint position, Field *field, int bindToTable, bool visible=true) |
| FieldList & | addField (Field *field, bool visible=true) |
| FieldList & | addField (Field *field, int bindToTable, bool visible=true) |
| virtual void | removeField (Field *field) |
| FieldList & | addExpression (BaseExpr *expr, bool visible=true) |
| bool | isColumnVisible (uint position) const |
| void | setColumnVisible (uint position, bool v) |
| Sets visibility flag for column at position to v. | |
| FieldList & | addAsterisk (QueryAsterisk *asterisk, bool visible=true) |
| virtual void | clear () |
| virtual QString | debugString () |
| Connection * | connection () const |
| TableSchema * | masterTable () const |
| void | setMasterTable (TableSchema *table) |
| TableSchema::List * | tables () const |
| void | addTable (TableSchema *table, const QCString &alias=QCString()) |
| void | removeTable (TableSchema *table) |
| TableSchema * | table (const QString &tableName) const |
| bool | contains (TableSchema *table) const |
| Field * | findTableField (const QString &tableOrTableAndFieldName) const |
| QCString | columnAlias (uint position) const |
| bool | hasColumnAlias (uint position) const |
| void | setColumnAlias (uint position, const QCString &alias) |
| int | tableBoundToColumn (uint columnPosition) const |
| QCString | tableAlias (uint position) const |
| int | tablePositionForAlias (const QCString &name) const |
| int | tablePosition (const QString &tableName) const |
| QValueList< int > | tablePositions (const QString &tableName) const |
| bool | hasTableAlias (uint position) const |
| int | columnPositionForAlias (const QCString &name) const |
| void | setTableAlias (uint position, const QCString &alias) |
| Relationship::List * | relationships () const |
| Relationship * | addRelationship (Field *field1, Field *field2) |
| Field::List * | asterisks () const |
| virtual Field * | field (const QString &name, bool expanded=true) |
| Field * | field (uint id) |
| QueryColumnInfo * | columnInfo (const QString &identifier, bool expanded=true) |
| QueryColumnInfo::Vector | fieldsExpanded (FieldsExpandedOptions options=Default) |
| QueryColumnInfo::Vector | internalFields () |
| QueryColumnInfo * | expandedOrInternalField (uint index) |
| QMap< QueryColumnInfo *, int > | columnsOrder (ColumnsOrderOptions options=ExpandedList) |
| QValueVector< int > | pkeyFieldsOrder () |
| uint | pkeyFieldsCount () |
| QueryColumnInfo::List * | autoIncrementFields () |
| QString | statement () const |
| void | setStatement (const QString &s) |
| QString | autoIncrementSQLFieldsList (Driver *driver) |
| void | setWhereExpression (BaseExpr *expr) |
| BaseExpr * | whereExpression () const |
| void | addToWhereExpression (KexiDB::Field *field, const QVariant &value, int relation= '=') |
| void | setOrderByColumnList (const OrderByColumnList &list) |
| OrderByColumnList & | orderByColumnList () const |
| QuerySchemaParameterList | parameters () |
Static Public Member Functions | |
| static QString | sqlColumnsList (QueryColumnInfo::List *infolist, Driver *driver) |
Protected Member Functions | |
| void | init () |
| void | computeFieldsExpanded () |
Protected Attributes | |
| QuerySchemaPrivate * | d |
Friends | |
| class | Connection |
| class | QuerySchemaPrivate |
Member Enumeration Documentation
|
|
Options used in columnsOrder().
Definition at line 592 of file queryschema.h. |
|
|
Options used in fieldsExpanded().
Definition at line 531 of file queryschema.h. |
Constructor & Destructor Documentation
|
|
Creates empty query object (without columns). Definition at line 500 of file queryschema.cpp. References init(). |
|
|
Creates query schema object that is equivalent to "SELECT * FROM table" sql command. Schema of table is used to contruct this query -- it is defined just adding all the fields to the query in natural order. To avoid problems (e.g. with fields added outside of Kexi using ALTER TABLE) we do not use "all-tables query asterisk" (see QueryAsterisk) item to achieve this effect. Properties such as the name and caption of the query are inherited from table schema. We consider that query schema based on table is not (a least yet) stored in a system table, so query connection is set to NULL (even if tableSchema's connection is not NULL). Id of the created query is set to 0. Definition at line 508 of file queryschema.cpp. References addField(), addTable(), d, init(), KexiDBWarn, KexiDB::SchemaData::m_caption, and KexiDB::SchemaData::m_name. |
|
|
Definition at line 537 of file queryschema.cpp. References d. |
Member Function Documentation
|
||||||||||||
|
Adds asterisk at the and of columns list. Definition at line 687 of file queryschema.cpp. References addField(), and asterisks(). Referenced by addColumn(). |
|
||||||||||||
|
Adds a field built on top of expr expression. This creates a new Field object and adds it to the query schema using addField(). Definition at line 671 of file queryschema.cpp. References addField(). Referenced by addColumn(). |
|
||||||||||||||||
|
Adds field to the columns list. Also binds to a table at bindToTable position. Use bindToTable==-1 if no table should be bound. If visible is true (the default), the field will be visible.
Definition at line 653 of file queryschema.cpp. References insertField(), and KexiDB::FieldList::m_fields. |
|
||||||||||||
|
Adds field to the columns list. If visible is true (the default), the field will be visible.
Definition at line 648 of file queryschema.cpp. References insertField(), and KexiDB::FieldList::m_fields. Referenced by addAsterisk(), addColumn(), addExpression(), KexiFormView::initDataSource(), KexiBLOBBuffer::objectForId(), and QuerySchema(). |
|
||||||||||||
|
Adds a new relationship defined by field1 and field2. Both fields should belong to two different tables of this query. This is convenience function useful for a typical cases. It automatically creates Relationship object for this query. If one of the fields are primary keys, it will be detected and appropriate master-detail relation will be established. This functiuon does nothing if the arguments are invalid. Definition at line 1395 of file queryschema.cpp. References d, and KexiDB::Relationship::isEmpty(). |
|
||||||||||||
|
Adds table schema as one of tables used in a query. if alias is not empty, it will be assigned to this table using setTableAlias(position, alias) Definition at line 838 of file queryschema.cpp. References d, KexiDBDbg, KexiDBWarn, setTableAlias(), and tableAlias(). Referenced by buildSelectQuery(), and QuerySchema(). |
|
||||||||||||||||
|
Adds a part to WHERE expression. Simplifies creating of WHERE expression, if used instead of setWhereExpression(BaseExpr *expr). Definition at line 1465 of file queryschema.cpp. References AND, CHARACTER_STRING_LITERAL, d, INTEGER_CONST, KexiDB::Field::isFPNumericType(), KexiDB::Field::isIntegerType(), KexiDBExpr_Logical, KexiDBExpr_Relational, KexiDB::Field::name(), REAL_CONST, SQL_NULL, and KexiDB::Field::table(). Referenced by KexiBLOBBuffer::objectForId(). |
|
|
Definition at line 1021 of file queryschema.cpp. References d. Referenced by addAsterisk(). |
|
|
Reimplemented from KexiDB::FieldList. Definition at line 1408 of file queryschema.cpp. References d, KexiDB::QueryColumnInfo::field, fieldsExpanded(), KexiDB::Field::isAutoIncrement(), KexiDBWarn, masterTable(), and KexiDB::Field::table(). Referenced by autoIncrementSQLFieldsList(), and KexiDB::Connection::insertRow(). |
|
|
Definition at line 1448 of file queryschema.cpp. References autoIncrementFields(), d, and sqlColumnsList(). Referenced by KexiDB::Connection::insertRow(). |
|
|
Removes all columns and their aliases from the columns list, removes all tables and their aliases from the tables list within this query. Sets master table information to NULL. Does not destroy any objects though. Clears name and all other properties.
Reimplemented from KexiDB::FieldList. Definition at line 548 of file queryschema.cpp. References KexiDB::SchemaData::clear(), KexiDB::FieldList::clear(), and d. Referenced by KexiQueryPart::TempData::clearQuery(). |
|
|
Definition at line 915 of file queryschema.cpp. References d. Referenced by computeFieldsExpanded(), KexiDB::Connection::selectStatement(), and KexiQueryDesignerGuiEditor::showFieldsOrRelationsForQueryInternal(). |
|
||||||||||||
|
Like QuerySchema::field(const QString& name) but returns not only Field object for identifier but entire QueryColumnInfo object. identifier can be:
Definition at line 1042 of file queryschema.cpp. References computeFieldsExpanded(), and d. Referenced by KexiDB::OrderByColumnList::appendField(), buildSelectQuery(), field(), and KexiFormDataProvider::invalidateDataSources(). |
|
|
Definition at line 985 of file queryschema.cpp. References d. |
|
|
Example use: let t be table (int id, name text, surname text) and q be query defined by a statement "select * from t".
Definition at line 1344 of file queryschema.cpp. References computeFieldsExpanded(), d, UnexpandedList, and UnexpandedListWithoutAsterisks. Referenced by KexiFormDataProvider::invalidateDataSources(), KexiQueryDesignerGuiEditor::showFieldsOrRelationsForQueryInternal(), and updateRowDataWithNewValues(). |
|
|
Definition at line 1117 of file queryschema.cpp. References columnAlias(), connection(), d, KexiDB::QueryColumnInfo::debugString(), KexiDB::QueryColumnInfo::field, KexiDB::FieldList::field(), KexiDB::FieldList::fieldCount(), KexiDB::FieldList::fields(), fieldsExpanded(), KexiDB::FieldList::fieldsIterator(), KexiDB::QueryColumnInfo::foreignColumn(), isColumnVisible(), KexiDB::Field::isQueryAsterisk(), KexiDBDbg, LOOKUP_COLUMN_KEY, KexiDB::LookupFieldSchema::RowSource::name(), KexiDB::QueryColumnInfo::setIndexForVisibleLookupValue(), KexiDB::Field::table(), KexiDB::LookupFieldSchema::RowSource::Table, table(), and KexiDB::LookupFieldSchema::RowSource::type(). Referenced by columnInfo(), columnsOrder(), fieldsExpanded(), and internalFields(). |
|
|
If query was created using a connection, returns this connection object, otherwise NULL. Definition at line 697 of file queryschema.cpp. References KexiDB::TableSchema::connection(), and masterTable(). Referenced by computeFieldsExpanded(), KexiDB::rowCount(), KexiTableViewColumn::KexiTableViewColumn(), and KexiDB::Connection::selectStatement(). |
|
|
Definition at line 890 of file queryschema.cpp. References d. |
|
|
Reimplemented from KexiDB::FieldList. Definition at line 703 of file queryschema.cpp. References d, KexiDB::QueryColumnInfo::debugString(), KexiDB::FieldList::debugString(), field, KexiDB::FieldList::fieldCount(), fieldsExpanded(), KexiDB::FieldList::m_fields, masterTable(), KexiDB::SchemaData::name(), orderByColumnList(), KexiDB::SchemaData::schemaDataDebugString(), table(), tableAlias(), and tableBoundToColumn(). Referenced by KexiDB::Cursor::Cursor(). |
|
|
Definition at line 1111 of file queryschema.cpp. References fieldsExpanded(), and WithInternalFields. Referenced by KexiComboBoxTableEdit::createInternalEditor(), and KexiCSVExport::exportData(). |
|
|
Reimplemented from KexiDB::FieldList. Definition at line 514 of file queryschema.h. References field. |
|
||||||||||||
|
Example: Let query be defined by "SELECT T.B AS X, T.* FROM T" statement and let T be table containing fields A, B, C. Expanded list of columns for the query is: T.B AS X, T.A, T.B, T.C.
Definition at line 1036 of file queryschema.cpp. References columnInfo(), and KexiDB::QueryColumnInfo::field. Referenced by KexiFormView::initDataSource(). |
|
|
If options is WithInternalFields or WithInternalFieldsAndRowID, additional internal fields are also appended to the vector. If options is WithInternalFieldsAndRowID, one fake BigInteger column is appended to make space for ROWID column used by KexiDB::Cursor implementations. For example, let persons be TABLE( surname, city_id ), let city_number reference cities.is in TABLE cities( id, name ) and let query q be defined by "SELECT * FROM t" statement. If we want to display persons' city names instead of city_id's. To do this, cities.name has to be retrieved as well, so the following statement should be used: "SELECT * FROM persons, cities.name LEFT OUTER JOIN cities ON persons.city_id=cities.id". Thus, calling fieldsExpanded(WithInternalFieldsAndRowID) will return 4 elements instead of 2: persons.surname, persons.city_id, cities.name, {ROWID}. The {ROWID} item is the placeholder used for fetching ROWID by KexiDB cursors. By default, all fields are returned in the vector even if there are multiple occurrences of one or more (options == Default). Note: You should assign the resulted vector in your space - it will be shared and implicity copied on any modification. This method's result is cached by QuerySchema object.
Definition at line 1048 of file queryschema.cpp. References KexiDB::QueryColumnInfo::aliasOrName(), KexiDB::Field::BigInteger, computeFieldsExpanded(), d, Default, size, WithInternalFields, and WithInternalFieldsAndRowID. Referenced by KexiDB::OrderByColumnList::appendColumn(), autoIncrementFields(), computeFieldsExpanded(), debugString(), expandedOrInternalField(), KexiSimplePrintingEngine::init(), KexiDB::Connection::insertRow(), KexiFormDataProvider::invalidateDataSources(), KexiCSVExport::exportData(), and pkeyFieldsOrder(). |
|
|
Convenience function.
QuerySchema::table("mytable")->field("myfield") could be alternative for findTableField("mytable.myfield") but it can crash if "mytable" is not defined in the query.
Definition at line 895 of file queryschema.cpp. References d, KexiDB::FieldList::field(), KexiDB::SetFieldNameIfNoTableName, KexiDB::splitToTableAndFieldParts(), and table(). Referenced by KexiDB::OrderByColumnList::appendField(), buildSelectQuery(), and KexiQueryDesignerGuiEditor::showFieldsOrRelationsForQueryInternal(). |
|
|
Provided for convenience.
Definition at line 921 of file queryschema.cpp. References d. |
|
|
Provided for convenience.
Definition at line 980 of file queryschema.cpp. References d. |
|
|
Definition at line 542 of file queryschema.cpp. References KexiDB::SchemaData::m_type, and KexiDB::QueryObjectType. Referenced by QuerySchema(). |
|
||||||||||||||||||||
|
Definition at line 566 of file queryschema.cpp. References d, KexiDB::FieldList::fieldCount(), KexiDB::FieldList::insertField(), KexiDB::Field::isExpression(), KexiDB::Field::isQueryAsterisk(), KexiDBDbg, KexiDBWarn, KexiDB::FieldList::m_fields, KexiDB::Field::name(), KexiDB::Field::table(), and tableAlias(). |
|
||||||||||||||||
|
Definition at line 555 of file queryschema.cpp. References insertField(). |
|
||||||||||||
|
Inserts field to the columns list at position. Inserted field will not be owned by this QuerySchema object, but still by corresponding TableSchema. As field object you can also pass KexiDB::QueryAsterisk, (see QueryAsterisk class description). Note: After inserting a field, corresponding table will be automatically added to query's tables list if it is not present there (see tables()). Field must have its table assigned. Added field will be visible. Use insertField(position, field, false) to add invisible field. Definition at line 561 of file queryschema.cpp. Referenced by addField(), and insertField(). |
|
|
Definition at line 1105 of file queryschema.cpp. References computeFieldsExpanded(), and d. |
|
|
Definition at line 676 of file queryschema.cpp. Referenced by computeFieldsExpanded(), and KexiDB::Connection::selectStatement(). |
|
|
Definition at line 807 of file queryschema.cpp. References d, and tableAlias(). Referenced by autoIncrementFields(), connection(), debugString(), KexiDB::Connection::deleteAllRows(), KexiDB::Connection::deleteRow(), KexiDB::Cursor::init(), KexiDB::Connection::insertRow(), KexiTableViewColumn::KexiTableViewColumn(), pkeyFieldsOrder(), KexiDB::Connection::selectStatement(), and KexiDB::Connection::updateRow(). |
|
|
Definition at line 1527 of file queryschema.cpp. References d. Referenced by buildSelectQuery(), debugString(), KexiDB::Connection::selectStatement(), and KexiQueryDesignerGuiEditor::showFieldsOrRelationsForQueryInternal(). |
|
|
Definition at line 1532 of file queryschema.cpp. References whereExpression(). Referenced by KexiQueryView::executeQuery(), and KexiQueryParameters::getParameters(). |
|
|
Examples: let table T has (ID1 INTEGER, ID2 INTEGER, A INTEGER) fields, and let (ID1, ID2) is T's primary key.
Definition at line 1389 of file queryschema.cpp. References d, and pkeyFieldsOrder(). Referenced by KexiDB::Connection::deleteRow(), KexiDB::Connection::insertRow(), and KexiDB::Connection::updateRow(). |
|
|
Each element of the returned vector:
If there are more than one primary key's field included in the query, only first-found column (oin the fieldsExpanded() list) for each pkey's field is included. Returns empty vector if there is no master table or no master table's pkey.
Definition at line 1355 of file queryschema.cpp. References d, KexiDB::QueryColumnInfo::field, KexiDB::FieldList::fieldCount(), fieldsExpanded(), KexiDB::FieldList::indexOf(), KexiDBDbg, masterTable(), KexiDB::SchemaData::name(), KexiDB::Field::name(), KexiDB::TableSchema::primaryKey(), and KexiDB::Field::table(). Referenced by KexiDB::Connection::deleteRow(), KexiDB::Connection::insertRow(), pkeyFieldsCount(), and KexiDB::Connection::updateRow(). |
|
|
Definition at line 1016 of file queryschema.cpp. References d. Referenced by KexiDB::Connection::selectStatement(), and KexiQueryDesignerGuiEditor::showFieldsOrRelationsForQueryInternal(). |
|
|
Removes field from the columns list. Use with care. Reimplemented from KexiDB::FieldList. Definition at line 659 of file queryschema.cpp. References d, KexiDB::Field::isQueryAsterisk(), and KexiDB::FieldList::removeField(). |
|
|
Removes table schema from this query. This does not destroy table object but only takes it out of the list. If this table was master for the query, master table information is also invalidated. Definition at line 870 of file queryschema.cpp. References d. |
|
||||||||||||
|
Sets alias for a column at position, within the query. Passing empty string to alias clears alias for a given column. Definition at line 926 of file queryschema.cpp. References KexiDB::Field::captionOrName(), d, field, KexiDBWarn, and KexiDB::FieldList::m_fields. Referenced by buildSelectQuery(). |
|
||||||||||||
|
Sets visibility flag for column at position to v.
Definition at line 681 of file queryschema.cpp. References d, and KexiDB::FieldList::fieldCount(). |
|
|
Sets master table of this query to table. This table should be also added to query's tables list using addTable(). If table equals NULL, nothing is performed.
Definition at line 827 of file queryschema.cpp. References d. Referenced by buildSelectQuery(). |
|
|
Sets a list of columns for ORDER BY section of the query. Each name on the list must be a field or alias present within the query and must not be covered by aliases. If one or more names cannot be found within the query, the method will have no effect. Any previous ORDER BY settings will be removed. Note that this information is cleared whenever you call methods that modify list of columns (QueryColumnInfo), i.e. insertFiled(), addField(), removeField(), addExpression(), etc. (because OrderByColumn items can point to a QueryColumnInfo that's removed by these methods), so you should use setOrderByColumnList() method after the query is completely built. Definition at line 1521 of file queryschema.cpp. References d. |
|
|
Forces a query statement (i.e. no statement is composed from QuerySchema's content) Definition at line 1031 of file queryschema.cpp. References d. |
|
||||||||||||
|
Sets alias for a table at position (within FROM section of the the query). Passing empty sting to alias clears alias for a given table (only for specified position). Definition at line 993 of file queryschema.cpp. References d, and KexiDBWarn. Referenced by addTable(). |
|
|
Sets a WHERE expression exp. It will be owned by this query, so you can forget about it. Previously set WHERE expression will be deleted. You can pass 0 to remove expresssion. Definition at line 1459 of file queryschema.cpp. References d. Referenced by buildSelectQuery(). |
|
||||||||||||
|
Definition at line 1430 of file queryschema.cpp. References KexiDB::Driver::escapeIdentifier(). Referenced by autoIncrementSQLFieldsList(). |
|
|
Definition at line 1026 of file queryschema.cpp. References d. Referenced by KexiDB::Connection::selectStatement(). |
|
|
