KDb

KDbDriverBehavior.h
1/* This file is part of the KDE project
2 Copyright (C) 2003-2018 Jarosław Staniek <staniek@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KDB_DRIVERBEHAVIOR_H
21#define KDB_DRIVERBEHAVIOR_H
22
23#include "KDbDriver.h"
24#include "KDbUtils.h"
25
26/**
27 * @brief Detailed definition of driver's default behavior
28 *
29 * This class is mostly interesting for KDb driver developers.
30 * Defaults can be changed by KDbDriver subclass in constructors.
31 */
32class KDB_EXPORT KDbDriverBehavior
33{
34public:
35 explicit KDbDriverBehavior(KDbDriver *driver);
36
38
39 /*! Features (like transactions, etc.) supported by this driver
40 (sum of selected Features enum items).
41 This member should be filled in driver implementation's constructor
42 (by default m_features==NoFeatures). */
44
45 //! real type names for this engine
47
48 /*! Driver properties (indexed by name), useful for presenting properties to the user.
49 Contains i18n-ed captions.
50 In driver implementations available properties can be initialized, for example:
51 @code
52 beh->properties.insert("maximum_performance", 1000, SomeClass::tr("Maximum performance"));
53 @endcode
54 You do not need to set captions of properties predefined by the KDbDriver superclass,
55 they will be reused. Predefined properties are set in KDbDriver. */
57
58 //! "UNSIGNED" by default
60
61 //! "AUTO_INCREMENT" by default, used as add-in word to field definition
62 //! May be also used as full definition if SPECIAL_AUTO_INCREMENT_DEF is true.
64
65 //! "AUTO_INCREMENT PRIMARY KEY" by default, used as add-in word to field definition
66 //! May be also used as full definition if SPECIAL_AUTO_INCREMENT_DEF is true.
68
69 //! "" by default, used as type string for autoinc. field definition
70 //! pgsql defines it as "SERIAL", sqlite defines it as "INTEGER"
72
73 /*! True if autoincrement field has special definition
74 e.g. like "INTEGER PRIMARY KEY" for SQLite.
75 Special definition string should be stored in AUTO_INCREMENT_FIELD_OPTION.
76 False by default. */
78
79 /*! True if autoincrement requires field to be declared as primary key.
80 This is true for SQLite. False by default. */
82
83 /*! Name of a field (or built-in function) with autoincremented unique value,
84 typically returned by KDbSqlResult::lastInsertRecordId().
85
86 Examples:
87 - PostgreSQL and SQLite engines use 'OID' field
88 - MySQL uses LAST_INSERT_ID() built-in function
89 */
91
92 /*! True if the value (fetched from field or function,
93 defined by ROW_ID_FIELD_NAME member) is EXACTLY the value of autoincremented field,
94 not an implicit (internal) row number. Default value is false.
95
96 Examples:
97 - PostgreSQL and SQLite engines have this flag set to false ('OID' field has
98 it's own implicit value)
99 - MySQL engine has this flag set to true (LAST_INSERT_ID() returns real value
100 of last autoincremented field).
101
102 Notes:
103 If it's false, we have a convenient way for identifying row even when there's
104 no primary key defined. So, as '_ROWID' column in MySQL is really
105 just a synonym for the primary key, this engine needs to have primary keys always
106 defined if we want to use interactive editing features like row updating and deleting.
107 */
109
110 /*! Name of any (e.g. first found) database for this connection that
111 typically always exists. This can be not set if we want to do some magic checking
112 what database name is availabe by reimplementing
113 KDbConnection::anyAvailableDatabaseName().
114 Example: for PostgreSQL this is "template1".
115
116 @see KDbConnection::SetAvailableDatabaseName()
117 */
119
120 /*! Opening quotation mark used for escaping identifier (see KDbDriver::escapeIdentifier()).
121 Default value is '"'. Change it for your driver.
122 */
124
125 /*! Opening quotation mark used for escaping identifier (see KDbDriver::escapeIdentifier()).
126 Default value is '"'. Change it for your driver.
127 */
129
130 /*! True if using database is required to perform real connection.
131 This is true for may engines, e.g. for PostgreSQL, where connection
132 strings should contain a database name.
133 If the flag is false, then developer has to call KDbConnection::useDatabase()
134 after creating the KDbConnection object.
135 This flag can be also used for file-based db drivers, e.g. SQLite sets it to true.
136 MySQL sets it to false.
137 By default this flag is true.
138 */
140
141 /*! True if connection should be established (KDbConnection::connect()) in order
142 to check database existence (KDbConnection::databaseExists()).
143 This is true for most engines, but not for SQLite (and probably most
144 file-based databases) where existence of database is checked at filesystem level.
145 By default this flag is true.
146 */
148
149 /*! True if connection should be established (KDbConnection::connect()) in order
150 to create new database (KDbConnection::createDatabase()).
151 This is true for most engines, but not for SQLite (and probably most
152 file-based databases) where opening physical connection for nonexisting
153 file creates new file.
154 By default this flag is true.
155 */
157
158 /*! True if connection should be established (KDbConnection::connect()) in order
159 to drop database (KDbConnection::dropDatabase()).
160 This is true for most engines, but not for SQLite (and probably most
161 file-based databases) where dropping database is performed at filesystem level.
162 By default this flag is true.
163 */
165
166 /*! Because some engines need to have opened any database before
167 executing administrative sql statements like "create database" or "drop database",
168 using appropriate, existing temporary database for this connection.
169 This is the case for PostgreSQL.
170 For file-based db drivers this flag is ignored.
171 By default this flag is false.
172
173 Note: This method has nothing to do with creating or using temporary databases
174 in such meaning that these database are not persistent.
175
176 @see KDbConnection::useTemporaryDatabaseIfNeeded()
177 */
179
180 /*! Set to @c true in a subclass if after successful drv_createDatabase() the database
181 is in opened state (as after useDatabase()).
182 @c false for most engines. */
184
185 /*! True if before we know whether the fetched result of executed query
186 is empty or not, we need to fetch first record. Particularly, it's true for SQLite.
187 The flag is used in KDbCursor::open(). By default this flag is false. */
189
190 /*! True if "SELECT 1 from (subquery)" is supported. False by default.
191 Used in KDbConnection::resultExists() for optimization. It's set to true for SQLite driver. */
193
194 /*! Literal for boolean true. "1" by default
195 which is typically expected by backends even while the standard says "TRUE":
196 https://troels.arvin.dk/db/rdbms/#data_types-boolean
197 */
199
200 /*! Literal for boolean false. "0" by default
201 which is typically expected by backends even while the standard says "TRUE":
202 https://troels.arvin.dk/db/rdbms/#data_types-boolean
203 */
205
206 /*! Specifies maximum length for Text type. If 0, there is are limits and length argument is not needed,
207 e.g. VARCHAR works for the driver this is the case for SQLite and PostgreSQL.
208 If greater than 0, this value should be used to express maximum value, e.g. VARCHAR(...).
209 This is the case for MySQL.
210 The default is 0. */
212
213 /*! "LIKE" by default, used to construct native expressions "x LIKE y" and "x NOT LIKE y".
214 LIKE is case-insensitive for MySQL, SQLite, and often on Sybase/MSSQL
215 while for PostgreSQL it's case-sensitive. So for PostgreSQL LIKE_OPERATOR == "ILIKE". */
217
218 /*! "RANDOM()" function name, used in Driver::randomFunctionToString() to construct native
219 expressions. */
221
222 /**
223 * SQL statement used to obtain list of physical table names.
224 * Used by default implementation of KDbConnection::drv_getTableNames(). Empty by default.
225 * If empty, default implementation of KDbConnection::drv_getTableNames() fails.
226 *
227 * @since 3.2
228 */
230
231private:
232 void initInternalProperties();
233 friend class KDbDriver;
234
235 Q_DISABLE_COPY(KDbDriverBehavior)
236 class Private;
237 Private * const d;
238};
239
240#endif
Detailed definition of driver's default behavior.
QString AUTO_INCREMENT_FIELD_OPTION
"AUTO_INCREMENT" by default, used as add-in word to field definition May be also used as full definit...
bool USE_TEMPORARY_DATABASE_FOR_CONNECTION_IF_NEEDED
QString ALWAYS_AVAILABLE_DATABASE_NAME
bool ROW_ID_FIELD_RETURNS_LAST_AUTOINCREMENTED_VALUE
KDbEscapedString GET_TABLE_NAMES_SQL
SQL statement used to obtain list of physical table names.
char OPENING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER
QString AUTO_INCREMENT_PK_FIELD_OPTION
"AUTO_INCREMENT PRIMARY KEY" by default, used as add-in word to field definition May be also used as ...
KDbUtils::PropertySet properties
QVector< QString > typeNames
real type names for this engine
QString AUTO_INCREMENT_TYPE
"" by default, used as type string for autoinc.
QString UNSIGNED_TYPE_KEYWORD
"UNSIGNED" by default
char CLOSING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER
bool CONNECTION_REQUIRED_TO_CHECK_DB_EXISTENCE
bool _1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY
Database driver's abstraction.
Definition KDbDriver.h:50
Specialized string for escaping.
A set of properties.
Definition KDbUtils.h:480
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:11:01 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.