KDb

MysqlDriver.h
1 /* This file is part of the KDE project
2  Copyright (C) 2002 Lucijan Busch <[email protected]>
3  Copyright (C) 2003 Daniel Molkentin <[email protected]>
4  Copyright (C) 2003 Joseph Wenninger<[email protected]>
5  Copyright (C) 2003-2016 JarosÅ‚aw Staniek <[email protected]>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this program; see the file COPYING. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21 */
22 
23 #ifndef KDB_MYSQLDRIVER_H
24 #define KDB_MYSQLDRIVER_H
25 
26 #include "KDbDriver.h"
27 
28 //! MySQL database driver.
29 class MysqlDriver : public KDbDriver
30 {
31  Q_OBJECT
32 
33 public:
34  /*!
35  * Constructor sets database features and
36  * maps the types in KDbField::Type to the MySQL types.
37  *
38  * See: https://dev.mysql.com/doc/mysql/en/Column_types.html
39  */
40  MysqlDriver(QObject *parent, const QVariantList &args);
41 
42  ~MysqlDriver() override;
43 
44  /*! @return false for this driver. */
45  bool isSystemObjectName(const QString& name) const override;
46 
47  /*! @return true if @a is "mysql", "information_schema" or "performance_schema". */
48  bool isSystemDatabaseName(const QString &name) const override;
49 
50  //! Escape a string for use as a value
51  KDbEscapedString escapeString(const QString& str) const override;
52  KDbEscapedString escapeString(const QByteArray& str) const override;
53 
54  //! Escape BLOB value @a array
55  KDbEscapedString escapeBLOB(const QByteArray& array) const override;
56 
57  //! Overrides the default implementation
58  QString sqlTypeName(KDbField::Type type, const KDbField &field) const override;
59 
60  //! Generates native (driver-specific) LENGTH() function call.
61  //! char_length(val) is used because length(val) in mysql returns number of bytes,
62  //! what is not right for multibyte (unicode) encodings. */
65  KDb::ExpressionCallStack *callStack) const override;
66 
67  //! Generates native (driver-specific) GREATEST() and LEAST() function call.
68  //! Since MySQL's LEAST()/GREATEST() function ignores NULL values, it only returns NULL
69  //! if all the expressions evaluate to NULL. So this is used for F(v0,..,vN):
70  //! (CASE WHEN (v0) IS NULL OR .. OR (vN) IS NULL THEN NULL ELSE F(v0,..,vN) END)
71  //! where F == GREATEST or LEAST.
73  const KDbNArgExpression &args,
75  KDb::ExpressionCallStack* callStack) const override;
76 
77  //! Generates native (driver-specific) UNICODE() function call.
78  //! Uses ORD(CONVERT(X USING UTF16)).
81  KDb::ExpressionCallStack* callStack) const override;
82 
83  //! Generates native (driver-specific) function call for concatenation of two strings.
84  //! Uses CONCAT().
87  KDb::ExpressionCallStack* callStack) const;
88 
89 protected:
90  QString drv_escapeIdentifier(const QString& str) const override;
91  QByteArray drv_escapeIdentifier(const QByteArray &str) const override;
93  const KDbConnectionOptions &options) override;
94  bool drv_isSystemFieldName(const QString& name) const override;
95  bool supportsDefaultValue(const KDbField &field) const override;
96 
97 private:
98  static const char *keywords[];
99  QString m_longTextPrimaryKeyType;
101 };
102 
103 #endif
Q_OBJECTQ_OBJECT
KDbEscapedString unicodeFunctionToString(const KDbNArgExpression &args, KDbQuerySchemaParameterValueListIterator *params, KDb::ExpressionCallStack *callStack) const override
Generates native (driver-specific) UNICODE() function call.
An iterator for a list of values of query schema parameters Allows to iterate over parameters and ret...
KDbEscapedString escapeBLOB(const QByteArray &array) const override
Escape BLOB value array.
The KDbBinaryExpression class represents binary operation.
Specialized string for escaping.
Database driver's abstraction.
Definition: KDbDriver.h:49
MysqlDriver(QObject *parent, const QVariantList &args)
Definition: MysqlDriver.cpp:40
KDbEscapedString greatestOrLeastFunctionToString(const QString &name, const KDbNArgExpression &args, KDbQuerySchemaParameterValueListIterator *params, KDb::ExpressionCallStack *callStack) const override
Generates native (driver-specific) GREATEST() and LEAST() function call.
QString sqlTypeName(KDbField::Type type, const KDbField &field) const override
Overrides the default implementation.
bool isSystemDatabaseName(const QString &name) const override
KDbEscapedString lengthFunctionToString(const KDbNArgExpression &args, KDbQuerySchemaParameterValueListIterator *params, KDb::ExpressionCallStack *callStack) const override
Generates native (driver-specific) LENGTH() function call.
QString drv_escapeIdentifier(const QString &str) const override
bool supportsDefaultValue(const KDbField &field) const override
bool isSystemObjectName(const QString &name) const override
Definition: MysqlDriver.cpp:95
The KDbNArgExpression class represents a base class N-argument expression.
bool drv_isSystemFieldName(const QString &name) const override
Database specific connection data, e.g. host, port.
Generic options for a single connection. The options are accessible using key/value pairs....
KDbConnection * drv_createConnection(const KDbConnectionData &connData, const KDbConnectionOptions &options) override
Definition: MysqlDriver.cpp:89
Meta-data for a field.
Definition: KDbField.h:71
Provides database connection, allowing queries and data modification.
Definition: KDbConnection.h:51
Q_DISABLE_COPY(Class)
KDbEscapedString escapeString(const QString &str) const override
Escape a string for use as a value.
QObject * parent() const const
KDbEscapedString concatenateFunctionToString(const KDbBinaryExpression &args, KDbQuerySchemaParameterValueListIterator *params, KDb::ExpressionCallStack *callStack) const
Generates native (driver-specific) function call for concatenation of two strings.
MySQL database driver.
Definition: MysqlDriver.h:29
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:21:34 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.