[196] | 1 | /****************************************************************************
|
---|
| 2 | ** $Id: qsqldriverplugin.cpp 2051 2007-02-21 10:04:20Z chehrlic $
|
---|
| 3 | **
|
---|
| 4 | ** Implementation of QSqlDriverPlugin class
|
---|
| 5 | **
|
---|
| 6 | ** Created : 2001-09-20
|
---|
| 7 | **
|
---|
| 8 | ** Copyright (C) 2001-2007 Trolltech ASA. All rights reserved.
|
---|
| 9 | **
|
---|
| 10 | ** This file is part of the sql module of the Qt GUI Toolkit.
|
---|
| 11 | **
|
---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
---|
| 13 | ** as defined by Trolltech ASA of Norway and appearing in the file
|
---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
| 15 | **
|
---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 19 | ** packaging of this file.
|
---|
| 20 | **
|
---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
| 23 | ** Agreement provided with the Software.
|
---|
| 24 | **
|
---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 27 | **
|
---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
| 29 | ** information about Qt Commercial License Agreements.
|
---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
| 32 | **
|
---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
| 34 | ** not clear to you.
|
---|
| 35 | **
|
---|
| 36 | **********************************************************************/
|
---|
| 37 |
|
---|
| 38 | #include "qsqldriverplugin.h"
|
---|
| 39 |
|
---|
| 40 | #ifndef QT_NO_SQL
|
---|
| 41 | #ifndef QT_NO_COMPONENT
|
---|
| 42 |
|
---|
| 43 | #include "qsqldriverinterface_p.h"
|
---|
| 44 |
|
---|
| 45 | /*!
|
---|
| 46 | \class QSqlDriverPlugin qsqldriverplugin.h
|
---|
| 47 | \brief The QSqlDriverPlugin class provides an abstract base for custom QSqlDriver plugins.
|
---|
| 48 |
|
---|
| 49 | \ingroup plugins
|
---|
| 50 | \mainclass
|
---|
| 51 |
|
---|
| 52 | The SQL driver plugin is a simple plugin interface that makes it
|
---|
| 53 | easy to create your own SQL driver plugins that can be loaded
|
---|
| 54 | dynamically by Qt.
|
---|
| 55 |
|
---|
| 56 | Writing a SQL plugin is achieved by subclassing this base class,
|
---|
| 57 | reimplementing the pure virtual functions keys() and create(), and
|
---|
| 58 | exporting the class with the \c Q_EXPORT_PLUGIN macro. See the SQL
|
---|
| 59 | plugins that come with Qt for example implementations (in the
|
---|
| 60 | \c{plugins/src/sqldrivers} subdirectory of the source
|
---|
| 61 | distribution). Read the \link plugins-howto.html plugins
|
---|
| 62 | documentation\endlink for more information on plugins.
|
---|
| 63 | */
|
---|
| 64 |
|
---|
| 65 | /*!
|
---|
| 66 | \fn QStringList QSqlDriverPlugin::keys() const
|
---|
| 67 |
|
---|
| 68 | Returns the list of drivers (keys) this plugin supports.
|
---|
| 69 |
|
---|
| 70 | These keys are usually the class names of the custom drivers that
|
---|
| 71 | are implemented in the plugin.
|
---|
| 72 |
|
---|
| 73 | \sa create()
|
---|
| 74 | */
|
---|
| 75 |
|
---|
| 76 | /*!
|
---|
| 77 | \fn QSqlDriver* QSqlDriverPlugin::create( const QString& key )
|
---|
| 78 |
|
---|
| 79 | Creates and returns a QSqlDriver object for the driver key \a key.
|
---|
| 80 | The driver key is usually the class name of the required driver.
|
---|
| 81 |
|
---|
| 82 | \sa keys()
|
---|
| 83 | */
|
---|
| 84 |
|
---|
| 85 | class QSqlDriverPluginPrivate : public QSqlDriverFactoryInterface
|
---|
| 86 | {
|
---|
| 87 | public:
|
---|
| 88 | QSqlDriverPluginPrivate( QSqlDriverPlugin *p )
|
---|
| 89 | : plugin( p )
|
---|
| 90 | {
|
---|
| 91 | }
|
---|
| 92 | virtual ~QSqlDriverPluginPrivate();
|
---|
| 93 |
|
---|
| 94 | QRESULT queryInterface( const QUuid &iid, QUnknownInterface **iface );
|
---|
| 95 | Q_REFCOUNT;
|
---|
| 96 |
|
---|
| 97 | QStringList featureList() const;
|
---|
| 98 | QSqlDriver *create( const QString &key );
|
---|
| 99 |
|
---|
| 100 | private:
|
---|
| 101 | QSqlDriverPlugin *plugin;
|
---|
| 102 | };
|
---|
| 103 |
|
---|
| 104 | QSqlDriverPluginPrivate::~QSqlDriverPluginPrivate()
|
---|
| 105 | {
|
---|
| 106 | delete plugin;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | QRESULT QSqlDriverPluginPrivate::queryInterface( const QUuid &iid, QUnknownInterface **iface )
|
---|
| 110 | {
|
---|
| 111 | *iface = 0;
|
---|
| 112 |
|
---|
| 113 | if ( iid == IID_QUnknown )
|
---|
| 114 | *iface = this;
|
---|
| 115 | else if ( iid == IID_QFeatureList )
|
---|
| 116 | *iface = this;
|
---|
| 117 | else if ( iid == IID_QSqlDriverFactory )
|
---|
| 118 | *iface = this;
|
---|
| 119 | else
|
---|
| 120 | return QE_NOINTERFACE;
|
---|
| 121 |
|
---|
| 122 | (*iface)->addRef();
|
---|
| 123 | return QS_OK;
|
---|
| 124 | }
|
---|
| 125 |
|
---|
| 126 | QStringList QSqlDriverPluginPrivate::featureList() const
|
---|
| 127 | {
|
---|
| 128 | return plugin->keys();
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | QSqlDriver *QSqlDriverPluginPrivate::create( const QString &key )
|
---|
| 132 | {
|
---|
| 133 | return plugin->create( key );
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | /*!
|
---|
| 137 | Constructs a SQL driver plugin. This is invoked automatically by
|
---|
| 138 | the \c Q_EXPORT_PLUGIN macro.
|
---|
| 139 | */
|
---|
| 140 |
|
---|
| 141 | QSqlDriverPlugin::QSqlDriverPlugin()
|
---|
| 142 | : QGPlugin( d = new QSqlDriverPluginPrivate( this ) )
|
---|
| 143 | {
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | /*!
|
---|
| 147 | Destroys the SQL driver plugin.
|
---|
| 148 |
|
---|
| 149 | You never have to call this explicitly. Qt destroys a plugin
|
---|
| 150 | automatically when it is no longer used.
|
---|
| 151 | */
|
---|
| 152 | QSqlDriverPlugin::~QSqlDriverPlugin()
|
---|
| 153 | {
|
---|
| 154 | // don't delete d, as this is deleted by d
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | #endif // QT_NO_COMPONENT
|
---|
| 158 | #endif // QT_NO_SQL
|
---|