KDb

SqliteDriver.h
1/* This file is part of the KDE project
2 Copyright (C) 2003-2015 Jarosław Staniek <staniek@kde.org>
3
4 This program 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 program 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 program; see the file COPYING. 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_DRIVER_SQLITE_H
21#define KDB_DRIVER_SQLITE_H
22
23#include "KDbDriver.h"
24
25class KDbConnection;
26class SqliteDriverPrivate;
27
28//! SQLite database driver.
29class SqliteDriver : public KDbDriver
30{
32
33public:
34 SqliteDriver(QObject *parent, const QVariantList &args);
35
36 ~SqliteDriver() override;
37
38 /*! @return true if @a n is a system object name;
39 for this driver any object with name prefixed with "sqlite_"
40 is considered as system object.
41 */
42 bool isSystemObjectName(const QString& n) const override;
43
44 /*! @return false for this driver. */
45 bool isSystemDatabaseName(const QString&) const override;
46
47 //! Escape a string for use as a value
48 KDbEscapedString escapeString(const QString& str) const override;
49 KDbEscapedString escapeString(const QByteArray& str) const override;
50
51 //! Escape BLOB value @a array
52 KDbEscapedString escapeBLOB(const QByteArray& array) const override;
53
54 /*! Implemented for KDbDriver class.
55 @return SQL clause to add for unicode text collation sequence
56 used in ORDER BY clauses of SQL statements generated by KDb.
57 Later other clauses may use this statement.
58 One space character should be be prepended.
59 Can be reimplemented for other drivers, e.g. the SQLite3 driver returns " COLLATE ''".
60 Default implementation returns empty string. */
61 KDbEscapedString collationSql() const override;
62
63 //! Generates native (driver-specific) GREATEST() and LEAST() function calls.
64 //! Uses MAX() and MIN(), respectively.
65 //! If arguments are of text type, to each argument default (unicode) collation
66 //! is assigned that is configured for SQLite by KDb.
67 //! Example: SELECT MAX('ą' COLLATE '', 'z' COLLATE '').
70 KDb::ExpressionCallStack *callStack) const override;
71
72 //! Generates native (driver-specific) RANDOM() and RANDOM(X,Y) function calls.
73 //! Accepted @a args can contain zero or two positive integer arguments X, Y; X < Y.
74 //! In case of numeric arguments, RANDOM(X, Y) returns a random integer that is equal
75 //! or greater than X and less than Y.
76 //! Because SQLite returns integer between -9223372036854775808 and +9223372036854775807,
77 //! RANDOM() for SQLite is equal to (RANDOM()+9223372036854775807)/18446744073709551615.
78 //! Similarly, RANDOM(X,Y) for SQLite is equal to
79 //! (X + CAST((Y-X) * (RANDOM()+9223372036854775807)/18446744073709551615 AS INT)).
82 KDb::ExpressionCallStack *callStack) const override;
83
84 //! Generates native (driver-specific) CEILING() and FLOOR() function calls.
85 //! Default implementation USES CEILING() and FLOOR(), respectively.
86 //! For CEILING() uses:
87 //! (CASE WHEN X = CAST(X AS INT) THEN CAST(X AS INT) WHEN X >= 0 THEN CAST(X AS INT) + 1 ELSE CAST(X AS INT) END).
88 //! For FLOOR() uses:
89 //! (CASE WHEN X >= 0 OR X = CAST(X AS INT) THEN CAST(X AS INT) ELSE CAST(X AS INT) - 1 END).
92 KDb::ExpressionCallStack *callStack) const override;
93
94protected:
95 QString drv_escapeIdentifier(const QString& str) const override;
96 QByteArray drv_escapeIdentifier(const QByteArray& str) const override;
98 const KDbConnectionOptions &options) override;
99 KDbAdminTools* drv_createAdminTools() const override;
100
101 /*! @return true if @a n is a system field name;
102 for this driver fields with name equal "_ROWID_"
103 is considered as system field.
104 */
105 bool drv_isSystemFieldName(const QString &n) const override;
106
107 SqliteDriverPrivate * const dp;
108
109private:
110 static const char * const keywords[];
111 Q_DISABLE_COPY(SqliteDriver)
112};
113
114#endif
An interface containing a set of tools for database administration.
Definition KDbAdmin.h:31
Database specific connection data, e.g. host, port.
Generic options for a single connection. The options are accessible using key/value pairs....
Provides database connection, allowing queries and data modification.
Database driver's abstraction.
Definition KDbDriver.h:50
Specialized string for escaping.
The KDbNArgExpression class represents a base class N-argument expression.
An iterator for a list of values of query schema parameters Allows to iterate over parameters and ret...
SQLite database driver.
QString drv_escapeIdentifier(const QString &str) const override
KDbConnection * drv_createConnection(const KDbConnectionData &connData, const KDbConnectionOptions &options) override
KDbEscapedString collationSql() const override
bool isSystemObjectName(const QString &n) const override
KDbEscapedString greatestOrLeastFunctionToString(const QString &name, const KDbNArgExpression &args, KDbQuerySchemaParameterValueListIterator *params, KDb::ExpressionCallStack *callStack) const override
Generates native (driver-specific) GREATEST() and LEAST() function calls.
KDbAdminTools * drv_createAdminTools() const override
bool isSystemDatabaseName(const QString &) const override
bool drv_isSystemFieldName(const QString &n) const override
KDbEscapedString randomFunctionToString(const KDbNArgExpression &args, KDbQuerySchemaParameterValueListIterator *params, KDb::ExpressionCallStack *callStack) const override
Generates native (driver-specific) RANDOM() and RANDOM(X,Y) function calls.
KDbEscapedString escapeBLOB(const QByteArray &array) const override
Escape BLOB value array.
KDbEscapedString ceilingOrFloorFunctionToString(const QString &name, const KDbNArgExpression &args, KDbQuerySchemaParameterValueListIterator *params, KDb::ExpressionCallStack *callStack) const override
Generates native (driver-specific) CEILING() and FLOOR() function calls.
KDbEscapedString escapeString(const QString &str) const override
Escape a string for use as a value.
Q_OBJECTQ_OBJECT
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:51:49 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.