kexi

sqlite/sqlitedriver.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003-2004 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 <kexidb/connection.h>
21#include <kexidb/drivermanager.h>
22#include <kexidb/driver_p.h>
23#include <kexidb/utils.h>
24
25#include "sqlite.h"
26#include "sqlitedriver.h"
27#include "sqliteconnection.h"
28#include "sqliteconnection_p.h"
29#include "sqliteadmin.h"
30
31#include <kdebug.h>
32
33using namespace KexiDB;
34
35#ifdef SQLITE2
36KEXIDB_DRIVER_INFO( SQLiteDriver, sqlite2 )
37#else
38KEXIDB_DRIVER_INFO( SQLiteDriver, sqlite3 )
39#endif
40
43class KexiDB::SQLiteDriverPrivate
44{
45 public:
46 SQLiteDriverPrivate()
47 {
48 }
49};
50
51//PgSqlDB::PgSqlDB(TQObject *parent, const char *name, const TQStringList &)
52SQLiteDriver::SQLiteDriver( TQObject *parent, const char *name, const TQStringList &args )
53 : Driver( parent, name, args )
54 ,dp( new SQLiteDriverPrivate() )
55{
56 d->isFileDriver = true;
57 d->isDBOpenedAfterCreate = true;
58 d->features = SingleTransactions | CursorForward
59#ifndef SQLITE2
60 | CompactingDatabaseSupported;
61#endif
62 ;
63
64 //special method for autoincrement definition
65 beh->SPECIAL_AUTO_INCREMENT_DEF = true;
66 beh->AUTO_INCREMENT_FIELD_OPTION = ""; //not available
67 beh->AUTO_INCREMENT_TYPE = "INTEGER";
68 beh->AUTO_INCREMENT_PK_FIELD_OPTION = "PRIMARY KEY";
69 beh->AUTO_INCREMENT_REQUIRES_PK = true;
70 beh->ROW_ID_FIELD_NAME = "OID";
71 beh->_1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY=true;
72 beh->QUOTATION_MARKS_FOR_IDENTIFIER='"';
73 beh->SELECT_1_SUBQUERY_SUPPORTED = true;
74 beh->SQL_KEYWORDS = keywords;
75 initSQLKeywords(29);
76
77 //predefined properties
78 d->properties["client_library_version"] = sqlite_libversion();
79 d->properties["default_server_encoding"] =
80#ifdef SQLITE2
81 sqlite_libencoding();
82#else //SQLITE3
83 "UTF8"; //OK?
84#endif
85
86 d->typeNames[Field::Byte]="Byte";
87 d->typeNames[Field::ShortInteger]="ShortInteger";
88 d->typeNames[Field::Integer]="Integer";
89 d->typeNames[Field::BigInteger]="BigInteger";
90 d->typeNames[Field::Boolean]="Boolean";
91 d->typeNames[Field::Date]="Date"; // In fact date/time types could be declared as datetext etc.
92 d->typeNames[Field::DateTime]="DateTime"; // to force text affinity..., see http://sqlite.org/datatype3.html
93 d->typeNames[Field::Time]="Time"; //
94 d->typeNames[Field::Float]="Float";
95 d->typeNames[Field::Double]="Double";
96 d->typeNames[Field::Text]="Text";
97 d->typeNames[Field::LongText]="CLOB";
98 d->typeNames[Field::BLOB]="BLOB";
99}
100
101SQLiteDriver::~SQLiteDriver()
102{
103 delete dp;
104}
105
106
107KexiDB::Connection*
109{
110 return new SQLiteConnection( this, conn_data );
111}
112
113bool SQLiteDriver::isSystemObjectName( const TQString& n ) const
114{
115 return Driver::isSystemObjectName(n) || n.lower().startsWith("sqlite_");
116}
117
118bool SQLiteDriver::drv_isSystemFieldName( const TQString& n ) const
119{
120 return n.lower()=="_rowid_"
121 || n.lower()=="rowid"
122 || n.lower()=="oid";
123}
124
125TQString SQLiteDriver::escapeString(const TQString& str) const
126{
127 return TQString("'")+TQString(str).replace( '\'', "''" ) + "'";
128}
129
130TQCString SQLiteDriver::escapeString(const TQCString& str) const
131{
132 return TQCString("'")+TQCString(str).replace( '\'', "''" )+"'";
133}
134
135TQString SQLiteDriver::escapeBLOB(const TQByteArray& array) const
136{
138}
139
140TQString SQLiteDriver::drv_escapeIdentifier( const TQString& str) const
141{
142 return TQString(str).replace( '"', "\"\"" );
143}
144
145TQCString SQLiteDriver::drv_escapeIdentifier( const TQCString& str) const
146{
147 return TQCString(str).replace( '"', "\"\"" );
148}
149
150AdminTools* SQLiteDriver::drv_createAdminTools() const
151{
152#ifdef SQLITE2
153 return new AdminTools(); //empty impl.
154#else
155 return new SQLiteAdminTools();
156#endif
157}
158
159#include "sqlitedriver.moc"
An interface containing a set of tools for database administration.
Definition admin.h:34
Database specific connection data, e.g. host, port.
Generic database abstraction.
Definition driver.h:67
bool isFileDriver() const
Definition driver.cpp:149
virtual bool isSystemObjectName(const TQString &n) const
Definition driver.cpp:230
@ ShortInteger
Definition field.h:86
sqlite-specific connection
SQLite database driver.
virtual bool drv_isSystemFieldName(const TQString &n) const
virtual bool isSystemObjectName(const TQString &n) const
virtual TQString escapeBLOB(const TQByteArray &array) const
Escape BLOB value array.
virtual TQString escapeString(const TQString &str) const
Escape a string for use as a value.
virtual Connection * drv_createConnection(ConnectionData &conn_data)
virtual TQString drv_escapeIdentifier(const TQString &str) const
An interface containing a set of tools for SQLite database administration.
High-level database connectivity library with database backend drivers.
KEXI_DB_EXPORT TQString escapeBLOB(const TQByteArray &array, BLOBEscapingType type)
@ BLOBEscapeXHex
escaping like X'1FAD', used by sqlite (hex numbers)