1
/* This file is part of the KDE project
2
Copyright (C) 2003-2011 Jarosław Staniek <staniek@kde.org>
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.
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.
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.
20
#include <db/connection.h>
21
#include <db/drivermanager.h>
22
#include <db/driver_p.h>
26
#include "sqlitedriver.h"
27
#include "sqliteconnection.h"
28
#include "sqliteconnection_p.h"
29
#include "sqliteadmin.h"
33
using namespace KexiDB;
35
K_EXPORT_KEXIDB_DRIVER(SQLiteDriver, "sqlite3")
37
//! driver specific private data
39
class KexiDB::SQLiteDriverPrivate
42
SQLiteDriverPrivate() : collate(" COLLATE ''")
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())
53
d->isFileDriver = true;
54
d->isDBOpenedAfterCreate = true;
55
d->features = SingleTransactions | CursorForward
56
| CompactingDatabaseSupported;
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);
70
//predefined properties
71
d->properties["client_library_version"] = sqlite3_libversion();
72
d->properties["default_server_encoding"] = "UTF8"; //OK?
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";
89
SQLiteDriver::~SQLiteDriver()
96
SQLiteDriver::drv_createConnection(ConnectionData &conn_data)
98
return new SQLiteConnection(this, conn_data);
101
bool SQLiteDriver::isSystemObjectName(const QString& n) const
103
return Driver::isSystemObjectName(n) || n.toLower().startsWith("sqlite_");
106
bool SQLiteDriver::drv_isSystemFieldName(const QString& n) const
108
QString lcName = n.toLower();
109
return (lcName == "_rowid_")
110
|| (lcName == "rowid")
111
|| (lcName == "oid");
114
QString SQLiteDriver::escapeString(const QString& str) const
116
return QString("'") + QString(str).replace('\'', "''") + "'";
119
QByteArray SQLiteDriver::escapeString(const QByteArray& str) const
121
return QByteArray("'") + QByteArray(str).replace('\'', "''") + "'";
124
QString SQLiteDriver::escapeBLOB(const QByteArray& array) const
126
return KexiDB::escapeBLOB(array, KexiDB::BLOBEscapeXHex);
129
QString SQLiteDriver::drv_escapeIdentifier(const QString& str) const
131
return QString(str).replace('"', "\"\"");
134
QByteArray SQLiteDriver::drv_escapeIdentifier(const QByteArray& str) const
136
return QByteArray(str).replace('"', "\"\"");
139
AdminTools* SQLiteDriver::drv_createAdminTools() const
141
return new SQLiteAdminTools();
144
QString SQLiteDriver::collationSQL() const
149
#include "sqlitedriver.moc"