kexi

#include <queryschema.h>

Inheritance diagram for KexiDB::QuerySchema:
KexiDB::FieldList KexiDB::SchemaData

Public Types

enum  FieldsExpandedOptions { Default , Unique , WithInternalFields , WithInternalFieldsAndRowID }
enum  ColumnsOrderOptions { UnexpandedList , UnexpandedListWithoutAsterisks , ExpandedList }

Public Member Functions

 QuerySchema ()
 QuerySchema (TableSchema &tableSchema)
 QuerySchema (const QuerySchema &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)
FieldList & addAsterisk (QueryAsterisk *asterisk, bool visible=true)
virtual void clear ()
virtual TQString debugString ()
Connection * connection () const
TableSchema * masterTable () const
void setMasterTable (TableSchema *table)
TableSchema::List * tables () const
void addTable (TableSchema *table, const TQCString &alias=TQCString())
void removeTable (TableSchema *table)
TableSchema * table (const TQString &tableName) const
bool contains (TableSchema *table) const
Field * findTableField (const TQString &tableOrTableAndFieldName) const
TQCString columnAlias (uint position) const
bool hasColumnAlias (uint position) const
void setColumnAlias (uint position, const TQCString &alias)
int tableBoundToColumn (uint columnPosition) const
TQCString tableAlias (uint position) const
int tablePositionForAlias (const TQCString &name) const
int tablePosition (const TQString &tableName) const
TQValueList< int > tablePositions (const TQString &tableName) const
bool hasTableAlias (uint position) const
int columnPositionForAlias (const TQCString &name) const
void setTableAlias (uint position, const TQCString &alias)
Relationship::List * relationships () const
Relationship * addRelationship (Field *field1, Field *field2)
Field::List * asterisks () const
virtual Field * field (const TQString &name, bool expanded=true)
Field * field (uint id)
QueryColumnInfo * columnInfo (const TQString &identifier, bool expanded=true)
QueryColumnInfo::Vector fieldsExpanded (FieldsExpandedOptions options=Default)
QueryColumnInfo::Vector internalFields ()
QueryColumnInfo * expandedOrInternalField (uint index)
TQMap< QueryColumnInfo *, int > columnsOrder (ColumnsOrderOptions options=ExpandedList)
TQValueVector< int > pkeyFieldsOrder ()
uint pkeyFieldsCount ()
QueryColumnInfo::List * autoIncrementFields ()
TQString statement () const
void setStatement (const TQString &s)
TQString autoIncrementSQLFieldsList (Driver *driver)
void setWhereExpression (BaseExpr *expr)
BaseExpr * whereExpression () const
void addToWhereExpression (KexiDB::Field *field, const TQVariant &value, int relation='=')
void setOrderByColumnList (const OrderByColumnList &list)
OrderByColumnList & orderByColumnList () const
QuerySchemaParameterList parameters ()
Public Member Functions inherited from KexiDB::FieldList
 FieldList (bool owner=false)
 FieldList (const FieldList &fl, bool deepCopyFields=true)
virtual ~FieldList ()
uint fieldCount () const
FieldList & addField (Field *field)
Field * field (uint id)
virtual Field * field (const TQString &name)
bool hasField (const Field *field)
int indexOf (const Field *field)
TQStringList names () const
Field::ListIterator fieldsIterator () const
Field::List * fields ()
Field::List * autoIncrementFields ()
bool isOwner () const
void debug ()
FieldList * subList (const TQString &n1, const TQString &n2=TQString(), const TQString &n3=TQString(), const TQString &n4=TQString(), const TQString &n5=TQString(), const TQString &n6=TQString(), const TQString &n7=TQString(), const TQString &n8=TQString(), const TQString &n9=TQString(), const TQString &n10=TQString(), const TQString &n11=TQString(), const TQString &n12=TQString(), const TQString &n13=TQString(), const TQString &n14=TQString(), const TQString &n15=TQString(), const TQString &n16=TQString(), const TQString &n17=TQString(), const TQString &n18=TQString())
FieldList * subList (const TQStringList &list)
FieldList * subList (const TQValueList< uint > &list)
TQString sqlFieldsList (Driver *driver, const TQString &separator=TQString::fromLatin1(","), const TQString &tableAlias=TQString(), int drvEscaping=Driver::EscapeDriver|Driver::EscapeAsNecessary)
void renameField (const TQString &oldName, const TQString &newName)
void renameField (KexiDB::Field *field, const TQString &newName)
Public Member Functions inherited from KexiDB::SchemaData
 SchemaData (int obj_type=KexiDB::UnknownObjectType)
int type () const
int id () const
TQString name () const
TQString objectName () const
void setName (const TQString &n)
TQString caption () const
void setCaption (const TQString &c)
TQString description () const
void setDescription (const TQString &desc)
virtual TQString schemaDataDebugString () const
virtual bool isNative () const
virtual void setNative (bool set)

Static Public Member Functions

static TQString sqlColumnsList (QueryColumnInfo::List *infolist, Driver *driver)
Static Public Member Functions inherited from KexiDB::FieldList
static TQString sqlFieldsList (Field::List *list, Driver *driver, const TQString &separator=TQString::fromLatin1(","), const TQString &tableAlias=TQString(), int drvEscaping=Driver::EscapeDriver|Driver::EscapeAsNecessary)

Protected Member Functions

void init ()
void computeFieldsExpanded ()
Protected Member Functions inherited from KexiDB::SchemaData
void clear ()

Protected Attributes

QuerySchemaPrivate * d
Protected Attributes inherited from KexiDB::FieldList
Field::List m_fields
TQDict< Field > m_fields_by_name
Field::List * m_autoinc_fields
Protected Attributes inherited from KexiDB::SchemaData
int m_type
int m_id
TQString m_name
TQString m_caption
TQString m_desc
bool m_native: 1

Friends

class Connection
class QuerySchemaPrivate

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 225 of file queryschema.h.

Member Enumeration Documentation

◆ ColumnsOrderOptions

Options used in columnsOrder().

Enumerator
UnexpandedList 

A map for unexpanded list is created.

UnexpandedListWithoutAsterisks 

A map for unexpanded list is created, with asterisks skipped.

ExpandedList 

A map for expanded list is created.

Definition at line 600 of file queryschema.h.

◆ FieldsExpandedOptions

Options used in fieldsExpanded().

Enumerator
Default 

All fields are returned even if duplicated.

Unique 

Unique list of fields is returned.

WithInternalFields 

Like Default but internal fields (for lookup) are appended.

WithInternalFieldsAndRowID 

Like WithInternalFields but RowID (big int type) field is appended after internal fields

Definition at line 539 of file queryschema.h.

Constructor & Destructor Documentation

◆ QuerySchema() [1/3]

QuerySchema::QuerySchema ( )

Creates empty query object (without columns).

Definition at line 555 of file queryschema.cpp.

◆ QuerySchema() [2/3]

QuerySchema::QuerySchema ( TableSchema & tableSchema)

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 by 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 563 of file queryschema.cpp.

◆ QuerySchema() [3/3]

QuerySchema::QuerySchema ( const QuerySchema & querySchema)

Copy constructor. Creates deep copy of querySchema. QueryAsterisk objects are deeply copied while only pointers to Field objects are copied.

Definition at line 591 of file queryschema.cpp.

◆ ~QuerySchema()

QuerySchema::~QuerySchema ( )
virtual

Definition at line 610 of file queryschema.cpp.

Member Function Documentation

◆ addAsterisk()

FieldList & QuerySchema::addAsterisk ( QueryAsterisk * asterisk,
bool visible = true )

Adds asterisk at the and of columns list.

Definition at line 760 of file queryschema.cpp.

◆ addExpression()

FieldList & QuerySchema::addExpression ( BaseExpr * expr,
bool visible = true )

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 744 of file queryschema.cpp.

◆ addField() [1/2]

KexiDB::FieldList & QuerySchema::addField ( KexiDB::Field * field,
bool visible = true )

Adds field to the columns list. If visible is true (the default), the field will be visible.

See also
insertField()

Definition at line 721 of file queryschema.cpp.

◆ addField() [2/2]

KexiDB::FieldList & QuerySchema::addField ( KexiDB::Field * field,
int bindToTable,
bool visible = true )

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.

See also
insertField()
tableBoundToColumn(uint columnPosition)

Definition at line 726 of file queryschema.cpp.

◆ addRelationship()

Relationship * QuerySchema::addRelationship ( Field * field1,
Field * field2 )

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 1613 of file queryschema.cpp.

◆ addTable()

void QuerySchema::addTable ( TableSchema * table,
const TQCString & alias = TQCString() )

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 911 of file queryschema.cpp.

◆ addToWhereExpression()

void QuerySchema::addToWhereExpression ( KexiDB::Field * field,
const TQVariant & value,
int relation = '=' )

Adds a part to WHERE expression. Simplifies creating of WHERE expression, if used instead of setWhereExpression(BaseExpr *expr).

Todo
date, time

Definition at line 1683 of file queryschema.cpp.

◆ asterisks()

Field::List * QuerySchema::asterisks ( ) const
Returns
list of QueryAsterisk objects defined for this query

Definition at line 1094 of file queryschema.cpp.

◆ autoIncrementFields()

QueryColumnInfo::List * QuerySchema::autoIncrementFields ( )
Returns
a list of field infos for all auto-incremented fields from master table of this query. This result is cached for efficiency. fieldsExpanded() is used for that.

Definition at line 1626 of file queryschema.cpp.

◆ autoIncrementSQLFieldsList()

TQString QuerySchema::autoIncrementSQLFieldsList ( Driver * driver)
Returns
cached sql list created using sqlColumnsList() on a list returned by autoIncrementFields().

Definition at line 1666 of file queryschema.cpp.

◆ clear()

void QuerySchema::clear ( )
virtual

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.

See also
FieldList::clear()

Reimplemented from KexiDB::FieldList.

Definition at line 621 of file queryschema.cpp.

◆ columnAlias()

TQCString QuerySchema::columnAlias ( uint position) const
Returns
alias of a column at position or null string If there is no alias for this column or if there is no such column within the query defined. If the column is an expression and has no alias defined, a new unique alias will be generated automatically on this call.

Definition at line 988 of file queryschema.cpp.

◆ columnInfo()

QueryColumnInfo * QuerySchema::columnInfo ( const TQString & identifier,
bool expanded = true )

Like QuerySchema::field(const TQString& name) but returns not only Field object for identifier but entire QueryColumnInfo object. identifier can be:

  • a fieldname
  • an aliasname
  • a tablename.fieldname
  • a tablename.aliasname Note that if there are two occurrrences of the same name, only the first is accessible using this method. For instance, calling columnInfo("name") for "SELECT t1.name, t2.name FROM t1, t2" statement will only return the column related to t1.name and not t2.name, so you'll need to explicitly specify "t2.name" as the identifier to get the second column.

Definition at line 1115 of file queryschema.cpp.

◆ columnPositionForAlias()

int QuerySchema::columnPositionForAlias ( const TQCString & name) const
Returns
column position that has defined alias name. If there is no such alias, -1 is returned.

Definition at line 1058 of file queryschema.cpp.

◆ columnsOrder()

TQMap< QueryColumnInfo *, int > QuerySchema::columnsOrder ( ColumnsOrderOptions options = ExpandedList)
Returns
a map for fast lookup of query columns' order.
  • If options is UnexpandedList, each QueryColumnInfo pointer is mapped to the index within (unexpanded) list of fields, i.e. "*" or "table.*" asterisks are considered to be single items.
  • If options is UnexpandedListWithoutAsterisks, each QueryColumnInfo pointer is mapped to the index within (unexpanded) list of columns that come from asterisks like "*" or "table.*" are not included in the map at all.
  • If options is ExpandedList (the default) this method provides is exactly opposite information compared to vector returned by fieldsExpanded().

This method's result is cached by the QuerySchema object. Note: indices of internal fields (see internalFields()) are also returned here - in this case the index is counted as a sum of size(e) + i (where "e" is the list of expanded fields and i is the column index within internal fields list). This feature is used eg. at the end of Connection::updateRow() where need indices of fields (including internal) to update all the values in memory.

Example use: let t be table (int id, name text, surname text) and q be query defined by a statement "select * from t".

  • columnsOrder(ExpandedList) will return the following map: QueryColumnInfo(id)->0, QueryColumnInfo(name)->1, QueryColumnInfo(surname)->2.
  • columnsOrder(UnexpandedList) will return the following map: QueryColumnInfo(id)->0, QueryColumnInfo(name)->0, QueryColumnInfo(surname)->0 because the column list is not expanded. This way you can use the returned index to get Field* pointer using field(uint) method of FieldList superclass.
  • columnsOrder(UnexpandedListWithoutAsterisks) will return the following map: QueryColumnInfo(id)->0,

Definition at line 1560 of file queryschema.cpp.

◆ computeFieldsExpanded()

void QuerySchema::computeFieldsExpanded ( )
protected
Todo
(js): perhaps not all fields should be appended here
Todo
QuerySchema itself will also support lookup fields...

Definition at line 1198 of file queryschema.cpp.

◆ connection()

Connection * QuerySchema::connection ( ) const

If query was created using a connection, returns this connection object, otherwise NULL.

Definition at line 770 of file queryschema.cpp.

◆ contains()

bool QuerySchema::contains ( TableSchema * table) const
Returns
true if the query uses table.

Definition at line 963 of file queryschema.cpp.

◆ debugString()

TQString QuerySchema::debugString ( )
virtual
Returns
string for debugging purposes.

Reimplemented from KexiDB::FieldList.

Definition at line 776 of file queryschema.cpp.

◆ expandedOrInternalField()

QueryColumnInfo * QuerySchema::expandedOrInternalField ( uint index)
Returns
info for expanded of internal field at index index. The returned field can be either logical or internal (for lookup), the latter case is true if index >= fieldsExpanded().count(). Equivalent of QuerySchema::fieldsExpanded(WithInternalFields).at(index).

Definition at line 1184 of file queryschema.cpp.

◆ field() [1/2]

Field * QuerySchema::field ( const TQString & name,
bool expanded = true )
virtual
Returns
field for identifier or 0 if no field for this name was found within the query. fieldsExpanded() method is used to lookup expanded list of the query fields, so queries with asterisks are processed well. If a field has alias defined, name is not taken into account, but only its alias. If a field has no alias:
  • field's name is checked
  • field's table and field's name are checked in a form of "tablename.fieldname", so you can provide identifier in this form to avoid ambiguity.

If there are more than one fields with the same name equal to identifier, first-found is returned (checking is performed from first to last query field). Structures needed to compute result of this method are cached, so only first usage costs o(n) - another usages cost o(1).

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.

  • Calling field("B") will return a pointer to third query column (not the first, because it is covered by "X" alias). Additionally, calling field("X") will return the same pointer.
  • Calling field("T.A") will return the same pointer as field("A").

Definition at line 1109 of file queryschema.cpp.

◆ field() [2/2]

Field * KexiDB::QuerySchema::field ( uint id)
inline
Returns
field id or NULL if there is no such a field.

Definition at line 522 of file queryschema.h.

◆ fieldsExpanded()

QueryColumnInfo::Vector QuerySchema::fieldsExpanded ( FieldsExpandedOptions options = Default)
Returns
fully expanded list of fields. QuerySchema::fields() returns vector of fields used for the query columns, but in a case when there are asterisks defined for the query, it does not expand QueryAsterisk objects to field lists but return every asterisk as-is. This could be inconvenient when you need just a fully expanded list of fields, so this method does the work for you.

If options is Unique, each field is returned in the vector only once (first found field is selected). Note however, that the same field can be returned more than once if it has attached a different alias. For example, let t be TABLE( a, b ) and let query be defined by "SELECT *, a AS alfa FROM t" statement. Both fieldsExpanded(Default) and fieldsExpanded(Unique) will return [ a, b, a (alfa) ] list. On the other hand, for query defined by "SELECT *, a FROM t" statement, fieldsExpanded(Default) will return [ a, b, a ] list while fieldsExpanded(Unique) will return [ a, b ] list.

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.

Todo
js: UPDATE CACHE!

Definition at line 1121 of file queryschema.cpp.

◆ findTableField()

Field * QuerySchema::findTableField ( const TQString & tableOrTableAndFieldName) const

Convenience function.

Returns
table field by searching through all tables in this query. The field does not need to be included on the list of query columns. Similarly, query aliases are not taken into account.

tableOrTableAndFieldName string may contain table name and field name with '.' character between them, e.g. "mytable.myfield". This is recommended way to avoid ambiguity. 0 is returned if the query has no such table defined of the table has no such field defined. If you do not provide a table name, the first field found is returned.

QuerySchema::table("mytable")->field("myfield") could be alternative for findTableField("mytable.myfield") but it can crash if "mytable" is not defined in the query.

See also
KexiDB::splitToTableAndFieldParts()

Definition at line 968 of file queryschema.cpp.

◆ hasColumnAlias()

bool QuerySchema::hasColumnAlias ( uint position) const

Provided for convenience.

Returns
true if a column at position has non empty alias defined within the query. If there is no alias for this column, or if there is no such column in the query defined, false is returned.

Definition at line 994 of file queryschema.cpp.

◆ hasTableAlias()

bool QuerySchema::hasTableAlias ( uint position) const

Provided for convenience.

Returns
true if a table at position (within FROM section of the the query) has non empty alias defined. If there is no alias for this table, or if there is no such table in the query defined, false is returned.

Definition at line 1053 of file queryschema.cpp.

◆ init()

void QuerySchema::init ( )
protected

Definition at line 615 of file queryschema.cpp.

◆ insertField() [1/3]

FieldList & QuerySchema::insertField ( uint position,
Field * field )
virtual

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.

Reimplemented from KexiDB::FieldList.

Definition at line 634 of file queryschema.cpp.

◆ insertField() [2/3]

FieldList & QuerySchema::insertField ( uint position,
Field * field,
bool visible )

Definition at line 628 of file queryschema.cpp.

◆ insertField() [3/3]

FieldList & QuerySchema::insertField ( uint position,
Field * field,
int bindToTable,
bool visible = true )

Definition at line 639 of file queryschema.cpp.

◆ internalFields()

QueryColumnInfo::Vector QuerySchema::internalFields ( )
Returns
list of fields internal fields used for lookup columns.

Definition at line 1178 of file queryschema.cpp.

◆ isColumnVisible()

bool QuerySchema::isColumnVisible ( uint position) const
Returns
visibility flag for column at position. By default column is visible.

Definition at line 749 of file queryschema.cpp.

◆ masterTable()

TableSchema * QuerySchema::masterTable ( ) const
Returns
table that is master to this query. All potentially-editable columns within this query belong just to this table. This method also can return NULL if there are no tables at all, or if previously assigned master table schema has been removed with removeTable(). Every query that has at least one table defined, should have assigned a master table. If no master table is assigned explicitym but this method there is only one table used for this query even if there are table aliases, a single table is returned here. (e.g. "T" table is returned for "SELECT T1.A, T2.B FROM T T1, T T2" statement).

Definition at line 880 of file queryschema.cpp.

◆ orderByColumnList()

OrderByColumnList & QuerySchema::orderByColumnList ( ) const
Returns
a list of columns listed in ORDER BY section of the query. Read notes for setOrderByColumnList().

Definition at line 1745 of file queryschema.cpp.

◆ parameters()

QuerySchemaParameterList QuerySchema::parameters ( )
Returns
query schema parameters. These are taked from the WHERE section (a tree of expression items).

Definition at line 1750 of file queryschema.cpp.

◆ pkeyFieldsCount()

uint QuerySchema::pkeyFieldsCount ( )
Returns
number of master table's primary key fields included in this query. This method is useful to quickly check whether the vector returned by pkeyFieldsOrder() if filled completely.

User e.g. in Connection::updateRow() to check if entire primary key information is specified.

Examples: let table T has (ID1 INTEGER, ID2 INTEGER, A INTEGER) fields, and let (ID1, ID2) is T's primary key.

  1. The query defined by "SELECT * FROM T" statement contains all T's primary key's fields as T is the master table, and thus pkeyFieldsCount() will return 2 (both primary key's fields are in the fieldsExpanded() list), and pkeyFieldsOrder() will return vector {0, 1}.
  2. The query defined by "SELECT A, ID2 FROM T" statement, and thus pkeyFieldsCount() will return 1 (only one primary key's field is in the fieldsExpanded() list), and pkeyFieldsOrder() will return vector {-1, 1}, as second primary key's field is at position #1 and first field is not specified at all within the query.

Definition at line 1607 of file queryschema.cpp.

◆ pkeyFieldsOrder()

TQValueVector< int > QuerySchema::pkeyFieldsOrder ( )
Returns
table describing order of primary key (PKEY) fields within the query. Indexing is performed against vector returned by fieldsExpanded(). It is usable for e.g. Conenction::updateRow(), when we need to locate each primary key's field in a constant time.

Returned vector is owned and cached by QuerySchema object. When you assign it, it is implicity shared. Its size is equal to number of primary key fields defined for master table (masterTable()->primaryKey()->fieldCount()).

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.

See also
example for pkeyFieldsCount().
Todo
js: UPDATE CACHE!

Definition at line 1571 of file queryschema.cpp.

◆ relationships()

Relationship::List * QuerySchema::relationships ( ) const
Returns
a list of relationships defined for this query

Definition at line 1089 of file queryschema.cpp.

◆ removeField()

void QuerySchema::removeField ( KexiDB::Field * field)
virtual

Removes field from the columns list. Use with care.

Reimplemented from KexiDB::FieldList.

Definition at line 732 of file queryschema.cpp.

◆ removeTable()

void QuerySchema::removeTable ( TableSchema * table)

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 943 of file queryschema.cpp.

◆ setColumnAlias()

void QuerySchema::setColumnAlias ( uint position,
const TQCString & alias )

Sets alias for a column at position, within the query. Passing empty string to alias clears alias for a given column.

Definition at line 999 of file queryschema.cpp.

◆ setColumnVisible()

void QuerySchema::setColumnVisible ( uint position,
bool v )

Sets visibility flag for column at position to v.

Definition at line 754 of file queryschema.cpp.

◆ setMasterTable()

void QuerySchema::setMasterTable ( TableSchema * table)

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.

See also
masterTable()

Definition at line 900 of file queryschema.cpp.

◆ setOrderByColumnList()

void QuerySchema::setOrderByColumnList ( const OrderByColumnList & list)

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 1739 of file queryschema.cpp.

◆ setStatement()

void QuerySchema::setStatement ( const TQString & s)

Forces a query statement (i.e. no statement is composed from QuerySchema's content)

Definition at line 1104 of file queryschema.cpp.

◆ setTableAlias()

void QuerySchema::setTableAlias ( uint position,
const TQCString & alias )

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 1066 of file queryschema.cpp.

◆ setWhereExpression()

void QuerySchema::setWhereExpression ( BaseExpr * expr)

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 1677 of file queryschema.cpp.

◆ sqlColumnsList()

TQString QuerySchema::sqlColumnsList ( QueryColumnInfo::List * infolist,
Driver * driver )
static
Returns
a string that is a result of concatenating all column names for infolist, with "," between each one. This is usable e.g. as argument like "field1,field2" for "INSERT INTO (xxx) ..". The result of this method is effectively cached, and it is invalidated when set of fields changes (e.g. using clear() or addField()).

This method is similar to FieldList::sqlFieldsList() it just uses QueryColumnInfo::List instead of Field::List.

Definition at line 1648 of file queryschema.cpp.

◆ statement()

TQString QuerySchema::statement ( ) const
Returns
a preset statement (if any).

Definition at line 1099 of file queryschema.cpp.

◆ table()

TableSchema * QuerySchema::table ( const TQString & tableName) const
Returns
table with name tableName or 0 if this query has no such table.

Definition at line 953 of file queryschema.cpp.

◆ tableAlias()

TQCString QuerySchema::tableAlias ( uint position) const
Returns
alias of a table at position (within FROM section) or null string if there is no alias for this table or if there is no such table within the query defined.

Definition at line 1016 of file queryschema.cpp.

◆ tableBoundToColumn()

int QuerySchema::tableBoundToColumn ( uint columnPosition) const
Returns
a table position (within FROM section), that is bound to column at columnPosition (within SELECT section). This information can be used to find if there is alias defined for a table that is referenced by a given column.

For example, for "SELECT t2.id FROM table1 t1, table2 t2" query statement, columnBoundToTable(0) returns 1, what means that table at position 1 (within FROM section) is bound to column at position 0, so we can now call tableAlias(1) to see if we have used alias for this column (t2.d) or just a table name (table2.d).

These checkings are performed e.g. by Connection::queryStatement() to construct a statement string maximally identical to originally defined query statement.

-1 is returned if:

  • columnPosition is out of range (i.e. < 0 or >= fieldCount())
  • a column at columnPosition is not bound to any table (i.e. no database field is used for this column, e.g. "1" constant for "SELECT 1 from table" query statement)

Definition at line 711 of file queryschema.cpp.

◆ tablePosition()

int QuerySchema::tablePosition ( const TQString & tableName) const
Returns
table position (within FROM section) for tableName. -1 is returend if there's no such table declared in the FROM section.
See also
tablePositions()

Definition at line 1030 of file queryschema.cpp.

◆ tablePositionForAlias()

int QuerySchema::tablePositionForAlias ( const TQCString & name) const
Returns
table position (within FROM section) that has attached alias name. If there is no such alias, -1 is returned. Only first table's position attached for this alias is returned. It is not especially bad, since aliases rarely can be duplicated, what leads to ambiguity. Duplicated aliases are only allowed for trivial queries that have no database fields used within their columns, e.g. "SELECT 1 from table1 t, table2 t" is ok but "SELECT t.id from table1 t, table2 t" is not.

Definition at line 1022 of file queryschema.cpp.

◆ tablePositions()

TQValueList< int > QuerySchema::tablePositions ( const TQString & tableName) const
Returns
a list of all tableName table occurrences (within FROM section). E.g. for "SELECT * FROM table t, table t2" [0, 1] list is returned. Empty list is returned there's no such table declared in the FROM section at all.
See also
tablePosition()

Definition at line 1040 of file queryschema.cpp.

◆ tables()

TableSchema::List * QuerySchema::tables ( ) const
Returns
list of tables used in a query. This also includes master table.
See also
masterTable()

Definition at line 906 of file queryschema.cpp.

◆ whereExpression()

BaseExpr * QuerySchema::whereExpression ( ) const
Returns
WHERE expression or 0 if this query has no WHERE expression

Definition at line 1734 of file queryschema.cpp.

◆ Connection

friend class Connection
friend

Definition at line 751 of file queryschema.h.

◆ QuerySchemaPrivate

friend class QuerySchemaPrivate
friend

Definition at line 752 of file queryschema.h.

Member Data Documentation

◆ d

QuerySchemaPrivate* KexiDB::QuerySchema::d
protected

Definition at line 749 of file queryschema.h.


The documentation for this class was generated from the following files: