QSqlDatabasePrivate Class Reference

Collaboration diagram for QSqlDatabasePrivate:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 101 of file qsqldatabase.cpp.

Public Member Functions

 QSqlDatabasePrivate (QSqlDriver *dr=0)
 QSqlDatabasePrivate (const QSqlDatabasePrivate &other)
 ~QSqlDatabasePrivate ()
void init (const QString &type)
void copy (const QSqlDatabasePrivate *other)
void disable ()

Static Public Member Functions

static QSqlDatabasePrivateshared_null ()
static QSqlDatabase database (const QString &name, bool open)
static void addDatabase (const QSqlDatabase &db, const QString &name)
static void removeDatabase (const QString &name)
static void invalidateDb (const QSqlDatabase &db, const QString &name)
static DriverDictdriverDict ()
static void cleanConnections ()

Public Attributes

QAtomic ref
QSqlDriverdriver
QString dbname
QString uname
QString pword
QString hname
QString drvName
int port
QString connOptions


Constructor & Destructor Documentation

QSqlDatabasePrivate::QSqlDatabasePrivate ( QSqlDriver dr = 0  )  [inline]

Definition at line 104 of file qsqldatabase.cpp.

References ref.

00104                                            :
00105         driver(dr),
00106         port(-1)
00107     {
00108         ref = 1;
00109     }
    QSqlDatabasePrivate(const QSqlDatabasePrivate &other);

QSqlDatabasePrivate::QSqlDatabasePrivate ( const QSqlDatabasePrivate other  ) 

Definition at line 136 of file qsqldatabase.cpp.

References connOptions, dbname, driver, drvName, hname, port, pword, ref, and uname.

00137 {
00138     ref = 1;
00139     dbname = other.dbname;
00140     uname = other.uname;
00141     pword = other.pword;
00142     hname = other.hname;
00143     drvName = other.drvName;
00144     port = other.port;
00145     connOptions = other.connOptions;
00146     driver = other.driver;
00147 }

QSqlDatabasePrivate::~QSqlDatabasePrivate (  ) 

Definition at line 149 of file qsqldatabase.cpp.

References driver, and shared_null().

00150 {
00151     if (driver != shared_null()->driver)
00152         delete driver;
00153 }

Here is the call graph for this function:


Member Function Documentation

void QSqlDatabasePrivate::init ( const QString type  ) 

Definition at line 677 of file qsqldatabase.cpp.

References data, driver, driverDict(), QSqlDatabase::drivers(), drvName, qWarning(), shared_null(), and type.

Referenced by QSqlDatabase::QSqlDatabase().

00678 {
00679     drvName = type;
00680 
00681     if (!driver) {
00682 #ifdef QT_SQL_PSQL
00683         if (type == QLatin1String("QPSQL") || type == QLatin1String("QPSQL7"))
00684             driver = new QPSQLDriver();
00685 #endif
00686 #ifdef QT_SQL_MYSQL
00687         if (type == QLatin1String("QMYSQL") || type == QLatin1String("QMYSQL3"))
00688             driver = new QMYSQLDriver();
00689 #endif
00690 #ifdef QT_SQL_ODBC
00691         if (type == QLatin1String("QODBC") || type == QLatin1String("QODBC3"))
00692             driver = new QODBCDriver();
00693 #endif
00694 #ifdef QT_SQL_OCI
00695         if (type == QLatin1String("QOCI") || type == QLatin1String("QOCI8"))
00696             driver = new QOCIDriver();
00697 #endif
00698 #ifdef QT_SQL_TDS
00699         if (type == QLatin1String("QTDS") || type == QLatin1String("QTDS7"))
00700             driver = new QTDSDriver();
00701 #endif
00702 #ifdef QT_SQL_DB2
00703         if (type == QLatin1String("QDB2"))
00704             driver = new QDB2Driver();
00705 #endif
00706 #ifdef QT_SQL_SQLITE
00707         if (type == QLatin1String("QSQLITE"))
00708             driver = new QSQLiteDriver();
00709 #endif
00710 #ifdef QT_SQL_SQLITE2
00711         if (type == QLatin1String("QSQLITE2"))
00712             driver = new QSQLite2Driver();
00713 #endif
00714 #ifdef QT_SQL_IBASE
00715         if (type == QLatin1String("QIBASE"))
00716             driver = new QIBaseDriver();
00717 #endif
00718     }
00719 
00720     if (!driver) {
00721         DriverDict dict = QSqlDatabasePrivate::driverDict();
00722         for (DriverDict::const_iterator it = dict.constBegin();
00723              it != dict.constEnd() && !driver; ++it) {
00724             if (type == it.key()) {
00725                 driver = ((QSqlDriverCreatorBase*)(*it))->createObject();
00726             }
00727         }
00728     }
00729 
00730 #ifndef QT_NO_LIBRARY
00731     if (!driver && loader()) {
00732         if (QSqlDriverFactoryInterface *factory = qobject_cast<QSqlDriverFactoryInterface*>(loader()->instance(type)))
00733             driver = factory->create(type);
00734     }
00735 #endif // QT_NO_LIBRARY
00736 
00737     if (!driver) {
00738         qWarning("QSqlDatabase: %s driver not loaded", type.toLatin1().data());
00739         qWarning("QSqlDatabase: available drivers: %s",
00740                         QSqlDatabase::drivers().join(QLatin1String(" ")).toLatin1().data());
00741         driver = shared_null()->driver;
00742     }
00743 }

Here is the call graph for this function:

void QSqlDatabasePrivate::copy ( const QSqlDatabasePrivate other  ) 

Definition at line 254 of file qsqldatabase.cpp.

References connOptions, dbname, drvName, hname, port, pword, and uname.

00255 {
00256     dbname = other->dbname;
00257     uname = other->uname;
00258     pword = other->pword;
00259     hname = other->hname;
00260     drvName = other->drvName;
00261     port = other->port;
00262     connOptions = other->connOptions;
00263 }

void QSqlDatabasePrivate::disable (  ) 

Definition at line 265 of file qsqldatabase.cpp.

References driver, and shared_null().

Referenced by invalidateDb().

00266 {
00267     if (driver != shared_null()->driver) {
00268         delete driver;
00269         driver = shared_null()->driver;
00270     }
00271 }

Here is the call graph for this function:

QSqlDatabasePrivate * QSqlDatabasePrivate::shared_null (  )  [static]

Definition at line 188 of file qsqldatabase.cpp.

References n.

Referenced by disable(), init(), QSqlDatabase::isValid(), QSqlDatabase::QSqlDatabase(), and ~QSqlDatabasePrivate().

00189 {
00190     static QSqlNullDriver dr;
00191     static QSqlDatabasePrivate n(&dr);
00192     return &n;
00193 }

QSqlDatabase QSqlDatabasePrivate::database ( const QString name,
bool  open 
) [static]

Definition at line 232 of file qsqldatabase.cpp.

References QByteArray::data(), QSqlDatabase::isOpen(), QSqlDatabase::isValid(), QSqlDatabase::lastError(), QConnectionDict::lock, QReadWriteLock::lockForRead(), name, QSqlDatabase::open(), qWarning(), QSqlError::text(), QString::toLocal8Bit(), QReadWriteLock::unlock(), and QHash< Key, T >::value().

Referenced by QSqlDatabase::database().

00233 {
00234     const QConnectionDict *dict = dbDict();
00235     Q_ASSERT(dict);
00236 
00237     dict->lock.lockForRead();
00238     QSqlDatabase db = dict->value(name);
00239     dict->lock.unlock();
00240     if (db.isValid() && !db.isOpen() && open) {
00241         db.open();
00242         if (!db.isOpen())
00243             qWarning("QSqlDatabasePrivate::database: unable to open database: %s",
00244                      db.lastError().text().toLocal8Bit().data());
00245 
00246     }
00247     return db;
00248 }

Here is the call graph for this function:

void QSqlDatabasePrivate::addDatabase ( const QSqlDatabase db,
const QString name 
) [static]

Definition at line 216 of file qsqldatabase.cpp.

References QHash< Key, T >::contains(), QHash< Key, T >::insert(), invalidateDb(), QConnectionDict::lock, name, qWarning(), and QHash< Key, T >::take().

Referenced by QSqlDatabase::addDatabase(), and QSqlDatabase::cloneDatabase().

00217 {
00218     QConnectionDict *dict = dbDict();
00219     Q_ASSERT(dict);
00220     QWriteLocker locker(&dict->lock);
00221 
00222     if (dict->contains(name)) {
00223         invalidateDb(dict->take(name), name);
00224         qWarning("QSqlDatabasePrivate::addDatabase: duplicate connection name '%s', old "
00225                  "connection removed.", name.toLocal8Bit().data());
00226     }
00227     dict->insert(name, db);
00228 }

Here is the call graph for this function:

void QSqlDatabasePrivate::removeDatabase ( const QString name  )  [static]

Definition at line 204 of file qsqldatabase.cpp.

References QHash< Key, T >::contains(), invalidateDb(), QConnectionDict::lock, name, and QHash< Key, T >::take().

Referenced by QSqlDatabase::removeDatabase().

00205 {
00206     QConnectionDict *dict = dbDict();
00207     Q_ASSERT(dict);
00208     QWriteLocker locker(&dict->lock);
00209 
00210     if (!dict->contains(name))
00211         return;
00212 
00213     invalidateDb(dict->take(name), name);
00214 }

Here is the call graph for this function:

void QSqlDatabasePrivate::invalidateDb ( const QSqlDatabase db,
const QString name 
) [static]

Definition at line 195 of file qsqldatabase.cpp.

References QSqlDatabase::d, disable(), name, qWarning(), and ref.

Referenced by addDatabase(), cleanConnections(), and removeDatabase().

00196 {
00197     if (db.d->ref != 1) {
00198         qWarning("QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, "
00199                  "all queries will cease to work.", name.toLocal8Bit().constData());
00200         db.d->disable();
00201     }
00202 }

Here is the call graph for this function:

DriverDict & QSqlDatabasePrivate::driverDict (  )  [static]

Definition at line 178 of file qsqldatabase.cpp.

References cleanDriverDict(), qAddPostRoutine(), and qDriverDictInit.

Referenced by cleanDriverDict(), QSqlDatabase::drivers(), init(), and QSqlDatabase::registerSqlDriver().

00179 {
00180     static DriverDict dict;
00181     if (!qDriverDictInit) {
00182         qDriverDictInit = true;
00183         qAddPostRoutine(cleanDriverDict);
00184     }
00185     return dict;
00186 }

Here is the call graph for this function:

void QSqlDatabasePrivate::cleanConnections (  )  [static]

Definition at line 155 of file qsqldatabase.cpp.

References QHash< Key, T >::begin(), QHash< Key, T >::clear(), QHash< Key, T >::end(), invalidateDb(), QHash< QString, QSqlDatabase >::iterator, and QConnectionDict::lock.

Referenced by cleanDriverDict().

00156 {
00157     QConnectionDict *dict = dbDict();
00158     Q_ASSERT(dict);
00159     QWriteLocker locker(&dict->lock);
00160 
00161     QConnectionDict::iterator it = dict->begin();
00162     while (it != dict->end()) {
00163         invalidateDb(it.value(), it.key());
00164         ++it;
00165     }
00166     dict->clear();
00167 }

Here is the call graph for this function:


Member Data Documentation

QAtomic QSqlDatabasePrivate::ref

Definition at line 116 of file qsqldatabase.cpp.

Referenced by invalidateDb(), QSqlDatabase::QSqlDatabase(), QSqlDatabasePrivate(), and QSqlDatabase::~QSqlDatabase().

QSqlDriver* QSqlDatabasePrivate::driver

Definition at line 117 of file qsqldatabase.cpp.

Referenced by QSqlDatabase::close(), QSqlDatabase::commit(), disable(), QSqlDatabase::driver(), QSqlDatabase::exec(), init(), QSqlDatabase::isOpen(), QSqlDatabase::isOpenError(), QSqlDatabase::isValid(), QSqlDatabase::lastError(), QSqlDatabase::open(), QSqlDatabase::primaryIndex(), QSqlDatabasePrivate(), QSqlDatabase::record(), QSqlDatabase::rollback(), QSqlDatabase::tables(), QSqlDatabase::transaction(), and ~QSqlDatabasePrivate().

QString QSqlDatabasePrivate::dbname

Definition at line 118 of file qsqldatabase.cpp.

Referenced by copy(), QSqlDatabase::databaseName(), QSqlDatabase::open(), QSqlDatabasePrivate(), and QSqlDatabase::setDatabaseName().

QString QSqlDatabasePrivate::uname

Definition at line 119 of file qsqldatabase.cpp.

Referenced by copy(), QSqlDatabase::open(), QSqlDatabasePrivate(), QSqlDatabase::setUserName(), and QSqlDatabase::userName().

QString QSqlDatabasePrivate::pword

Definition at line 120 of file qsqldatabase.cpp.

Referenced by copy(), QSqlDatabase::open(), QSqlDatabase::password(), QSqlDatabasePrivate(), and QSqlDatabase::setPassword().

QString QSqlDatabasePrivate::hname

Definition at line 121 of file qsqldatabase.cpp.

Referenced by copy(), QSqlDatabase::hostName(), QSqlDatabase::open(), QSqlDatabasePrivate(), and QSqlDatabase::setHostName().

QString QSqlDatabasePrivate::drvName

Definition at line 122 of file qsqldatabase.cpp.

Referenced by copy(), QSqlDatabase::driverName(), init(), and QSqlDatabasePrivate().

int QSqlDatabasePrivate::port

Definition at line 123 of file qsqldatabase.cpp.

Referenced by copy(), QSqlDatabase::open(), QSqlDatabase::port(), QSqlDatabasePrivate(), and QSqlDatabase::setPort().

QString QSqlDatabasePrivate::connOptions

Definition at line 124 of file qsqldatabase.cpp.

Referenced by QSqlDatabase::connectOptions(), copy(), QSqlDatabase::open(), QSqlDatabasePrivate(), and QSqlDatabase::setConnectOptions().


The documentation for this class was generated from the following file:
Generated on Thu Mar 15 19:00:08 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1