kexi

driver.h

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 #ifndef KEXIDB_DRIVER_H
00021 #define KEXIDB_DRIVER_H
00022 
00023 #include <qobject.h>
00024 #include <qdatetime.h>
00025 #include <qdict.h>
00026 
00027 #include <kexidb/object.h>
00028 #include <kexidb/field.h>
00029 
00030 class KService;
00031 
00032 namespace KexiDB {
00033 
00034 class Connection;
00035 class ConnectionData;
00036 class ConnectionInternal;
00037 class DriverManager;
00038 class DriverBehaviour;
00039 class DriverPrivate;
00040 
00042 
00064 class KEXI_DB_EXPORT Driver : public QObject, public KexiDB::Object
00065 {
00066     Q_OBJECT
00067     public:
00070         class Info {
00071             public:
00072             Info() : fileBased(false) {}
00073             QString name, caption, comment, fileDBMimeType;
00074             bool fileBased : 1;
00075         };
00076         typedef QMap<QString,Info> InfoMap;
00077         
00079         enum Features {
00080             NoFeatures = 0,
00082             SingleTransactions = 1,   
00085             MultipleTransactions = 2, 
00086 //(js) NOT YET IN USE:
00089             NestedTransactions = 4,
00092             CursorForward = 8, 
00094             CursorBackward = (CursorForward+16),
00095             //-- temporary options: can be removed later, use at your own risk --
00101             IgnoreTransactions = 1024
00102         };
00103 
00105         enum CreateConnectionOptions {
00106             ReadOnlyConnection = 1 
00107         };
00108         
00109         virtual ~Driver();
00110 
00116         Connection *createConnection( ConnectionData &conn_data, int options = 0 );
00117 
00119         const QPtrList<Connection> connectionsList() const;
00120 
00121 //      /*! \return a name equal to the service name (X-Kexi-DriverName) 
00122 //       stored in given service .desktop file. */
00123 //      QString driverName() { return m_driverName; }
00124 
00130         QString fileDBDriverMimeType() const;
00131 
00134         static QString defaultFileBasedDriverMimeType();
00135 
00137         static QString defaultFileBasedDriverName();
00138 
00140         const KService* service() const;
00141 
00143         bool isFileDriver() const;
00144 
00154         virtual bool isSystemObjectName( const QString& n ) const;
00155 
00159         static bool isKexiDBSystemObjectName( const QString& n );
00160 
00167         virtual bool isSystemDatabaseName( const QString& n ) const = 0;
00168 
00175         bool isSystemFieldName( const QString& n ) const;
00176 
00179         int features() const;
00180 
00183         bool transactionsSupported() const;
00184         
00186         virtual QString sqlTypeName(int id_t, int p=0) const;
00187 
00189         static QString defaultSQLTypeName(int id_t);
00190 
00196         virtual bool isValid();
00197     
00200         virtual int versionMajor() const = 0;
00201 
00202         virtual int versionMinor() const = 0;
00203 
00210         virtual QString valueToSQL( uint ftype, const QVariant& v ) const;
00211         
00213         inline QString valueToSQL( const QString& ftype, const QVariant& v ) const {
00214             return valueToSQL(Field::typeForString(ftype), v);
00215         }
00216 
00218         inline QString valueToSQL( const Field *field, const QVariant& v ) const {
00219             return valueToSQL( (field ? field->type() : Field::InvalidType), v );
00220         }
00221 
00223         inline virtual QString dateTimeToSQL(const QDateTime& v) const {
00224 
00231 //old           const QDateTime dt( v.toDateTime() );
00232 //old           return QString("\'")+dt.date().toString(Qt::ISODate)+" "+dt.time().toString(Qt::ISODate)+"\'";
00233             return QString("\'")+v.toString(Qt::ISODate)+"\'";
00234         }
00235 
00240         virtual QString escapeString( const QString& str ) const = 0;
00241         
00245         virtual QCString escapeString( const QCString& str ) const = 0;
00246         
00251         virtual QString escapeBLOB(const QByteArray& array) const = 0;
00252 
00253 //todo enum EscapeType { EscapeDriver = 0x00, EscapeKexi = 0x01};
00254 //todo enum EscapePolicy { EscapeAsNecessary = 0x00, EscapeAlways = 0x02 };
00255 
00256         enum EscapeType { EscapeDriver = 0x01, EscapeKexi = 0x02};
00257         
00258         enum EscapePolicy { EscapeAsNecessary = 0x04, EscapeAlways = 0x08 };
00259 
00261 
00266         QString escapeIdentifier( const QString& str, 
00267             int options = EscapeDriver|EscapeAsNecessary) const;
00268 
00269         QCString escapeIdentifier( const QCString& str, 
00270             int options = EscapeDriver|EscapeAsNecessary) const;
00271 
00274         QVariant propertyValue( const QCString& propName ) const;
00275 
00278         QString propertyCaption( const QCString& propName ) const;
00279 
00281         QValueList<QCString> propertyNames() const;
00282 
00283     protected:
00294         Driver( QObject *parent, const char *name, const QStringList &args = QStringList() );
00295 
00300         virtual Connection *drv_createConnection( ConnectionData &conn_data ) = 0;
00301 //virtual ConnectionInternal* createConnectionInternalObject( Connection& conn ) = 0;
00302 
00310         virtual QString drv_escapeIdentifier( const QString& str ) const = 0;
00311         
00315         virtual QCString drv_escapeIdentifier( const QCString& str ) const = 0;
00316         
00321         virtual bool drv_isSystemFieldName( const QString& n ) const = 0;
00322         
00327         Connection* removeConnection( Connection *conn );
00328 
00335         QString escapeBLOBInternal(const QByteArray& array, int type) const;
00336 
00337     friend class Connection;
00338     friend class Cursor;
00339     friend class DriverManagerInternal;
00340 
00341 
00346     void initSQLKeywords(int hashSize = 17);
00347 
00348     DriverBehaviour *beh;
00349     DriverPrivate *d;
00350 };
00351 
00352 } //namespace KexiDB
00353 
00356 #define KEXIDB_DRIVER \
00357     public: \
00358     virtual int versionMajor() const; \
00359     virtual int versionMinor() const;
00360 
00361 #endif
00362 
KDE Home | KDE Accessibility Home | Description of Access Keys