~smartboyhw/ubuntu/raring/calligra/2.6.0-0ubuntu1

« back to all changes in this revision

Viewing changes to libs/db/drivers/sqlite/sqlitedriver.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-10-23 21:09:16 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20121023210916-m82w6zxnxhaxz7va
Tags: 1:2.5.90-0ubuntu1
* New upstream alpha release (LP: #1070436)
  - Add libkactivities-dev and libopenimageio-dev to build-depends
  - Add kubuntu_build_calligraactive.diff to build calligraactive by default
  - Add package for calligraauthor and move files that are shared between
    calligrawords and calligraauthor to calligrawords-common
* Document the patches
* Remove numbers from patches so they follow the same naming scheme as
  the rest of our patches.
* calligra-data breaks replaces krita-data (<< 1:2.5.3) (LP: #1071686)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2003-2011 Jarosław Staniek <staniek@kde.org>
 
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 <db/connection.h>
 
21
#include <db/drivermanager.h>
 
22
#include <db/driver_p.h>
 
23
#include <db/utils.h>
 
24
 
 
25
#include "sqlite3.h"
 
26
#include "sqlitedriver.h"
 
27
#include "sqliteconnection.h"
 
28
#include "sqliteconnection_p.h"
 
29
#include "sqliteadmin.h"
 
30
 
 
31
#include <kdebug.h>
 
32
 
 
33
using namespace KexiDB;
 
34
 
 
35
K_EXPORT_KEXIDB_DRIVER(SQLiteDriver, "sqlite3")
 
36
 
 
37
//! driver specific private data
 
38
//! @internal
 
39
class KexiDB::SQLiteDriverPrivate
 
40
{
 
41
public:
 
42
    SQLiteDriverPrivate() : collate(" COLLATE ''")
 
43
    {
 
44
    }
 
45
    QString collate;
 
46
};
 
47
 
 
48
//PgSqlDB::PgSqlDB(QObject *parent, const char *name, const QStringList &)
 
49
SQLiteDriver::SQLiteDriver(QObject *parent, const QVariantList &args)
 
50
        : Driver(parent, args)
 
51
        , dp(new SQLiteDriverPrivate())
 
52
{
 
53
    d->isFileDriver = true;
 
54
    d->isDBOpenedAfterCreate = true;
 
55
    d->features = SingleTransactions | CursorForward
 
56
                  | CompactingDatabaseSupported;
 
57
 
 
58
    //special method for autoincrement definition
 
59
    beh->SPECIAL_AUTO_INCREMENT_DEF = true;
 
60
    beh->AUTO_INCREMENT_FIELD_OPTION = ""; //not available
 
61
    beh->AUTO_INCREMENT_TYPE = "INTEGER";
 
62
    beh->AUTO_INCREMENT_PK_FIELD_OPTION = "PRIMARY KEY";
 
63
    beh->AUTO_INCREMENT_REQUIRES_PK = true;
 
64
    beh->ROW_ID_FIELD_NAME = "OID";
 
65
    beh->_1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY = true;
 
66
    beh->QUOTATION_MARKS_FOR_IDENTIFIER = '"';
 
67
    beh->SELECT_1_SUBQUERY_SUPPORTED = true;
 
68
    initDriverSpecificKeywords(keywords);
 
69
 
 
70
    //predefined properties
 
71
    d->properties["client_library_version"] = sqlite3_libversion();
 
72
    d->properties["default_server_encoding"] = "UTF8"; //OK?
 
73
 
 
74
    d->typeNames[Field::Byte] = "Byte";
 
75
    d->typeNames[Field::ShortInteger] = "ShortInteger";
 
76
    d->typeNames[Field::Integer] = "Integer";
 
77
    d->typeNames[Field::BigInteger] = "BigInteger";
 
78
    d->typeNames[Field::Boolean] = "Boolean";
 
79
    d->typeNames[Field::Date] = "Date";       // In fact date/time types could be declared as datetext etc.
 
80
    d->typeNames[Field::DateTime] = "DateTime"; // to force text affinity..., see http://sqlite.org/datatype3.html
 
81
    d->typeNames[Field::Time] = "Time";       //
 
82
    d->typeNames[Field::Float] = "Float";
 
83
    d->typeNames[Field::Double] = "Double";
 
84
    d->typeNames[Field::Text] = "Text";
 
85
    d->typeNames[Field::LongText] = "CLOB";
 
86
    d->typeNames[Field::BLOB] = "BLOB";
 
87
}
 
88
 
 
89
SQLiteDriver::~SQLiteDriver()
 
90
{
 
91
    delete dp;
 
92
}
 
93
 
 
94
 
 
95
KexiDB::Connection*
 
96
SQLiteDriver::drv_createConnection(ConnectionData &conn_data)
 
97
{
 
98
    return new SQLiteConnection(this, conn_data);
 
99
}
 
100
 
 
101
bool SQLiteDriver::isSystemObjectName(const QString& n) const
 
102
{
 
103
    return Driver::isSystemObjectName(n) || n.toLower().startsWith("sqlite_");
 
104
}
 
105
 
 
106
bool SQLiteDriver::drv_isSystemFieldName(const QString& n) const
 
107
{
 
108
    QString lcName = n.toLower();
 
109
    return (lcName == "_rowid_")
 
110
           || (lcName == "rowid")
 
111
           || (lcName == "oid");
 
112
}
 
113
 
 
114
QString SQLiteDriver::escapeString(const QString& str) const
 
115
{
 
116
    return QString("'") + QString(str).replace('\'', "''") + "'";
 
117
}
 
118
 
 
119
QByteArray SQLiteDriver::escapeString(const QByteArray& str) const
 
120
{
 
121
    return QByteArray("'") + QByteArray(str).replace('\'', "''") + "'";
 
122
}
 
123
 
 
124
QString SQLiteDriver::escapeBLOB(const QByteArray& array) const
 
125
{
 
126
    return KexiDB::escapeBLOB(array, KexiDB::BLOBEscapeXHex);
 
127
}
 
128
 
 
129
QString SQLiteDriver::drv_escapeIdentifier(const QString& str) const
 
130
{
 
131
    return QString(str).replace('"', "\"\"");
 
132
}
 
133
 
 
134
QByteArray SQLiteDriver::drv_escapeIdentifier(const QByteArray& str) const
 
135
{
 
136
    return QByteArray(str).replace('"', "\"\"");
 
137
}
 
138
 
 
139
AdminTools* SQLiteDriver::drv_createAdminTools() const
 
140
{
 
141
    return new SQLiteAdminTools();
 
142
}
 
143
 
 
144
QString SQLiteDriver::collationSQL() const
 
145
{
 
146
    return dp->collate;
 
147
}
 
148
 
 
149
#include "sqlitedriver.moc"