kexi

sqlitedriver.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003-2004 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This program is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this program; see the file COPYING.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <kexidb/connection.h>
00021 #include <kexidb/drivermanager.h>
00022 #include <kexidb/driver_p.h>
00023 #include <kexidb/utils.h>
00024 
00025 #include "sqlite.h"
00026 #include "sqlitedriver.h"
00027 #include "sqliteconnection.h"
00028 #include "sqliteconnection_p.h"
00029 #include "sqliteadmin.h"
00030 
00031 #include <kdebug.h>
00032 
00033 using namespace KexiDB;
00034 
00035 #ifdef SQLITE2
00036 KEXIDB_DRIVER_INFO( SQLiteDriver, sqlite2 )
00037 #else
00038 KEXIDB_DRIVER_INFO( SQLiteDriver, sqlite3 )
00039 #endif
00040 
00043 class KexiDB::SQLiteDriverPrivate 
00044 {
00045     public:
00046         SQLiteDriverPrivate()
00047         {
00048         }
00049 };
00050 
00051 //PgSqlDB::PgSqlDB(QObject *parent, const char *name, const QStringList &) 
00052 SQLiteDriver::SQLiteDriver( QObject *parent, const char *name, const QStringList &args )
00053     : Driver( parent, name, args )
00054     ,dp( new SQLiteDriverPrivate() )
00055 {
00056     d->isFileDriver = true;
00057     d->isDBOpenedAfterCreate = true;
00058     d->features = SingleTransactions | CursorForward
00059 #ifndef SQLITE2
00060         | CompactingDatabaseSupported;
00061 #endif
00062     ;
00063     
00064     //special method for autoincrement definition
00065     beh->SPECIAL_AUTO_INCREMENT_DEF = true;
00066     beh->AUTO_INCREMENT_FIELD_OPTION = ""; //not available
00067     beh->AUTO_INCREMENT_TYPE = "INTEGER";
00068     beh->AUTO_INCREMENT_PK_FIELD_OPTION = "PRIMARY KEY";
00069     beh->AUTO_INCREMENT_REQUIRES_PK = true;
00070     beh->ROW_ID_FIELD_NAME = "OID";
00071     beh->_1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY=true;
00072     beh->QUOTATION_MARKS_FOR_IDENTIFIER='"';
00073     beh->SELECT_1_SUBQUERY_SUPPORTED = true;
00074     beh->SQL_KEYWORDS = keywords;
00075     initSQLKeywords(29);
00076 
00077     //predefined properties
00078     d->properties["client_library_version"] = sqlite_libversion();
00079     d->properties["default_server_encoding"] = 
00080 #ifdef SQLITE2
00081         sqlite_libencoding();
00082 #else //SQLITE3
00083         "UTF8"; //OK?
00084 #endif
00085 
00086     d->typeNames[Field::Byte]="Byte";
00087     d->typeNames[Field::ShortInteger]="ShortInteger";
00088     d->typeNames[Field::Integer]="Integer";
00089     d->typeNames[Field::BigInteger]="BigInteger";
00090     d->typeNames[Field::Boolean]="Boolean";
00091     d->typeNames[Field::Date]="Date";         // In fact date/time types could be declared as datetext etc. 
00092     d->typeNames[Field::DateTime]="DateTime"; // to force text affinity..., see http://sqlite.org/datatype3.html
00093     d->typeNames[Field::Time]="Time";         //
00094     d->typeNames[Field::Float]="Float";
00095     d->typeNames[Field::Double]="Double";
00096     d->typeNames[Field::Text]="Text";
00097     d->typeNames[Field::LongText]="CLOB";
00098     d->typeNames[Field::BLOB]="BLOB";
00099 }
00100 
00101 SQLiteDriver::~SQLiteDriver()
00102 {
00103     delete dp;
00104 }
00105 
00106 
00107 KexiDB::Connection* 
00108 SQLiteDriver::drv_createConnection( ConnectionData &conn_data )
00109 {
00110     return new SQLiteConnection( this, conn_data );
00111 }
00112 
00113 bool SQLiteDriver::isSystemObjectName( const QString& n ) const
00114 {
00115     return Driver::isSystemObjectName(n) || n.lower().startsWith("sqlite_");
00116 }
00117 
00118 bool SQLiteDriver::drv_isSystemFieldName( const QString& n ) const
00119 {
00120     return n.lower()=="_rowid_"
00121         || n.lower()=="rowid"
00122         || n.lower()=="oid";
00123 }
00124 
00125 QString SQLiteDriver::escapeString(const QString& str) const
00126 {
00127     return QString("'")+QString(str).replace( '\'', "''" ) + "'";
00128 }
00129 
00130 QCString SQLiteDriver::escapeString(const QCString& str) const
00131 {
00132     return QCString("'")+QCString(str).replace( '\'', "''" )+"'";
00133 }
00134 
00135 QString SQLiteDriver::escapeBLOB(const QByteArray& array) const
00136 {
00137     return KexiDB::escapeBLOB(array, KexiDB::BLOBEscapeXHex);
00138 }
00139 
00140 QString SQLiteDriver::drv_escapeIdentifier( const QString& str) const
00141 {
00142     return QString(str).replace( '"', "\"\"" );
00143 }
00144 
00145 QCString SQLiteDriver::drv_escapeIdentifier( const QCString& str) const
00146 {
00147     return QCString(str).replace( '"', "\"\"" );
00148 }
00149 
00150 AdminTools* SQLiteDriver::drv_createAdminTools() const
00151 {
00152 #ifdef SQLITE2
00153     return new AdminTools(); //empty impl.
00154 #else
00155     return new SQLiteAdminTools();
00156 #endif
00157 }
00158 
00159 #include "sqlitedriver.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys