KDb

XbaseConnection.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2008 Sharan Rao <sharanrao@gmail.com>
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
21#include "XbaseDriver.h"
22#include "XbaseCursor.h"
23#include "XbaseConnection.h"
24#include "XbaseConnection_p.h"
25#include "KDbError.h"
26
28 : KDbConnection(driver, connData)
29 , d(new xBaseConnectionInternal(this, internalDriver))
30{
31}
32
33xBaseConnection::~xBaseConnection() {
34 destroy();
35}
36
38{
39 Q_UNUSED(version);
40 const bool ok = d->db_connect(*data());
41 if (!ok)
42 return false;
43
44 //! @todo xBase version here
45 //version.string = mysql_get_host_info(d->mysql);
46
47 return true;
48}
49
51 return d->db_disconnect(*data());
52}
53
54KDbCursor* xBaseConnection::prepareQuery(const KDbEscapedString& sql, int cursor_options)
55{
56 if ( !d->internalConn ) {
57 return nullptr;
58 }
59 KDbCursor* internalCursor = d->internalConn->prepareQuery(sql,cursor_options);
60 return new xBaseCursor( this, internalCursor, sql, cursor_options );
61}
62
63KDbCursor* xBaseConnection::prepareQuery(KDbQuerySchema* query, int cursor_options) {
64 if ( !d->internalConn ) {
65 return nullptr;
66 }
67 KDbCursor* internalCursor = d->internalConn->prepareQuery(query, cursor_options);
68 return new xBaseCursor( this, internalCursor, query, cursor_options );
69}
70
72{
73 //! @todo Check whether this is the right thing to do
74 *list += QStringList( d->dbMap.keys() );
75// list<<d->internalConn->databaseNames();
76 return true;
77}
78
80 //! @todo Check whether this function has any use.
81 //xbaseDebug() << dbName;
82// return d->internalConn->createDatabase(d->dbMap[dbName]);
83 return true;
84}
85
86bool xBaseConnection::drv_useDatabase(const QString &dbName, bool *cancelled, KDbMessageHandler* msgHandler)
87{
88 Q_UNUSED(cancelled);
89 Q_UNUSED(msgHandler);
90//! @todo is here escaping needed?
91 return d->useDatabase(dbName);
92}
93
95 if (!d->internalConn || !d->internalConn->closeDatabase() ) {
96 return false;
97 }
98 return true;
99}
100
102 Q_UNUSED(dbName);
103//! @todo is here escaping needed
104 // Delete the directory ?
105 return true;
106}
107
109 return d->executeSql(sql);
110}
111
113{
114 //! @todo
115 quint64 rowID = -1;
116 if (d->internalConn)
117 d->internalConn->lastInsertedAutoIncValue(QString(), QString(), &rowID );
118
119 return rowID;
120}
121
122int xBaseConnection::serverResult()
123{
124 return d->res;
125}
126
128{
129 if (!d->internalConn) {
130 return QString();
131 }
132 return d->internalConn->serverResultName();
133}
134
135/*void xBaseConnection::drv_clearServerResult()
136{
137 if (!d || !d->internalConn)
138 return;
139 d->internalConn->clearError();
140 d->res = 0;
141}*/
142
143QString xBaseConnection::serverErrorMsg()
144{
145 return d->errmsg;
146}
147
149{
150 return resultExists(KDbEscapedString("SHOW TABLES LIKE %1")
151 .arg(escapeString(tableName)));
152}
153
155{
156 if ( !d->internalConn ) {
157 return false;
158 }
159 *list += d->internalConn->tableNames();
160 return true;
161}
162
164{
165 if ( !d->internalConn )
166 return nullptr;
167//! @todo return new XBasePreparedStatement(*d);
168 return nullptr;
169}
Database specific connection data, e.g. host, port.
Provides database connection, allowing queries and data modification.
virtual KDbEscapedString escapeString(const QString &str) const
KDbConnectionData data() const
virtual bool drv_connect()=0
tristate resultExists(const KDbEscapedString &sql, QueryRecordOptions options=QueryRecordOption::Default)
Provides database cursor functionality.
Definition KDbCursor.h:69
Database driver's abstraction.
Definition KDbDriver.h:50
Specialized string for escaping.
Prepared statement interface for backend-dependent implementations.
KDbQuerySchema provides information about database query.
virtual quint64 drv_lastInsertRecordId()
virtual bool drv_closeDatabase()
virtual bool drv_executeSql(const KDbEscapedString &sql)
Executes query for a raw SQL statement sql without returning resulting records.
virtual bool drv_getTablesList(QStringList *list)
virtual bool drv_useDatabase(const QString &dbName=QString(), bool *cancelled=0, KDbMessageHandler *msgHandler=0)
virtual bool drv_createDatabase(const QString &dbName=QString())
virtual QString serverResultName() const
Implemented for KDbResultable.
virtual bool drv_getDatabasesList(QStringList *list)
virtual bool drv_dropDatabase(const QString &dbName=QString())
xBaseConnection(KDbDriver *driver, KDbDriver *internalDriver, const KDbConnectionData &connData)
virtual bool drv_disconnect()
virtual bool drv_containsTable(const QString &tableName)
KDbPreparedStatementInterface * prepareStatementInternal() override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:38:30 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.