kexi

kexiprojectset.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003-2005 Jaroslaw Staniek <js@iidea.pl>
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#include "kexiprojectset.h"
21#include "kexi.h"
22
23#include <kexidb/driver.h>
24#include <kexidb/connection.h>
25#include <kexidb/msghandler.h>
26
27#include <kdebug.h>
28
29//#define ERRMSG(a1, a2)
30// { if (m_msgHandler) m_msgHandler->showErrorMessage(a1, a2); }
31
33class KexiProjectSetPrivate
34{
35public:
36 KexiProjectSetPrivate()
37 {
38// list.setAutoDelete(true);
39 }
40 KexiProjectData::List list;
41// KexiDB::MessageHandler* msgHandler;
42};
43
45: KexiDB::Object(handler)
46, d(new KexiProjectSetPrivate())
47{
48}
49
52: KexiDB::Object(handler)
53, d(new KexiProjectSetPrivate())
54{
56 if (!drv) {
58 return;
59 }
60 KexiDB::Connection *conn = drv->createConnection(conndata);
61 if (!conn) {
62 setError(drv);
63 return;
64 }
65 if (!conn->connect()) {
66 setError(conn);
67 delete conn;
68 return;
69 }
70 TQStringList dbnames = conn->databaseNames(false/*skip system*/);
71// kexidbg << dbnames.count() << endl;
72 if (conn->error()) {
73 setError(conn);
74 delete conn;
75 return;
76 }
77 delete conn;
78 conn = 0;
79 for (TQStringList::ConstIterator it = dbnames.constBegin(); it!=dbnames.constEnd(); ++it) {
80 // project's caption is just the same as database name - nothing better is available
81 KexiProjectData *pdata = new KexiProjectData(conndata, *it, *it);
82 d->list.append( pdata );
83 }
84 clearError();
85}
86
87
88KexiProjectSet::~KexiProjectSet()
89{
90 delete d;
91}
92
94{
95 d->list.append(data);
96}
97
98KexiProjectData::List KexiProjectSet::list() const
99{
100 return d->list;
101}
102
103KexiProjectData* KexiProjectSet::findProject(const TQString &dbName) const
104{
105 const TQString _dbName = dbName.lower();
106 TQPtrListIterator<KexiProjectData> it( d->list );
107 for (;it.current();++it) {
108 if (it.current()->databaseName().lower()==_dbName)
109 return it.current();
110 }
111 return 0;
112}
TQString driverName
the name of the driver that should be used to create a connection
Database specific connection data, e.g. host, port.
Provides database connection, allowing queries and data modification.
Definition connection.h:62
TQStringList databaseNames(bool also_system_db=false)
bool connect()
Connects to driver with given parameters.
Driver * driver(const TQString &name)
Generic database abstraction.
Definition driver.h:67
Connection * createConnection(ConnectionData &conn_data, int options=0)
Definition driver.cpp:178
bool error() const
Definition object.h:38
virtual void clearError()
Definition object.cpp:131
virtual void setError(int code=ERR_OTHER, const TQString &msg=TQString())
Definition object.cpp:53
Kexi project core data member.
KexiProjectData::List list() const
KexiProjectSet(KexiDB::MessageHandler *handler=0)
KexiProjectData * findProject(const TQString &dbName) const
Case insensitive lookup.
void addProjectData(KexiProjectData *data)
High-level database connectivity library with database backend drivers.
KEXICORE_EXPORT KexiDB::DriverManager & driverManager()
shared driver manager
Definition kexi.cpp:91