~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kexi/scripting/kexidb/kexidbdriver.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 * kexidbdriver.cpp
3
 
 * This file is part of the KDE project
4
 
 * copyright (C)2004-2005 by Sebastian Sauer (mail@dipe.org)
5
 
 *
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
 
 ***************************************************************************/
19
 
 
20
 
#include "kexidbdriver.h"
21
 
#include "kexidbdrivermanager.h"
22
 
 
23
 
#include "kexidbconnection.h"
24
 
#include "kexidbconnectiondata.h"
25
 
 
26
 
#include <qvaluelist.h>
27
 
#include <klocale.h>
28
 
#include <kdebug.h>
29
 
 
30
 
#include <kexidb/connection.h>
31
 
 
32
 
using namespace Kross::KexiDB;
33
 
 
34
 
KexiDBDriver::KexiDBDriver(KexiDBDriverManager* drivermanager, ::KexiDB::Driver* driver)
35
 
    : Kross::Api::Class<KexiDBDriver>("KexiDBDriver", drivermanager)
36
 
    , m_driver(driver)
37
 
{
38
 
    addFunction("versionMajor", &KexiDBDriver::versionMajor,
39
 
        Kross::Api::ArgumentList(),
40
 
        i18n("Return the major version number of this driver.")
41
 
    );
42
 
    addFunction("versionMinor", &KexiDBDriver::versionMinor,
43
 
        Kross::Api::ArgumentList(),
44
 
        i18n("Return the minor version number of this driver.")
45
 
    );
46
 
 
47
 
    addFunction("escapeString", &KexiDBDriver::escapeString,
48
 
        Kross::Api::ArgumentList() << Kross::Api::Argument("Kross::Api::Variant::String"),
49
 
        i18n("Return a driver-specific escaped SQL string.")
50
 
    );
51
 
    addFunction("valueToSQL", &KexiDBDriver::valueToSQL,
52
 
        Kross::Api::ArgumentList()
53
 
            << Kross::Api::Argument("Kross::Api::Variant::String")
54
 
            << Kross::Api::Argument("Kross::Api::Variant"),
55
 
        i18n("Return the escaped and convert as second argument passed "
56
 
             "Variant value to the as first argument passed "
57
 
             "KexiDBField::type.")
58
 
    );
59
 
 
60
 
    addFunction("createConnection", &KexiDBDriver::createConnection,
61
 
        Kross::Api::ArgumentList() << Kross::Api::Argument("Kross::KexiDB::KexiDBConnectionData"),
62
 
        i18n("Create a new KexiDBConnection object and return it.")
63
 
    );
64
 
    addFunction("connectionList", &KexiDBDriver::connectionList,
65
 
        Kross::Api::ArgumentList(),
66
 
        i18n("Return a list of KexiDBConnection objects.")
67
 
    );
68
 
}
69
 
 
70
 
KexiDBDriver::~KexiDBDriver()
71
 
{
72
 
}
73
 
 
74
 
const QString KexiDBDriver::getClassName() const
75
 
{
76
 
    return "Kross::KexiDB::KexiDBDriver";
77
 
}
78
 
 
79
 
const QString KexiDBDriver::getDescription() const
80
 
{
81
 
    return i18n("KexiDB::Driver wrapper to access the generic "
82
 
                "database abstraction functionality KexiDB spends.");
83
 
}
84
 
 
85
 
::KexiDB::Driver* KexiDBDriver::driver()
86
 
{
87
 
    if(! m_driver)
88
 
        throw Kross::Api::RuntimeException(i18n("KexiDB::Driver is NULL."));
89
 
    if(m_driver->error())
90
 
        throw Kross::Api::RuntimeException(i18n("KexiDB::Driver error: %1").arg(m_driver->errorMsg()));
91
 
    return m_driver;
92
 
}
93
 
 
94
 
Kross::Api::Object* KexiDBDriver::versionMajor(Kross::Api::List*)
95
 
{
96
 
    return Kross::Api::Variant::create(driver()->versionMajor(),
97
 
           "Kross::KexiDB::Driver::versionMajor::Int");
98
 
}
99
 
 
100
 
Kross::Api::Object* KexiDBDriver::versionMinor(Kross::Api::List*)
101
 
{
102
 
    return Kross::Api::Variant::create(driver()->versionMinor(),
103
 
           "Kross::KexiDB::Driver::versionMinor::Int");
104
 
}
105
 
 
106
 
Kross::Api::Object* KexiDBDriver::createConnection(Kross::Api::List* args)
107
 
{
108
 
    KexiDBConnectionData* data =
109
 
        Kross::Api::Object::fromObject<KexiDBConnectionData>(args->item(0));
110
 
    QGuardedPtr< ::KexiDB::Connection > connection = driver()->createConnection( *(data->getConnectionData()) );
111
 
    if(! connection)
112
 
        throw Kross::Api::RuntimeException("Failed to create connection.");
113
 
    return new KexiDBConnection(this, connection, data);
114
 
}
115
 
 
116
 
Kross::Api::Object* KexiDBDriver::connectionList(Kross::Api::List*)
117
 
{
118
 
    QValueList<Object*> list;
119
 
    QPtrList< ::KexiDB::Connection > connectionlist = driver()->connectionsList();
120
 
    ::KexiDB::Connection* connection;
121
 
    for(connection = connectionlist.first(); connection; connection = connectionlist.next())
122
 
        list.append( new KexiDBConnection(this, connection) );
123
 
    return Kross::Api::List::create(list,
124
 
           "Kross::KexiDB::Driver::connectionList::List");
125
 
}
126
 
 
127
 
Kross::Api::Object* KexiDBDriver::escapeString(Kross::Api::List* args)
128
 
{
129
 
    return Kross::Api::Variant::create(
130
 
           driver()->escapeString( Kross::Api::Variant::toString(args->item(0)) ),
131
 
           "Kross::KexiDB::DriverManager::escapeString::String");
132
 
}
133
 
 
134
 
Kross::Api::Object* KexiDBDriver::valueToSQL(Kross::Api::List* args)
135
 
{
136
 
    return Kross::Api::Variant::create(
137
 
           driver()->valueToSQL(
138
 
               (uint)::KexiDB::Field::typeForString(Kross::Api::Variant::toString(args->item(0))),
139
 
               Kross::Api::Variant::toVariant(args->item(1))
140
 
           ),
141
 
           "Kross::KexiDB::DriverManager::valueToSQL::String");
142
 
}
143