KDb

SqliteConnection.h
1 /* This file is part of the KDE project
2  Copyright (C) 2003-2016 JarosÅ‚aw Staniek <[email protected]>
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_CONN_SQLITE_H
21 #define KDB_CONN_SQLITE_H
22 
23 #include <QStringList>
24 
25 #include "KDbConnection.h"
26 
27 class SqliteConnectionInternal;
28 class KDbDriver;
29 
30 /*! @brief SQLite-specific connection
31  Following connection options are supported (see KDbConnectionOptions):
32  - extraSqliteExtensionPaths (read/write, QStringList): adds extra seach paths for SQLite
33  extensions. Set them before KDbConnection::useDatabase()
34  is called. Absolute paths are recommended.
35 */
37 {
38  Q_DECLARE_TR_FUNCTIONS(SqliteConnection)
39 public:
40  ~SqliteConnection() override;
41 
42  Q_REQUIRED_RESULT KDbCursor *prepareQuery(const KDbEscapedString &sql,
44  = KDbCursor::Option::None) override;
45  Q_REQUIRED_RESULT KDbCursor *prepareQuery(KDbQuerySchema *query,
47  = KDbCursor::Option::None) override;
48 
49  Q_REQUIRED_RESULT KDbPreparedStatementInterface *prepareStatementInternal() override;
50 
51 protected:
52  /*! Used by driver */
55 
56  bool drv_connect() override;
58  bool drv_disconnect() override;
59  bool drv_getDatabasesList(QStringList* list) override;
60 
61 #if 0 // TODO
62 //! @todo move this somewhere to low level class (MIGRATION?)
63  virtual bool drv_getTablesList(QStringList* list);
64 #endif
65 
66 //! @todo move this somewhere to low level class (MIGRATION?)
67  tristate drv_containsTable(const QString &tableName) override;
68 
69  /*! Creates new database using connection. Note: Do not pass @a dbName
70  arg because for file-based engine (that has one database per connection)
71  it is defined during connection. */
72  bool drv_createDatabase(const QString &dbName = QString()) override;
73 
74  /*! Opens existing database using connection. Do not pass @a dbName
75  arg because for file-based engine (that has one database per connection)
76  it is defined during connection. If you pass it,
77  database file name will be changed. */
78  bool drv_useDatabase(const QString &dbName = QString(), bool *cancelled = nullptr,
79  KDbMessageHandler* msgHandler = nullptr) override;
80 
81  bool drv_closeDatabase() override;
82 
83  /*! Drops database from the server using connection.
84  After drop, database shouldn't be accessible
85  anymore, so database file is just removed. See note from drv_useDatabase(). */
86  bool drv_dropDatabase(const QString &dbName = QString()) override;
87 
88  KDbSqlResult* drv_prepareSql(const KDbEscapedString& sql) override;
89 
90  bool drv_executeSql(const KDbEscapedString& sql) override;
91 
92  //! Implemented for KDbResultable
93  QString serverResultName() const override;
94 
95  void storeResult();
96 
98  const QString& propertyName, const QVariant& value) override;
99 
100  //! for drv_changeFieldProperty()
102 
103  SqliteConnectionInternal* d;
104 
105 private:
106  bool drv_useDatabaseInternal(bool *cancelled, KDbMessageHandler* msgHandler, bool createIfMissing);
107 
108  //! Closes database without altering stored result number and message
109  void drv_closeDatabaseSilently();
110 
111  //! Finds a native SQLite extension @a name in the search path and loads it.
112  //! Path and filename extension should not be provided.
113  //! @return true on success
114  bool findAndLoadExtension(const QString & name);
115 
116  //! Loads extension from plugin at @a path (absolute path is recommended)
117  //! @return true on success
118  bool loadExtension(const QString& path);
119 
120  friend class SqliteDriver;
121  friend class SqliteCursor;
122  friend class SqliteSqlResult;
123  Q_DISABLE_COPY(SqliteConnection)
124 };
125 
126 #endif
Provides database cursor functionality.
Definition: KDbCursor.h:68
The KDbSqlResult class abstracts result of a raw SQL query preparation by KDbConnection::prepareSql()
Definition: KDbSqlResult.h:44
Specialized string for escaping.
bool drv_createDatabase(const QString &dbName=QString()) override
Database driver's abstraction.
Definition: KDbDriver.h:49
bool drv_executeSql(const KDbEscapedString &sql) override
Executes query for a raw SQL statement sql without returning resulting records.
bool drv_getDatabasesList(QStringList *list) override
SQLite-specific connection Following connection options are supported (see KDbConnectionOptions):
bool drv_disconnect() override
bool drv_connect() override
3-state logical type with three values: true, false and cancelled and convenient operators.
Definition: KDbTristate.h:100
KDbCursor * prepareQuery(const KDbEscapedString &sql, KDbCursor::Options options=KDbCursor::Option::None) override
SQLite database driver.
Definition: SqliteDriver.h:29
bool drv_closeDatabase() override
bool drv_useDatabase(const QString &dbName=QString(), bool *cancelled=nullptr, KDbMessageHandler *msgHandler=nullptr) override
Prepared statement interface for backend-dependent implementations.
KDbQuerySchema provides information about database query.
unsigned int version()
Definition: KDb.cpp:336
KDbPreparedStatementInterface * prepareStatementInternal() override
tristate drv_containsTable(const QString &tableName) override
KDbConnectionOptions * options()
Database specific connection data, e.g. host, port.
QString serverResultName() const override
Implemented for KDbResultable.
bool drv_getServerVersion(KDbServerVersionInfo *version) override
tristate drv_changeFieldProperty(KDbTableSchema *table, KDbField *field, const QString &propertyName, const QVariant &value) override
Definition: SqliteAlter.cpp:61
Generic options for a single connection. The options are accessible using key/value pairs....
SqliteConnection(KDbDriver *driver, const KDbConnectionData &connData, const KDbConnectionOptions &options)
tristate changeFieldType(KDbTableSchema *table, KDbField *field, KDbField::Type type)
for drv_changeFieldProperty()
Definition: SqliteAlter.cpp:98
Meta-data for a field.
Definition: KDbField.h:71
KDbSqlResult * drv_prepareSql(const KDbEscapedString &sql) override
Prepares query for a raw SQL statement sql with possibility of returning records.
Provides database connection, allowing queries and data modification.
Definition: KDbConnection.h:51
KDbDriver * driver() const
bool drv_dropDatabase(const QString &dbName=QString()) override
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.