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 
00024 #include "sqlite.h"
00025 #include "sqlitedriver.h"
00026 #include "sqliteconnection.h"
00027 #include "sqliteconnection_p.h"
00028 
00029 #include <kdebug.h>
00030 
00031 using namespace KexiDB;
00032 
00033 #ifdef SQLITE2
00034 KEXIDB_DRIVER_INFO( SQLiteDriver, sqlite2 )
00035 #else
00036 KEXIDB_DRIVER_INFO( SQLiteDriver, sqlite3 )
00037 #endif
00038 
00041 class KexiDB::SQLiteDriverPrivate 
00042 {
00043     public:
00044         SQLiteDriverPrivate()
00045         {
00046         }
00047 };
00048 
00049 //PgSqlDB::PgSqlDB(QObject *parent, const char *name, const QStringList &) 
00050 SQLiteDriver::SQLiteDriver( QObject *parent, const char *name, const QStringList &args )
00051     : Driver( parent, name, args )
00052     ,dp( new SQLiteDriverPrivate() )
00053 {
00054     d->isFileDriver = true;
00055     d->isDBOpenedAfterCreate = true;
00056     d->features = SingleTransactions | CursorForward;
00057     
00058     //special method for autoincrement definition
00059     beh->SPECIAL_AUTO_INCREMENT_DEF = true;
00060     beh->AUTO_INCREMENT_FIELD_OPTION = ""; //not available
00061     beh->AUTO_INCREMENT_TYPE = "INTEGER";
00062     beh->AUTO_INCREMENT_PK_FIELD_OPTION = "PRIMARY KEY";
00063     beh->AUTO_INCREMENT_REQUIRES_PK = true;
00064     beh->ROW_ID_FIELD_NAME = "OID";
00065     beh->_1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY=true;
00066     beh->QUOTATION_MARKS_FOR_IDENTIFIER='"';
00067     beh->SELECT_1_SUBQUERY_SUPPORTED = true;
00068     beh->SQL_KEYWORDS = keywords;
00069     initSQLKeywords(29);
00070 
00071     //predefined properties
00072     d->properties["client_library_version"] = sqlite_libversion();
00073     d->properties["default_server_encoding"] = 
00074 #ifdef SQLITE2
00075         sqlite_libencoding();
00076 #else //SQLITE3
00077         "UTF8"; //OK?
00078 #endif
00079 
00080     d->typeNames[Field::Byte]="Byte";
00081     d->typeNames[Field::ShortInteger]="ShortInteger";
00082     d->typeNames[Field::Integer]="Integer";
00083     d->typeNames[Field::BigInteger]="BigInteger";
00084     d->typeNames[Field::Boolean]="Boolean";
00085     d->typeNames[Field::Date]="Date";
00086     d->typeNames[Field::DateTime]="DateTime";
00087     d->typeNames[Field::Time]="Time";
00088     d->typeNames[Field::Float]="Float";
00089     d->typeNames[Field::Double]="Double";
00090     d->typeNames[Field::Text]="Text";
00091     d->typeNames[Field::LongText]="CLOB";
00092     d->typeNames[Field::BLOB]="BLOB";
00093 }
00094 
00095 SQLiteDriver::~SQLiteDriver()
00096 {
00097     delete dp;
00098 }
00099 
00100 
00101 KexiDB::Connection* 
00102 SQLiteDriver::drv_createConnection( ConnectionData &conn_data )
00103 {
00104     return new SQLiteConnection( this, conn_data );
00105 }
00106 
00107 bool SQLiteDriver::isSystemObjectName( const QString& n ) const
00108 {
00109     return Driver::isSystemObjectName(n) || n.lower().startsWith("sqlite_");
00110 }
00111 
00112 bool SQLiteDriver::drv_isSystemFieldName( const QString& n ) const
00113 {
00114     return n.lower()=="_rowid_"
00115         || n.lower()=="rowid"
00116         || n.lower()=="oid";
00117 }
00118 
00119 QString SQLiteDriver::escapeString(const QString& str) const
00120 {
00121     return QString("'")+QString(str).replace( '\'', "''" ) + "'";
00122 }
00123 
00124 QCString SQLiteDriver::escapeString(const QCString& str) const
00125 {
00126     return QCString("'")+QCString(str).replace( '\'', "''" )+"'";
00127 }
00128 
00129 QString SQLiteDriver::escapeBLOB(const QByteArray& array) const
00130 {
00131     return escapeBLOBInternal(array, BLOB_ESCAPING_TYPE_USE_X);
00132 }
00133 
00134 QString SQLiteDriver::drv_escapeIdentifier( const QString& str) const
00135 {
00136     return QString(str).replace( '"', "\"\"" );
00137 }
00138 
00139 QCString SQLiteDriver::drv_escapeIdentifier( const QCString& str) const
00140 {
00141     return QCString(str).replace( '"', "\"\"" );
00142 }
00143 
00144 #include "sqlitedriver.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys