File indexing completed on 2024-04-21 15:29:53

0001 /* This file is part of the KDE project
0002    Copyright (C) 2008 Sharan Rao <sharanrao@gmail.com>
0003 
0004    This program is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This program is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this program; see the file COPYING.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017 * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #include "XbaseDriver.h"
0021 
0022 #include "KDbConnection.h"
0023 #include "KDbDriverManager.h"
0024 #include "KDbDriverBehavior.h"
0025 #include "KDb.h"
0026 
0027 
0028 #include "XbaseConnection.h"
0029 
0030 KDB_DRIVER_PLUGIN_FACTORY(xBaseDriver, "kdb_xbasedriver.json")
0031 
0032 class KDbxBaseDriverPrivate {
0033 
0034 public:
0035   xBaseDriverPrivate()
0036     : internalDriver(0)
0037   {
0038   }
0039 
0040   KDbDriver* internalDriver;
0041 
0042 };
0043 
0044 xBaseDriver::xBaseDriver(QObject *parent, const QVariantList &args)
0045   : KDbDriver(parent, args)
0046   ,dp( new xBaseDriverPrivate() )
0047 {
0048   KDbDriverManager manager;
0049   dp->internalDriver = manager.driver(KDb::defaultFileBasedDriverId());
0050 
0051 //  d->isFileDriver = true ;
0052   beh->features = SingleTransactions | CursorForward;
0053 
0054   // Everything below is for the SQLite (default file based) driver
0055 
0056   //special method for autoincrement definition
0057   beh->SPECIAL_AUTO_INCREMENT_DEF = true;
0058   beh->AUTO_INCREMENT_FIELD_OPTION = ""; //not available
0059   beh->AUTO_INCREMENT_TYPE = "INTEGER";
0060   beh->AUTO_INCREMENT_PK_FIELD_OPTION = "PRIMARY KEY";
0061   beh->AUTO_INCREMENT_REQUIRES_PK = true;
0062   beh->ROW_ID_FIELD_NAME = "OID";
0063   beh->IS_DB_OPEN_AFTER_CREATE = true;
0064 
0065   beh->OPENING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER = '"';
0066   beh->CLOSING_QUOTATION_MARK_BEGIN_FOR_IDENTIFIER = '"';
0067   beh->SELECT_1_SUBQUERY_SUPPORTED = true;
0068 
0069   // As we provide a wrapper over SQLite, this aspect will be hidden by SQLite to us.
0070   beh->_1ST_ROW_READ_AHEAD_REQUIRED_TO_KNOW_IF_THE_RESULT_IS_EMPTY=false;
0071 
0072   initDriverSpecificKeywords(keywords);
0073 
0074   // Ditto like SQLite , as it won't matter
0075   beh->typeNames[KDbField::Byte]="Byte";
0076   beh->typeNames[KDbField::ShortInteger]="ShortInteger";
0077   beh->typeNames[KDbField::Integer]="Integer";
0078   beh->typeNames[KDbField::BigInteger]="BigInteger";
0079   beh->typeNames[KDbField::Boolean]="Boolean";
0080   beh->typeNames[KDbField::Date]="Date";
0081   beh->typeNames[KDbField::DateTime]="DateTime";
0082   beh->typeNames[KDbField::Time]="Time";
0083   beh->typeNames[KDbField::Float]="Float";
0084   beh->typeNames[KDbField::Double]="Double";
0085   beh->typeNames[KDbField::Text]="Text";
0086   beh->typeNames[KDbField::LongText]="CLOB";
0087   beh->typeNames[KDbField::BLOB]="BLOB";
0088 }
0089 
0090 xBaseDriver::~xBaseDriver()
0091 {
0092   delete dp;
0093 }
0094 
0095 KDbConnection* xBaseDriver::drv_createConnection(const KDbConnectionData& connData,
0096                                                  const KDbConnectionOptions &options)
0097 {
0098     if ( !dp->internalDriver ) {
0099         return nullptr;
0100     }
0101     return new xBaseConnection(this, dp->internalDriver, connData, options);
0102 }
0103 
0104 bool xBaseDriver::isSystemObjectName( const QString& n ) const
0105 {
0106   if ( !dp->internalDriver ) {
0107     return false;
0108   }
0109   return dp->internalDriver->isSystemObjectName(n);
0110 }
0111 
0112 bool xBaseDriver::isSystemDatabaseName(const QString& n) const
0113 {
0114     Q_UNUSED(n);
0115     return false;
0116 }
0117 
0118 bool xBaseDriver::drv_isSystemFieldName( const QString& n ) const
0119 {
0120   if ( !dp->internalDriver ) {
0121     return false;
0122   }
0123   return dp->internalDriver->isSystemFieldName(n);
0124 }
0125 
0126 KDbEscapedString xBaseDriver::escapeString(const QString& str) const
0127 {
0128   if ( !dp->internalDriver ) {
0129     return KDbEscapedString("'") + str + '\'';
0130   }
0131   return dp->internalDriver->escapeString(str);
0132 }
0133 
0134 KDbEscapedString xBaseDriver::escapeString(const QByteArray& str) const
0135 {
0136   if ( !dp->internalDriver ) {
0137     return KDbEscapedString("'") + str + '\'';
0138   }
0139   return dp->internalDriver->escapeString(str);
0140 }
0141 
0142 KDbEscapedString xBaseDriver::escapeBLOB(const QByteArray& array) const
0143 {
0144   if ( !dp->internalDriver ) {
0145     return array;
0146   }
0147   return dp->internalDriver->escapeBLOB(array);
0148 }
0149 
0150 QByteArray xBaseDriver::drv_escapeIdentifier( const QString& str) const
0151 {
0152   if ( !dp->internalDriver ) {
0153     return str;
0154   }
0155   return dp->internalDriver->escapeIdentifier(str);
0156 }
0157 
0158 QByteArray xBaseDriver::drv_escapeIdentifier( const QByteArray& str) const
0159 {
0160   if ( !dp->internalDriver ) {
0161     return str;
0162   }
0163   return dp->internalDriver->escapeIdentifier(str);
0164 }