KexiDB::Connection Class Reference
#include <connection.h>
Inheritance diagram for KexiDB::Connection:

Detailed Description
Provides database connection, allowing queries and data modification.This class represents a database connection established within a data source. It supports data queries and modification by creating client-side database cursors. Database transactions are supported.
Definition at line 61 of file connection.h.
Public Member Functions | |
| virtual | ~Connection () |
| ConnectionData * | data () const |
| Driver * | driver () const |
| bool | connect () |
| Connects to driver with given parameters. | |
| bool | isConnected () const |
| bool | isDatabaseUsed () const |
| virtual bool | isReadOnly () const |
| virtual void | clearError () |
| bool | disconnect () |
| Disconnects from driver with given parameters. | |
| QStringList | databaseNames (bool also_system_db=false) |
| bool | databaseExists (const QString &dbName, bool ignoreErrors=true) |
| bool | createDatabase (const QString &dbName) |
| Creates new database with name dbName, using this connection. | |
| bool | useDatabase (const QString &dbName, bool kexiCompatible=true, bool *cancelled=0, MessageHandler *msgHandler=0) |
| Opens an existing database specified by dbName. | |
| bool | closeDatabase () |
| Closes currently used database for this connection. | |
| QString | currentDatabase () const |
| Get the name of the current database. | |
| bool | dropDatabase (const QString &dbName=QString::null) |
| Drops database with name dbName. | |
| QStringList | objectNames (int objType=KexiDB::AnyObjectType, bool *ok=0) |
| QStringList | tableNames (bool also_system_tables=false) |
| KexiDB::ServerVersionInfo * | serverVersion () const |
| KexiDB::DatabaseVersionInfo * | databaseVersion () const |
| DatabaseProperties & | databaseProperties () |
| QValueList< int > | tableIds () |
| QValueList< int > | queryIds () |
| QValueList< int > | objectIds (int objType) |
| Transaction | beginTransaction () |
| Creates new transaction handle and starts a new transaction. | |
| bool | commitTransaction (Transaction trans=Transaction::null, bool ignore_inactive=false) |
| bool | rollbackTransaction (Transaction trans=Transaction::null, bool ignore_inactive=false) |
| Transaction & | defaultTransaction () const |
| void | setDefaultTransaction (const Transaction &trans) |
| const QValueList< Transaction > & | transactions () |
| bool | autoCommit () const |
| bool | setAutoCommit (bool on) |
| virtual Cursor * | prepareQuery (const QString &statement, uint cursor_options=0)=0 |
| Cursor * | prepareQuery (QuerySchema &query, const QValueList< QVariant > ¶ms, uint cursor_options=0) |
| virtual Cursor * | prepareQuery (QuerySchema &query, uint cursor_options=0)=0 |
| Cursor * | prepareQuery (TableSchema &table, uint cursor_options=0) |
| Cursor * | executeQuery (const QString &statement, uint cursor_options=0) |
| Cursor * | executeQuery (QuerySchema &query, const QValueList< QVariant > ¶ms, uint cursor_options=0) |
| Cursor * | executeQuery (QuerySchema &query, uint cursor_options=0) |
| Cursor * | executeQuery (TableSchema &table, uint cursor_options=0) |
| bool | deleteCursor (Cursor *cursor) |
| TableSchema * | tableSchema (int tableId) |
| TableSchema * | tableSchema (const QString &tableName) |
| QuerySchema * | querySchema (int queryId) |
| QuerySchema * | querySchema (const QString &queryName) |
| bool | setQuerySchemaObsolete (const QString &queryName) |
| tristate | querySingleRecord (const QString &sql, RowData &data, bool addLimitTo1=true) |
| tristate | querySingleRecord (QuerySchema &query, RowData &data, bool addLimitTo1=true) |
| tristate | querySingleString (const QString &sql, QString &value, uint column=0, bool addLimitTo1=true) |
| tristate | querySingleNumber (const QString &sql, int &number, uint column=0, bool addLimitTo1=true) |
| bool | queryStringList (const QString &sql, QStringList &list, uint column=0) |
| bool | resultExists (const QString &sql, bool &success, bool addLimitTo1=true) |
| bool | isEmpty (TableSchema &table, bool &success) |
| int | resultCount (const QString &sql) |
| bool | insertRecord (TableSchema &tableSchema, QValueList< QVariant > &values) |
| bool | insertRecord (FieldList &fields, QValueList< QVariant > &values) |
| bool | createTable (TableSchema *tableSchema, bool replaceExisting=false) |
| Creates a table according to the given schema. | |
| tristate | dropTable (TableSchema *tableSchema) |
| Drops a table corresponding to the name in the given schema. | |
| tristate | dropTable (const QString &table) |
| tristate | alterTable (TableSchema &tableSchema, TableSchema &newTableSchema) |
| bool | alterTableName (TableSchema &tableSchema, const QString &newName, bool replace=false) |
| bool | dropQuery (QuerySchema *querySchema) |
| bool | dropQuery (const QString &query) |
| bool | removeObject (uint objId) |
| Field * | findSystemFieldName (FieldList *fieldlist) |
| virtual QString | anyAvailableDatabaseName () |
| void | setAvailableDatabaseName (const QString &dbName) |
| bool | useTemporaryDatabaseIfNeeded (QString &tmpdbName) |
| Q_ULLONG | lastInsertedAutoIncValue (const QString &aiFieldName, const QString &tableName, Q_ULLONG *ROWID=0) |
| Q_ULLONG | lastInsertedAutoIncValue (const QString &aiFieldName, const TableSchema &table, Q_ULLONG *ROWID=0) |
| bool | executeSQL (const QString &statement) |
| QString | selectStatement (QuerySchema &querySchema, const QValueList< QVariant > ¶ms, const SelectStatementOptions &options=SelectStatementOptions()) const |
| QString | selectStatement (QuerySchema &querySchema, const SelectStatementOptions &options=SelectStatementOptions()) const |
| bool | storeObjectSchemaData (SchemaData &sdata, bool newObject) |
| tristate | loadObjectSchemaData (int objectID, SchemaData &sdata) |
| tristate | loadObjectSchemaData (int objectType, const QString &objectName, SchemaData &sdata) |
| tristate | loadDataBlock (int objectID, QString &dataString, const QString &dataID) |
| bool | storeDataBlock (int objectID, const QString &dataString, const QString &dataID=QString::null) |
| bool | removeDataBlock (int objectID, const QString &dataID=QString::null) |
| void | registerForTableSchemaChanges (TableSchemaChangeListenerInterface &listener, TableSchema &schema) |
| Register listener for receiving (listening) information about changes in TableSchema object. | |
| void | unregisterForTableSchemaChanges (TableSchemaChangeListenerInterface &listener, TableSchema &schema) |
| void | unregisterForTablesSchemaChanges (TableSchemaChangeListenerInterface &listener) |
| QPtrList< Connection::TableSchemaChangeListenerInterface > * | tableSchemaChangeListeners (TableSchema &tableSchema) const |
| tristate | closeAllTableSchemaChangeListeners (TableSchema &tableSchema) |
| void | removeTableSchemaInternal (KexiDB::TableSchema *tableSchema) |
| void | insertInternalTableSchema (TableSchema *tableSchema) |
| virtual bool | drv_containsTable (const QString &tableName)=0 |
| virtual bool | drv_createTable (const TableSchema &tableSchema) |
| virtual bool | drv_alterTableName (TableSchema &tableSchema, const QString &newName) |
| virtual bool | drv_dropTable (const QString &name) |
| virtual PreparedStatement::Ptr | prepareStatement (PreparedStatement::StatementType type, FieldList &fields)=0 |
| bool | isInternalTableSchema (const QString &tableName) |
| bool | setupObjectSchemaData (const RowData &data, SchemaData &sdata) |
| KexiDB::Field * | setupField (const RowData &data) |
Static Public Member Functions | |
| static const QStringList & | kexiDBSystemTableNames () |
Public Attributes | |
| H_INS_REC_ALL | |
Protected Member Functions | |
| Connection (Driver *driver, ConnectionData &conn_data) | |
| void | destroy () |
| tristate | dropTable (KexiDB::TableSchema *tableSchema, bool alsoRemoveSchema) |
| virtual bool | drv_connect (KexiDB::ServerVersionInfo &version)=0 |
| virtual bool | drv_disconnect ()=0 |
| virtual bool | drv_executeSQL (const QString &statement)=0 |
| virtual bool | drv_getDatabasesList (QStringList &list) |
| virtual bool | drv_getTablesList (QStringList &list)=0 |
| virtual bool | drv_databaseExists (const QString &dbName, bool ignoreErrors=true) |
| virtual bool | drv_createDatabase (const QString &dbName=QString::null)=0 |
| virtual bool | drv_useDatabase (const QString &dbName=QString::null, bool *cancelled=0, MessageHandler *msgHandler=0)=0 |
| virtual bool | drv_closeDatabase ()=0 |
| virtual bool | drv_isDatabaseUsed () const |
| virtual bool | drv_dropDatabase (const QString &dbName=QString::null)=0 |
| QString | createTableStatement (const TableSchema &tableSchema) const |
| QString | selectStatement (TableSchema &tableSchema, const SelectStatementOptions &options=SelectStatementOptions()) const |
| virtual bool | drv_createTable (const QString &tableSchemaName) |
| virtual Q_ULLONG | drv_lastInsertRowID ()=0 |
| virtual TransactionData * | drv_beginTransaction () |
| virtual bool | drv_commitTransaction (TransactionData *trans) |
| virtual bool | drv_rollbackTransaction (TransactionData *trans) |
| virtual bool | drv_setAutoCommit (bool on) |
| bool | beginAutoCommitTransaction (TransactionGuard &tg) |
| bool | commitAutoCommitTransaction (const Transaction &trans) |
| bool | rollbackAutoCommitTransaction (const Transaction &trans) |
| bool | checkConnected () |
| bool | checkIsDatabaseUsed () |
| TableSchema * | setupTableSchema (const RowData &data) |
| QuerySchema * | setupQuerySchema (const RowData &data) |
| bool | updateRow (QuerySchema &query, RowData &data, RowEditBuffer &buf, bool useROWID=false) |
| bool | insertRow (QuerySchema &query, RowData &data, RowEditBuffer &buf, bool getROWID=false) |
| bool | deleteRow (QuerySchema &query, RowData &data, bool useROWID=false) |
| bool | deleteAllRows (QuerySchema &query) |
| bool | setupKexiDBSystemSchema () |
| Creates kexi__* tables. | |
| TableSchema * | newKexiDBSystemTableSchema (const QString &tsname) |
| QString | escapeIdentifier (const QString &id, int drvEscaping=Driver::EscapeDriver|Driver::EscapeAsNecessary) const |
| Identifier escaping function in the associated Driver. | |
| void | removeMe (TableSchema *ts) |
| bool | checkIfColumnExists (Cursor *cursor, uint column) |
| tristate | querySingleRecordInternal (RowData &data, const QString *sql, QuerySchema *query, bool addLimitTo1=true) |
| void | setReadOnly (bool set) |
| bool | loadExtendedTableSchemaData (TableSchema &tableSchema) |
| bool | storeExtendedTableSchemaData (TableSchema &tableSchema) |
| bool | storeMainFieldSchema (Field *field) |
| virtual tristate | drv_changeFieldProperty (TableSchema &table, Field &field, const QString &propertyName, const QVariant &value) |
Protected Attributes | |
| QPtrDict< KexiDB::Cursor > | m_cursors |
| cursors created for this connection | |
Friends | |
| class | KexiDB::Driver |
| class | KexiDB::Cursor |
| class | KexiDB::TableSchema |
| for removeMe() | |
| class | KexiDB::DatabaseProperties |
| for setError() | |
| class | ConnectionPrivate |
| class | KexiDB::AlterTableHandler |
Classes | |
| class | SelectStatementOptions |
| options used in selectStatement() More... | |
| class | TableSchemaChangeListenerInterface |
Constructor & Destructor Documentation
|
|
Opened connection is automatically disconnected and removed from driver's connections list. Note for driver developers: you should call destroy() from you Connection's subclass destructor. Definition at line 221 of file connection.cpp. |
|
||||||||||||
|
Used by Driver Definition at line 198 of file connection.cpp. References m_cursors, and KexiDB::Object::m_sql. |
Member Function Documentation
|
||||||||||||
|
Definition at line 1659 of file connection.cpp. References clearError(), closeAllTableSchemaChangeListeners(), createTable(), ERR_OBJECT_THE_SAME, isEmpty(), KexiDB::SchemaData::name(), and KexiDB::Object::setError(). Referenced by KexiTableDesignerView::storeData(). |
|
||||||||||||||||
|
Alters name of table described by tableSchema to newName. If replace is true, destination table is completely dropped and replaced by tableSchema, if present. In this case, identifier of tableSchema becomes equal to the dropped table's id, what can be useful if tableSchema was created with a temporary name and ID (used in AlterTableHandler). If replace is false (the default) and destination table is present -- false is returned and ERR_OBJECT_EXISTS error is set. The schema of tableSchema is updated on success.
Definition at line 1685 of file connection.cpp. References alterTableName_ERR, beginAutoCommitTransaction(), clearError(), commitAutoCommitTransaction(), dropTable(), drv_alterTableName(), ERR_INVALID_IDENTIFIER, ERR_OBJECT_EXISTS, ERR_OBJECT_NOT_FOUND, ERR_OBJECT_THE_SAME, KexiDB::Driver::escapeString(), executeSQL(), KexiDB::SchemaData::id(), KexiUtils::isIdentifier(), KexiDB::SchemaData::m_id, KexiDB::SchemaData::name(), KexiDB::Object::setError(), KexiDB::SchemaData::setName(), KexiDB::TableObjectType, tableSchema(), and KexiDB::TransactionGuard::transaction(). Referenced by KexiTablePart::rename(). |
|
|
Note for driver developers: return here a name of database which you are sure is existing. Default implementation returns:
See decription of DriverBehaviour::ALWAYS_AVAILABLE_DATABASE_NAME member. You may want to reimplement this method only when you need to depend on this connection specifics (e.g. you need to check something remotely). Definition at line 3006 of file connection.cpp. References KexiDB::DriverBehaviour::ALWAYS_AVAILABLE_DATABASE_NAME, and KexiDB::Driver::beh. Referenced by useDatabase(), and useTemporaryDatabaseIfNeeded(). |
|
|
For drivers that do not support transactions (see Driver::features()) this method shouldn't be called because it does nothing ans always returns false. No internal KexiDB object should changes this option, although auto commit's behaviour depends on database engine's specifics. Engines that support only single transaction per connection (see Driver::SingleTransactions), use this single connection for autocommiting, so if there is already transaction started by the KexiDB user program (with beginTransaction()), this transaction is committed before any sql functional statement execution. In this situation default transaction is also affected (see defaultTransaction()). Only for drivers that support nested transactions (Driver::NestedTransactions), autocommiting works independently from previously started transaction, For other drivers set this option off if you need use transaction for grouping more statements together. NOTE: nested transactions are not yet implemented in KexiDB API. Definition at line 2058 of file connection.cpp. |
|
|
Internal, for handling autocommited transactions: begins transaction if one is supported.
Definition at line 1855 of file connection.cpp. References beginTransaction(), commitTransaction(), KexiDB::Driver::d, KexiDB::TransactionGuard::doNothing(), KexiDB::Object::error(), KexiDB::DriverPrivate::features, KexiDB::Driver::IgnoreTransactions, KexiDB::Driver::MultipleTransactions, KexiDB::TransactionGuard::setTransaction(), and KexiDB::Driver::SingleTransactions. Referenced by alterTableName(), createTable(), dropQuery(), and dropTable(). |
|
|
Creates new transaction handle and starts a new transaction.
Definition at line 1916 of file connection.cpp. References checkIsDatabaseUsed(), KexiDB::Driver::d, drv_beginTransaction(), ERR_TRANSACTION_ACTIVE, KexiDB::DriverPrivate::features, KexiDB::Driver::IgnoreTransactions, KexiDB::Transaction::m_data, KexiDB::Driver::MultipleTransactions, KexiDB::Transaction::null, SET_BEGIN_TR_ERROR, SET_ERR_TRANS_NOT_SUPP, KexiDB::Object::setError(), and KexiDB::Driver::SingleTransactions. Referenced by KexiCSVImportDialog::accept(), beginAutoCommitTransaction(), createDatabase(), and KexiMigration::KexiMigrate::performImport(). |
|
|
Helper: checks if connection is established; if not: error message is set up and false returned Definition at line 293 of file connection.cpp. References clearError(), ERR_NO_CONNECTION, and KexiDB::Object::setError(). Referenced by closeDatabase(), createDatabase(), databaseExists(), databaseNames(), dropDatabase(), and useDatabase(). |
|
||||||||||||
|
Definition at line 2300 of file connection.cpp. References ERR_CURSOR_RECORD_FETCHING, KexiDB::Cursor::fieldCount(), and KexiDB::Object::setError(). Referenced by querySingleString(), and queryStringList(). |
|
|
Helper: checks both if connection is established and database any is used; if not: error message is set up and false returned Definition at line 303 of file connection.cpp. References clearError(), ERR_NO_DB_USED, isDatabaseUsed(), and KexiDB::Object::setError(). Referenced by beginTransaction(), createTable(), objectIds(), and objectNames(). |
|
|
Reimplemented from Object: also clears sql string.
Reimplemented from KexiDB::Object. Definition at line 267 of file connection.cpp. References KexiDB::Object::clearError(), and KexiDB::Object::m_sql. Referenced by alterTable(), alterTableName(), checkConnected(), checkIsDatabaseUsed(), commitTransaction(), connect(), createTable(), databaseExists(), deleteAllRows(), deleteRow(), disconnect(), dropQuery(), dropTable(), KexiDB::SQLiteConnection::drv_useDatabase(), insertRow(), querySchema(), queryStringList(), removeObject(), rollbackTransaction(), and updateRow(). |
|
|
Definition at line 3401 of file connection.cpp. Referenced by alterTable(), KexiTablePart::askForClosingObjectsUsingTableSchema(), and dropTable(). |
|
|
Closes currently used database for this connection. Any active transactions (if supported) are rolled back, so commit these before closing, if you'd like to save your changes. Definition at line 623 of file connection.cpp. References checkConnected(), drv_closeDatabase(), KexiDBDbg, m_cursors, rollbackTransaction(), and KexiDB::Driver::transactionsSupported(). Referenced by createDatabase(), databaseExists(), databaseNames(), disconnect(), dropDatabase(), and useDatabase(). |
|
|
Internal, for handling autocommited transactions: Commits transaction prevoiusly started with beginAutoCommitTransaction().
Definition at line 1888 of file connection.cpp. References commitTransaction(), KexiDB::Driver::d, KexiDB::DriverPrivate::features, KexiDB::Driver::IgnoreTransactions, KexiDB::Transaction::isNull(), KexiDB::Driver::SingleTransactions, and KexiDB::Driver::transactionsSupported(). Referenced by alterTableName(), createTable(), dropQuery(), and dropTable(). |
|
||||||||||||
|
|
Connects to driver with given parameters.
Definition at line 245 of file connection.cpp. References clearError(), drv_connect(), ERR_ALREADY_CONNECTED, KexiDB::Driver::isFileDriver(), and KexiDB::Object::setError(). Referenced by KexiMigration::KexiMigrate::checkIfDestinationDatabaseOverwritingNeedsAccepting(), and KexiProjectSet::KexiProjectSet(). |
|
|
||||||||||||
|
Creates a table according to the given schema. Creates table defined by tableSchema. Schema information is also added into kexi system tables, for later reuse.
Note that on error:
Definition at line 1418 of file connection.cpp. References beginAutoCommitTransaction(), buildValuesForKexi__Fields(), checkIsDatabaseUsed(), clearError(), commitAutoCommitTransaction(), createFieldListForKexi__Fields(), createTable_ERR, KexiDB::deleteRow(), dropTable(), drv_createTable(), ERR_CANNOT_CREATE_EMPTY_OBJECT, ERR_OBJECT_EXISTS, ERR_SYSTEM_NAME_RESERVED, KexiDB::FieldList::fieldCount(), KexiDB::FieldList::fields(), findSystemFieldName(), KexiDB::SchemaData::id(), insertInternalTableSchema(), insertRecord(), KexiDB::Driver::isSystemObjectName(), KexiDB::TableSchema::m_conn, KexiDB::SchemaData::m_id, KexiDB::Field::name(), KexiDB::SchemaData::name(), removeTableSchemaInternal(), KexiDB::Object::setError(), storeExtendedTableSchemaData(), storeObjectSchemaData(), and KexiDB::TransactionGuard::transaction(). Referenced by KexiCSVImportDialog::accept(), alterTable(), KexiMigration::KexiMigrate::performImport(), and KexiTableDesignerView::storeNewData(). |
|
|
|
Get the name of the current database.
Definition at line 666 of file connection.cpp. |
|
|
Definition at line 240 of file connection.cpp. Referenced by KexiDB::MySqlConnection::drv_connect(), KexiDB::SQLiteConnection::drv_createDatabase(), KexiDB::SQLiteConnection::drv_dropDatabase(), KexiDB::SQLiteConnection::drv_getDatabasesList(), KexiDB::SQLiteConnection::drv_useDatabase(), KexiDB::pqxxSqlConnection::drv_useDatabase(), KexiProject::KexiProject(), loadObjectSchemaData(), querySchema(), and tableSchema(). |
|
||||||||||||
|
Definition at line 372 of file connection.cpp. References checkConnected(), clearError(), closeDatabase(), drv_databaseExists(), ERR_ACCESS_RIGHTS, ERR_OBJECT_NOT_FOUND, file, KexiDB::Driver::isFileDriver(), KexiDB::Object::setError(), and useTemporaryDatabaseIfNeeded(). Referenced by KexiMigration::KexiMigrate::checkIfDestinationDatabaseOverwritingNeedsAccepting(), createDatabase(), and useDatabase(). |
|
|
Definition at line 313 of file connection.cpp. References checkConnected(), closeDatabase(), drv_getDatabasesList(), KexiDB::Driver::isSystemDatabaseName(), KexiDBDbg, and useTemporaryDatabaseIfNeeded(). Referenced by drv_databaseExists(), and KexiProjectSet::KexiProjectSet(). |
|
|
Definition at line 831 of file connection.cpp. |
|
|
Definition at line 826 of file connection.cpp. References isDatabaseUsed(). |
|
|
Definition at line 2034 of file connection.cpp. |
|
|
Delete all existing rows. Definition at line 3338 of file connection.cpp. References clearError(), ERR_DELETE_SERVER_ERROR, escapeIdentifier(), executeSQL(), KexiDB::FieldList::fields(), KexiDBDbg, KexiDBWarn, KexiDB::Object::m_sql, KexiDB::QuerySchema::masterTable(), KexiDB::SchemaData::name(), KexiDB::TableSchema::primaryKey(), and KexiDB::Object::setError(). |
|
|
Deletes cursor cursor previously created by functions like executeQuery() for this connection. There is an attempt to close the cursor with Cursor::close() if it was opened. Anyway, at last cursor is deleted.
Definition at line 2149 of file connection.cpp. References KexiDBWarn. Referenced by KexiPart::Manager::checkProject(), KexiFormView::deleteQuery(), KexiDB::SQLiteConnection::drv_getTablesList(), KexiDB::pqxxSqlConnection::drv_getTablesList(), KexiDB::MySqlConnection::drv_getTablesList(), KexiSimplePrintingEngine::init(), objectIds(), objectNames(), querySingleRecordInternal(), querySingleString(), queryStringList(), resultExists(), setupTableSchema(), and KexiFormView::~KexiFormView(). |
|
||||||||||||||||
|
|
Method to be called form Connection's subclass destructor.
Definition at line 214 of file connection.cpp. References KexiDB::DriverPrivate::connections, KexiDB::Driver::d, and disconnect(). Referenced by KexiDB::MySqlConnection::~MySqlConnection(), KexiDB::pqxxSqlConnection::~pqxxSqlConnection(), and KexiDB::SQLiteConnection::~SQLiteConnection(). |
