KDbDriver
#include <KDbDriver.h>
Public Types | |
enum | Features { NoFeatures = 0 , SingleTransactions = 1 , MultipleTransactions = 2 , NestedTransactions = 4 , CursorForward = 8 , CursorBackward = (CursorForward + 16) , CompactingDatabaseSupported = 32 , IgnoreTransactions = 1024 } |
Public Types inherited from QObject | |
typedef | QObjectList |
Static Public Member Functions | |
static QString | defaultSqlTypeName (KDbField::Type type) |
static bool | isKDbSystemObjectName (const QString &name) |
Static Public Member Functions inherited from QObject | |
QMetaObject::Connection | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type) |
QMetaObject::Connection | connect (const QObject *sender, PointerToMemberFunction signal, Functor functor) |
bool | disconnect (const QMetaObject::Connection &connection) |
bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method) |
bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method) |
bool | disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method) |
QString | tr (const char *sourceText, const char *disambiguation, int n) |
Protected Member Functions | |
KDbDriver (QObject *parent, const QVariantList &args) | |
virtual KDbEscapedString | addLimitTo1 (const KDbEscapedString &sql, bool add=true) |
KDbDriverBehavior * | behavior () |
const KDbDriverBehavior * | behavior () const |
virtual KDbAdminTools * | drv_createAdminTools () const |
virtual KDbConnection * | drv_createConnection (const KDbConnectionData &connData, const KDbConnectionOptions &options)=0 |
virtual QByteArray | drv_escapeIdentifier (const QByteArray &str) const =0 |
virtual QString | drv_escapeIdentifier (const QString &str) const =0 |
virtual bool | drv_isSystemFieldName (const QString &name) const =0 |
void | initDriverSpecificKeywords (const char *const *keywords) |
virtual bool | isValid () |
KDbConnection * | removeConnection (KDbConnection *conn) |
void | setMetaData (const KDbDriverMetaData *metaData) |
virtual bool | supportsDefaultValue (const KDbField &field) const |
Protected Member Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signal) |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signal) |
bool | isSignalConnected (const QMetaMethod &signal) const const |
int | receivers (const char *signal) const const |
QObject * | sender () const const |
int | senderSignalIndex () const const |
virtual void | timerEvent (QTimerEvent *event) |
Protected Attributes | |
KDbDriverPrivate *const | d |
Protected Attributes inherited from KDbResultable | |
Private *const | d |
KDbResult | m_result |
Additional Inherited Members | |
Properties inherited from QObject | |
objectName | |
Detailed Description
Database driver's abstraction.
This class is a prototype of the database driver. KDbDriver allows new connections to be created, and groups as their parent. Before destruction, all owned connections are destructed.
Definition at line 49 of file KDbDriver.h.
Member Enumeration Documentation
◆ Features
enum KDbDriver::Features |
Features supported by driver (sum of few Features enum items).
Enumerator | |
---|---|
SingleTransactions | single trasactions are only supported |
MultipleTransactions | multiple concurrent trasactions are supported (this implies !SingleTransactions) |
NestedTransactions | nested trasactions are supported (this should imply !SingleTransactions and MultipleTransactions) |
CursorForward | forward moving is supported for cursors (if not available, no cursors available at all) |
CursorBackward | backward moving is supported for cursors (this implies CursorForward) |
CompactingDatabaseSupported | compacting database supported (aka VACUUM) |
IgnoreTransactions | If set, actions related to transactions will be silently bypassed with success. Set this if your driver does not support transactions at all Currently, this is only way to get it working with KDb. Keep in mind that this hack do not provide data integrity! This flag is currently used for MySQL driver. |
Definition at line 55 of file KDbDriver.h.
Constructor & Destructor Documentation
◆ ~KDbDriver()
|
override |
Definition at line 64 of file KDbDriver.cpp.
◆ KDbDriver()
|
protected |
Used by KDbDriverManager. Note for driver developers: Reimplement this. In your reimplementation you should initialize:
- beh->typeNames - to types accepted by your engine
- beh->features - to combination of selected values from Features enum
You may also want to change options in KDbDriverBehavior *beh member. See drivers/mySQL/mysqldriver.cpp for usage example.
Definition at line 56 of file KDbDriver.cpp.
Member Function Documentation
◆ addLimitTo1()
|
protectedvirtual |
- Returns
- SQL statement sql modified by appending a "LIMIT 1" clause, (if possible and if add is
true
). Used for optimization for the server side. Can be reimplemented for other drivers.
Definition at line 303 of file KDbDriver.cpp.
◆ adminTools()
KDbAdminTools & KDbDriver::adminTools | ( | ) | const |
- Returns
- admin tools object providing a number of database administration tools for the driver. Tools availablility varies from driver to driver. You can check it using features().
Definition at line 118 of file KDbDriver.cpp.
◆ behavior() [1/2]
|
protected |
Returns structure that provides detailed information about driver's default behavior.
- Since
- 3.1
Definition at line 74 of file KDbDriver.cpp.
◆ behavior() [2/2]
|
protected |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 79 of file KDbDriver.cpp.
◆ ceilingOrFloorFunctionToString()
|
virtual |
Generates native (driver-specific) CEILING() and FLOOR() function calls.
Default implementation USES CEILING() and FLOOR(), respectively. Special case is for SQLite.
Reimplemented in SqliteDriver.
Definition at line 373 of file KDbDriver.cpp.
◆ collationSql()
|
inlinevirtual |
- Returns
- SQL clause to add for unicode text collation sequence used in ORDER BY clauses of SQL statements generated by KDb. Later other clauses may use this statement. One space character should be be prepended. Can be reimplemented for other drivers, e.g. the SQLite3 driver returns " COLLATE ''". Default implementation returns empty string.
Reimplemented in SqliteDriver.
Definition at line 232 of file KDbDriver.h.
◆ concatenateFunctionToString()
KDbEscapedString KDbDriver::concatenateFunctionToString | ( | const KDbBinaryExpression & | args, |
KDbQuerySchemaParameterValueListIterator * | params, | ||
KDb::ExpressionCallStack * | callStack ) const |
Generates native (driver-specific) function call for concatenation of two strings.
Default implementation USES infix "||" operator. Special case is for MYSQL (CONCAT()).
- Todo
- API supporting KDbNArgExpression would be useful so instead of a||b||c can be expressed as CONCAT(a,b,c) instead of CONCAT(CONCAT(a,b),c). This requires changes to the KDbSQL parser.
Definition at line 390 of file KDbDriver.cpp.
◆ connections()
const QSet< KDbConnection * > KDbDriver::connections | ( | ) | const |
- Returns
- Set of created connections.
Definition at line 98 of file KDbDriver.cpp.
◆ createConnection() [1/2]
KDbConnection * KDbDriver::createConnection | ( | const KDbConnectionData & | connData | ) |
Definition at line 153 of file KDbDriver.cpp.
◆ createConnection() [2/2]
KDbConnection * KDbDriver::createConnection | ( | const KDbConnectionData & | connData, |
const KDbConnectionOptions & | options ) |
Creates connection using connData as parameters.
- Returns
nullptr
and sets error message on error. driverId member of connData will be updated with the driver's ID. options can be set for the new connection.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
- Todo
- needed? connData->setDriverId(id());
Definition at line 139 of file KDbDriver.cpp.
◆ dateTimeToSql() [1/2]
|
virtual |
Converts date/time value to string.
Default implementation uses dateTimeToSql(QVariant). Deprecated, use dateTimeToSql(QVariant).
Not compatible with all drivers - reimplement.
Definition at line 267 of file KDbDriver.cpp.
◆ dateTimeToSql() [2/2]
|
virtual |
Converts date/time value to string.
Default implementation uses KDb::dateTimeToIsoString().
Not compatible with all drivers - reimplement.
- Since
- 3.2.0
Definition at line 262 of file KDbDriver.cpp.
◆ dateToSql()
|
virtual |
Converts date value to string.
Default implementation uses KDb::dateToSql().
Not compatible with all drivers - reimplement.
- Since
- 3.2.0
Definition at line 252 of file KDbDriver.cpp.
◆ defaultSqlTypeName()
|
static |
used when we do not have KDbDriver instance yet
Definition at line 166 of file KDbDriver.cpp.
◆ drv_createAdminTools()
|
protectedvirtual |
Creates admin tools object providing a number of database administration tools for the driver. This is called once per driver.
Note for driver developers: Reimplement this method by returning a KDbAdminTools-derived object. Default implementation creates anmd returns an empty admin tools KDbAdminTools object.
- See also
- adminTools()
Reimplemented in SqliteDriver.
Definition at line 125 of file KDbDriver.cpp.
◆ drv_createConnection()
|
protectedpure virtual |
For reimplementation: creates and returns connection object with additional structures specific for a given driver. KDbConnection object should inherit KDbConnection and have a destructor that descructs all allocated driver-dependent connection structures.
Implemented in MysqlDriver, PostgresqlDriver, SqliteDriver, and SybaseDriver.
◆ drv_escapeIdentifier() [1/2]
|
protectedpure virtual |
This is overloaded version of drv_escapeIdentifier( const QString& str ) to be implemented in the same way.
Implemented in MysqlDriver, PostgresqlDriver, SqliteDriver, and SybaseDriver.
◆ drv_escapeIdentifier() [2/2]
Driver-specific SQL string escaping. This method is used by escapeIdentifier(). Implement escaping for any character like " or ' as your database engine requires. Do not append or prepend any quotation marks characters - it is automatically done by escapeIdentifier() using KDbDriverBehavior::OPENING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER and KDbDriverBehavior::CLOSING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER.
Implemented in MysqlDriver, PostgresqlDriver, SqliteDriver, and SybaseDriver.
◆ drv_isSystemFieldName()
|
protectedpure virtual |
- Returns
- true if name is a system field's name, build-in system field that cannot be used or created by a user, and in most cases user even shouldn't see this. The list is specific for a given driver implementation. For implementation.
Implemented in MysqlDriver, PostgresqlDriver, SqliteDriver, and SybaseDriver.
◆ escapeBLOB()
|
pure virtual |
Driver-specific SQL BLOB value escaping. Implement escaping for any character like " or ' and \0 as your database engine requires. Prepend and append quotation marks.
Implemented in MysqlDriver, PostgresqlDriver, SqliteDriver, and SybaseDriver.
◆ escapeIdentifier() [1/2]
QByteArray KDbDriver::escapeIdentifier | ( | const QByteArray & | str | ) | const |
Definition at line 279 of file KDbDriver.cpp.
◆ escapeIdentifier() [2/2]
- Returns
- str string with applied driver-specific identifier escaping
This escaping can be used for field, table, database names, etc.
- See also
- KDb::escapeIdentifier
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 272 of file KDbDriver.cpp.
◆ escapeString() [1/2]
|
pure virtual |
This is overloaded version of escapeString( const QString& str ) to be implemented in the same way.
Implemented in MysqlDriver, PostgresqlDriver, SqliteDriver, and SybaseDriver.
◆ escapeString() [2/2]
|
pure virtual |
Driver-specific SQL string escaping. Implement escaping for any character like " or ' as your database engine requires. Prepend and append quotation marks.
Implemented in MysqlDriver, PostgresqlDriver, SqliteDriver, and SybaseDriver.
◆ features()
int KDbDriver::features | ( | ) | const |
- Returns
- driver's features that are combination of KDbDriver::Features enum.
- Todo
- change int to Features
Definition at line 108 of file KDbDriver.cpp.
◆ greatestOrLeastFunctionToString()
|
virtual |
Generates native (driver-specific) GREATEST() and LEAST() function calls.
Default implementation just uses GREATEST() and LEAST(), respectively. (this works only with MySQL >= 5.0.13). For backends workarounds are added.
Reimplemented in MysqlDriver, PostgresqlDriver, and SqliteDriver.
Definition at line 343 of file KDbDriver.cpp.
◆ hexFunctionToString()
|
virtual |
Generates native (driver-specific) HEX() function call.
Default implementation uses HEX(val).
Reimplemented in PostgresqlDriver.
Definition at line 319 of file KDbDriver.cpp.
◆ ifnullFunctionToString()
|
virtual |
Generates native (driver-specific) IFNULL() function call.
Default implementation uses IFNULL().
Reimplemented in PostgresqlDriver.
Definition at line 327 of file KDbDriver.cpp.
◆ initDriverSpecificKeywords()
|
protected |
Used to initialise the dictionary of driver-specific keywords. Should be called by the driver's constructor. keywords should be 0-terminated array of null-terminated strings.
Definition at line 298 of file KDbDriver.cpp.
◆ internalProperty()
KDbUtils::Property KDbDriver::internalProperty | ( | const QByteArray & | name | ) | const |
- Returns
- internal property with a name name for this driver. If there's no such property defined for driver, a null property is returned.
Definition at line 286 of file KDbDriver.cpp.
◆ internalPropertyNames()
QList< QByteArray > KDbDriver::internalPropertyNames | ( | ) | const |
- Returns
- a list of internal property names for this driver.
Definition at line 291 of file KDbDriver.cpp.
◆ isDriverSpecificKeyword()
bool KDbDriver::isDriverSpecificKeyword | ( | const QByteArray & | word | ) | const |
- Returns
- true if word is a driver-specific keyword.
Definition at line 308 of file KDbDriver.cpp.
◆ isKDbSystemObjectName()
|
static |
- Returns
- true if name is a related to KDb's 'system' object's name, i.e. when name starts with "kexi__" prefix.
Definition at line 173 of file KDbDriver.cpp.
◆ isSystemDatabaseName()
|
pure virtual |
- Returns
- true if name is a database type-specific system database's name, e.g. name of a built-in system database that cannot be created by a user, and in most cases user a name that user shouldn't even see.
Implemented in MysqlDriver, PostgresqlDriver, SqliteDriver, and SybaseDriver.
◆ isSystemFieldName()
bool KDbDriver::isSystemFieldName | ( | const QString & | name | ) | const |
- Returns
- true if name is a system field's name, build-in system field that cannot be used or created by a user, and in most cases user even shouldn't see this. The list is specific for a given driver implementation.
Definition at line 180 of file KDbDriver.cpp.
◆ isSystemObjectName()
|
pure virtual |
- Returns
- true if n is a database type-specific system object's name, e.g. name of a built-in system table that cannot be created by the user, and in most cases a name that user shouldn't even see.
Implemented in MysqlDriver, PostgresqlDriver, and SqliteDriver.
◆ isValid()
|
protectedvirtual |
- Returns
- true if this driver's implementation is valid. Just a few constraints are checked to ensure that driver developer didn't forget something. This method is called automatically on createConnection(), and proper error message is set properly on error. Drivers can reimpement this method but should call KDbDriver::isValid() first.
Definition at line 84 of file KDbDriver.cpp.
◆ lengthFunctionToString()
|
virtual |
Generates native (driver-specific) LENGTH() function call.
Default implementation uses LENGTH().
Reimplemented in MysqlDriver, and PostgresqlDriver.
Definition at line 335 of file KDbDriver.cpp.
◆ metaData()
const KDbDriverMetaData * KDbDriver::metaData | ( | ) | const |
Info about the driver.
Definition at line 103 of file KDbDriver.cpp.
◆ randomFunctionToString()
|
virtual |
Generates native (driver-specific) RANDOM() and RANDOM(X,Y) function calls.
Accepted args can contain zero or two positive integer arguments X, Y; X < Y. In case of numeric arguments, RANDOM(X, Y) returns a random integer that is equal or greater than X and less than Y. Default implementation for RANDOM() returns F() where F is behavior()->RANDOM_FUNCTION. This works with PostgreSQL. Default implementation for RANDOM(X,Y) returns (X + FLOOR(F()*(Y-X+1))) where F is behavior()->RANDOM_FUNCTION. This works with PostgreSQL. If args has neither zero nor two arguments, empty string is returned.
Reimplemented in SqliteDriver.
Definition at line 352 of file KDbDriver.cpp.
◆ removeConnection()
|
protected |
- Returns
- connection conn, does not delete it nor affect. Returns
nullptr
if conn is not owned by this driver. After this, you are owner of conn object, so you should eventually delete it. Better use KDbConnection destructor.
Definition at line 158 of file KDbDriver.cpp.
◆ setMetaData()
|
protected |
Used by the driver manager to set metaData for just loaded driver.
Definition at line 313 of file KDbDriver.cpp.
◆ sqlTypeName()
|
virtual |
SQL-implementation-dependent name of given type
Reimplemented in MysqlDriver, and PostgresqlDriver.
Definition at line 130 of file KDbDriver.cpp.
◆ supportsDefaultValue()
|
inlineprotectedvirtual |
- Returns
- true if the database supports specifying default values for field field.
true
by default. For example MySQL does not support default values for BLOB, TEXT, GEOMETRY, and JSON types. (https://dev.mysql.com/doc/refman/5.7/en/data-type-defaults.html).
Reimplemented in MysqlDriver.
Definition at line 407 of file KDbDriver.h.
◆ timeToSql()
|
virtual |
Converts time value to string.
Default implementation uses KDb::timeToIsoString().
Not compatible with all drivers - reimplement.
- Since
- 3.2.0
Definition at line 257 of file KDbDriver.cpp.
◆ transactionsSupported()
bool KDbDriver::transactionsSupported | ( | ) | const |
- Returns
- true if transaction are supported (single or multiple).
Definition at line 113 of file KDbDriver.cpp.
◆ unicodeFunctionToString()
|
virtual |
Generates native (driver-specific) UNICODE() function call.
Default implementation USES UNICODE(). Special case is for MYSQL and PostgreSQL.
Reimplemented in MysqlDriver, and PostgresqlDriver.
Definition at line 382 of file KDbDriver.cpp.
◆ valueToSql() [1/3]
|
inline |
Like above method, for field.
Definition at line 162 of file KDbDriver.h.
◆ valueToSql() [2/3]
|
inline |
Like above but with the fildtype as string.
Definition at line 157 of file KDbDriver.h.
◆ valueToSql() [3/3]
|
virtual |
Escapes and converts value v (for type ftype) to string representation required by SQL commands. Reimplement this if you need other behavior (eg. for 'date' type handling) This implementation return date, datetime and time values in ISO format, what seems to be accepted by SQL servers.
- See also
- Qt::DateFormat
- Note
- it was compatible with SQLite: https://www.sqlite.org/lang_datefunc.html
Definition at line 246 of file KDbDriver.cpp.
Member Data Documentation
◆ d
|
protected |
Definition at line 426 of file KDbDriver.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.