1
/***************************************************************************
2
* kexidbdrivermanager.cpp
3
* This file is part of the KDE project
4
* copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
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., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
18
***************************************************************************/
20
#include "kexidbdrivermanager.h"
21
#include "kexidbdriver.h"
22
#include "kexidbconnectiondata.h"
23
#include "kexidbfield.h"
24
#include "kexidbschema.h"
26
#include "../api/exception.h"
28
#include <qguardedptr.h>
32
#include <kexidb/driver.h>
33
#include <kexidb/connectiondata.h>
34
#include <kexidb/field.h>
35
#include <kexidb/tableschema.h>
36
#include <kexidb/queryschema.h>
38
using namespace Kross::KexiDB;
40
KexiDBDriverManager::KexiDBDriverManager()
41
: Kross::Api::Class<KexiDBDriverManager>("KexiDBDriverManager")
43
addFunction("driverNames", &KexiDBDriverManager::driverNames,
44
Kross::Api::ArgumentList(),
45
i18n("Returns a stringlist of all available drivernames.")
47
addFunction("driver", &KexiDBDriverManager::driver,
48
Kross::Api::ArgumentList() << Kross::Api::Argument("Kross::Api::Variant::String"),
49
i18n("Returns the to name matching KexiDBDriver object.")
51
addFunction("lookupByMime", &KexiDBDriverManager::lookupByMime,
52
Kross::Api::ArgumentList() << Kross::Api::Argument("Kross::Api::Variant::String"),
53
i18n("Looks up a drivers list by MIME type of database file. "
54
"Only file-based database drivers are checked. "
55
"The lookup is case insensitive.")
58
addFunction("connectionData", &KexiDBDriverManager::connectionData,
59
Kross::Api::ArgumentList(),
60
i18n("Return a new KexiDBConnectionData object.")
62
addFunction("field", &KexiDBDriverManager::field,
63
Kross::Api::ArgumentList(),
64
i18n("Return a new KexiDBField object.")
66
addFunction("tableSchema", &KexiDBDriverManager::tableSchema,
67
Kross::Api::ArgumentList() << Kross::Api::Argument("Kross::Api::Variant::String"),
68
i18n("Return a new KexiDBTableSchema object.")
70
addFunction("querySchema", &KexiDBDriverManager::querySchema,
71
Kross::Api::ArgumentList(),
72
i18n("Return a new KexiDBQuerySchema object.")
76
KexiDBDriverManager::~KexiDBDriverManager()
80
const QString KexiDBDriverManager::getClassName() const
82
return "Kross::KexiDB::KexiDBDriverManager";
85
const QString KexiDBDriverManager::getDescription() const
87
return i18n("KexiDB::DriverManager wrapper for database driver "
88
"management, e.g. finding and loading drivers.");
91
KexiDB::DriverManager& KexiDBDriverManager::driverManager()
93
if(m_drivermanager.error())
94
throw Kross::Api::RuntimeException(i18n("KexiDB::DriverManager error: %1").arg(m_drivermanager.errorMsg()));
95
return m_drivermanager;
98
Kross::Api::Object* KexiDBDriverManager::driverNames(Kross::Api::List*)
100
return Kross::Api::Variant::create(driverManager().driverNames(), "Kross::KexiDB::DriverManager::driverNames::StringList");
103
Kross::Api::Object* KexiDBDriverManager::driver(Kross::Api::List* args)
105
QString drivername = Kross::Api::Variant::toString(args->item(0));
106
QGuardedPtr< ::KexiDB::Driver > driver = driverManager().driver(drivername); // caching is done by the DriverManager
108
throw Kross::Api::AttributeException(i18n("No such KexiDB::Driver object for the defined drivername '%1'.").arg(drivername));
110
throw Kross::Api::RuntimeException(i18n("KexiDB::Driver error for drivername '%1': %2").arg(drivername).arg(driver->errorMsg()));
111
return new KexiDBDriver(this, driver);
114
Kross::Api::Object* KexiDBDriverManager::lookupByMime(Kross::Api::List* args)
116
return Kross::Api::Variant::create(
117
driverManager().lookupByMime( Kross::Api::Variant::toString(args->item(0)) ),
118
"Kross::KexiDB::DriverManager::lookupByMime::String");
121
Kross::Api::Object* KexiDBDriverManager::connectionData(Kross::Api::List*)
123
return new KexiDBConnectionData( new ::KexiDB::ConnectionData() );
126
Kross::Api::Object* KexiDBDriverManager::field(Kross::Api::List*)
128
return new KexiDBField( new ::KexiDB::Field() );
131
Kross::Api::Object* KexiDBDriverManager::tableSchema(Kross::Api::List* args)
133
return new KexiDBTableSchema(
134
new ::KexiDB::TableSchema(Kross::Api::Variant::toString(args->item(0)))
138
Kross::Api::Object* KexiDBDriverManager::querySchema(Kross::Api::List*)
140
return new KexiDBQuerySchema( new ::KexiDB::QuerySchema() );