Qt 4.8
Public Functions | Static Public Functions | Public Variables | List of all members
QSqlDatabasePrivate Class Reference

Public Functions

void copy (const QSqlDatabasePrivate *other)
 Copies the connection data from other. More...
 
void disable ()
 
void init (const QString &type)
 Create the actual driver instance type. More...
 
 QSqlDatabasePrivate (QSqlDatabase *d, QSqlDriver *dr=0)
 
 QSqlDatabasePrivate (const QSqlDatabasePrivate &other)
 
 ~QSqlDatabasePrivate ()
 

Static Public Functions

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

Public Variables

QString connName
 
QString connOptions
 
QString dbname
 
QSqlDriverdriver
 
QString drvName
 
QString hname
 
int port
 
QSql::NumericalPrecisionPolicy precisionPolicy
 
QString pword
 
QSqlDatabaseq
 
QAtomicInt ref
 
QString uname
 

Detailed Description

Definition at line 132 of file qsqldatabase.cpp.

Constructors and Destructors

◆ QSqlDatabasePrivate() [1/2]

QSqlDatabasePrivate::QSqlDatabasePrivate ( QSqlDatabase d,
QSqlDriver dr = 0 
)
inline

Definition at line 135 of file qsqldatabase.cpp.

135  :
136  q(d),
137  driver(dr),
138  port(-1)
139  {
140  ref = 1;
142  }
QSql::NumericalPrecisionPolicy precisionPolicy
QSqlDatabase * q

◆ QSqlDatabasePrivate() [2/2]

QSqlDatabasePrivate::QSqlDatabasePrivate ( const QSqlDatabasePrivate other)

Definition at line 171 of file qsqldatabase.cpp.

172 {
173  ref = 1;
174  q = other.q;
175  dbname = other.dbname;
176  uname = other.uname;
177  pword = other.pword;
178  hname = other.hname;
179  drvName = other.drvName;
180  port = other.port;
181  connOptions = other.connOptions;
182  driver = other.driver;
184 }
QSql::NumericalPrecisionPolicy precisionPolicy
QSqlDatabase * q

◆ ~QSqlDatabasePrivate()

QSqlDatabasePrivate::~QSqlDatabasePrivate ( )

Definition at line 186 of file qsqldatabase.cpp.

187 {
188  if (driver != shared_null()->driver)
189  delete driver;
190 }
static QSqlDatabasePrivate * shared_null()

Functions

◆ addDatabase()

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

Definition at line 254 of file qsqldatabase.cpp.

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

255 {
256  QConnectionDict *dict = dbDict();
257  Q_ASSERT(dict);
258  QWriteLocker locker(&dict->lock);
259 
260  if (dict->contains(name)) {
261  invalidateDb(dict->take(name), name);
262  qWarning("QSqlDatabasePrivate::addDatabase: duplicate connection name '%s', old "
263  "connection removed.", name.toLocal8Bit().data());
264  }
265  dict->insert(name, db);
266  db.d->connName = name;
267 }
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QReadWriteLock lock
QSqlDatabasePrivate * d
Definition: qsqldatabase.h:150
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
Definition: qhash.h:753
const char * name
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
static void invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn=true)

◆ cleanConnections()

void QSqlDatabasePrivate::cleanConnections ( )
static

Definition at line 192 of file qsqldatabase.cpp.

Referenced by cleanDriverDict().

193 {
194  QConnectionDict *dict = dbDict();
195  Q_ASSERT(dict);
196  QWriteLocker locker(&dict->lock);
197 
199  while (it != dict->end()) {
200  invalidateDb(it.value(), it.key(), false);
201  ++it;
202  }
203  dict->clear();
204 }
void clear()
Removes all items from the hash.
Definition: qhash.h:574
QReadWriteLock lock
#define it(className, varName)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
static void invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn=true)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the hash...
Definition: qhash.h:467
iterator begin()
Returns an STL-style iterator pointing to the first item in the hash.
Definition: qhash.h:464

◆ copy()

void QSqlDatabasePrivate::copy ( const QSqlDatabasePrivate other)

Copies the connection data from other.

Warning
This function is not part of the public interface.

Definition at line 294 of file qsqldatabase.cpp.

Referenced by QSqlDatabase::cloneDatabase().

295 {
296  q = other->q;
297  dbname = other->dbname;
298  uname = other->uname;
299  pword = other->pword;
300  hname = other->hname;
301  drvName = other->drvName;
302  port = other->port;
303  connOptions = other->connOptions;
305 }
QSql::NumericalPrecisionPolicy precisionPolicy
QSqlDatabase * q

◆ database()

QSqlDatabase QSqlDatabasePrivate::database ( const QString name,
bool  open 
)
static
Warning
This function is not part of the public interface.

Definition at line 271 of file qsqldatabase.cpp.

Referenced by QSqlDatabase::database().

272 {
273  const QConnectionDict *dict = dbDict();
274  Q_ASSERT(dict);
275 
276  dict->lock.lockForRead();
277  QSqlDatabase db = dict->value(name);
278  dict->lock.unlock();
279  if (db.isValid() && !db.isOpen() && open) {
280  if (!db.open())
281  qWarning() << "QSqlDatabasePrivate::database: unable to open database:" << db.lastError().text();
282 
283  }
284  return db;
285 }
QString text() const
This is a convenience function that returns databaseText() and driverText() concatenated into a singl...
Definition: qsqlerror.cpp:237
bool isOpen() const
Returns true if the database connection is currently open; otherwise returns false.
QReadWriteLock lock
void unlock()
Unlocks the lock.
bool isValid() const
Returns true if the QSqlDatabase has a valid driver.
The QSqlDatabase class represents a connection to a database.
Definition: qsqldatabase.h:78
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
QSqlError lastError() const
Returns information about the last error that occurred on the database.
Q_CORE_EXPORT void qWarning(const char *,...)
void lockForRead()
Locks the lock for reading.
bool open()
Opens the database connection using the current connection values.
int open(const char *, int,...)

◆ disable()

void QSqlDatabasePrivate::disable ( )

Definition at line 307 of file qsqldatabase.cpp.

Referenced by invalidateDb().

308 {
309  if (driver != shared_null()->driver) {
310  delete driver;
312  }
313 }
static QSqlDatabasePrivate * shared_null()

◆ driverDict()

DriverDict & QSqlDatabasePrivate::driverDict ( )
static

Definition at line 215 of file qsqldatabase.cpp.

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

216 {
217  static DriverDict dict;
218  if (!qDriverDictInit) {
219  qDriverDictInit = true;
221  }
222  return dict;
223 }
void qAddPostRoutine(QtCleanUpFunction p)
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,(QSqlDriverFactoryInterface_iid, QLatin1String("/sqldrivers"))) QT_STATIC_CONST_IMPL char *QSqlDatabase typedef QHash< QString, QSqlDriverCreatorBase * > DriverDict
static bool qDriverDictInit
static void cleanDriverDict()

◆ init()

void QSqlDatabasePrivate::init ( const QString type)

Create the actual driver instance type.

Warning
This function is not part of the public interface.

Definition at line 762 of file qsqldatabase.cpp.

763 {
764  drvName = type;
765 
766  if (!driver) {
767 #ifdef QT_SQL_PSQL
768  if (type == QLatin1String("QPSQL") || type == QLatin1String("QPSQL7"))
769  driver = new QPSQLDriver();
770 #endif
771 #ifdef QT_SQL_MYSQL
772  if (type == QLatin1String("QMYSQL") || type == QLatin1String("QMYSQL3"))
773  driver = new QMYSQLDriver();
774 #endif
775 #ifdef QT_SQL_ODBC
776  if (type == QLatin1String("QODBC") || type == QLatin1String("QODBC3"))
777  driver = new QODBCDriver();
778 #endif
779 #ifdef QT_SQL_OCI
780  if (type == QLatin1String("QOCI") || type == QLatin1String("QOCI8"))
781  driver = new QOCIDriver();
782 #endif
783 #ifdef QT_SQL_TDS
784  if (type == QLatin1String("QTDS") || type == QLatin1String("QTDS7"))
785  driver = new QTDSDriver();
786 #endif
787 #ifdef QT_SQL_DB2
788  if (type == QLatin1String("QDB2"))
789  driver = new QDB2Driver();
790 #endif
791 #ifdef QT_SQL_SQLITE
792  if (type == QLatin1String("QSQLITE"))
793  driver = new QSQLiteDriver();
794 #endif
795 #ifdef QT_SQL_SQLITE2
796  if (type == QLatin1String("QSQLITE2"))
797  driver = new QSQLite2Driver();
798 #endif
799 #ifdef QT_SQL_IBASE
800  if (type == QLatin1String("QIBASE"))
801  driver = new QIBaseDriver();
802 #endif
803  }
804 
805  if (!driver) {
807  for (DriverDict::const_iterator it = dict.constBegin();
808  it != dict.constEnd() && !driver; ++it) {
809  if (type == it.key()) {
810  driver = ((QSqlDriverCreatorBase*)(*it))->createObject();
811  }
812  }
813  }
814 
815 #ifndef QT_NO_LIBRARY
816  if (!driver && loader()) {
817  if (QSqlDriverFactoryInterface *factory = qobject_cast<QSqlDriverFactoryInterface*>(loader()->instance(type)))
818  driver = factory->create(type);
819  }
820 #endif // QT_NO_LIBRARY
821 
822  if (!driver) {
823  qWarning("QSqlDatabase: %s driver not loaded", type.toLatin1().data());
824  qWarning("QSqlDatabase: available drivers: %s",
825  QSqlDatabase::drivers().join(QLatin1String(" ")).toLatin1().data());
826  if (QCoreApplication::instance() == 0)
827  qWarning("QSqlDatabase: an instance of QCoreApplication is required for loading driver plugins");
829  }
830 }
int type
Definition: qmetatype.cpp:239
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
#define it(className, varName)
static QStringList drivers()
Returns a list of all the available database drivers.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,(QSqlDriverFactoryInterface_iid, QLatin1String("/sqldrivers"))) QT_STATIC_CONST_IMPL char *QSqlDatabase typedef QHash< QString, QSqlDriverCreatorBase * > DriverDict
static QSqlDatabasePrivate * shared_null()
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
static QCoreApplication * instance()
Returns a pointer to the application&#39;s QCoreApplication (or QApplication) instance.
static DriverDict & driverDict()
The QSqlDriverCreatorBase class is the base class for SQL driver factories.
Definition: qsqldatabase.h:64

◆ invalidateDb()

void QSqlDatabasePrivate::invalidateDb ( const QSqlDatabase db,
const QString name,
bool  doWarn = true 
)
static

Definition at line 232 of file qsqldatabase.cpp.

233 {
234  if (db.d->ref != 1 && doWarn) {
235  qWarning("QSqlDatabasePrivate::removeDatabase: connection '%s' is still in use, "
236  "all queries will cease to work.", name.toLocal8Bit().constData());
237  db.d->disable();
238  db.d->connName.clear();
239  }
240 }
QSqlDatabasePrivate * d
Definition: qsqldatabase.h:150
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723

◆ removeDatabase()

void QSqlDatabasePrivate::removeDatabase ( const QString name)
static

Definition at line 242 of file qsqldatabase.cpp.

Referenced by QSqlDatabase::removeDatabase().

243 {
244  QConnectionDict *dict = dbDict();
245  Q_ASSERT(dict);
246  QWriteLocker locker(&dict->lock);
247 
248  if (!dict->contains(name))
249  return;
250 
251  invalidateDb(dict->take(name), name);
252 }
QReadWriteLock lock
T take(const Key &key)
Removes the item with the key from the hash and returns the value associated with it...
Definition: qhash.h:807
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const char * name
The QWriteLocker class is a convenience class that simplifies locking and unlocking read-write locks ...
static void invalidateDb(const QSqlDatabase &db, const QString &name, bool doWarn=true)

◆ shared_null()

QSqlDatabasePrivate * QSqlDatabasePrivate::shared_null ( )
static

Definition at line 225 of file qsqldatabase.cpp.

Referenced by QSqlDatabase::QSqlDatabase().

226 {
227  static QSqlNullDriver dr;
228  static QSqlDatabasePrivate n(NULL, &dr);
229  return &n;
230 }

Properties

◆ connName

QString QSqlDatabasePrivate::connName

Definition at line 159 of file qsqldatabase.cpp.

Referenced by addDatabase(), and invalidateDb().

◆ connOptions

QString QSqlDatabasePrivate::connOptions

Definition at line 158 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().

◆ dbname

QString QSqlDatabasePrivate::dbname

Definition at line 152 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().

◆ driver

QSqlDriver* QSqlDatabasePrivate::driver

Definition at line 151 of file qsqldatabase.cpp.

Referenced by QSqlDatabasePrivate().

◆ drvName

QString QSqlDatabasePrivate::drvName

Definition at line 156 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().

◆ hname

QString QSqlDatabasePrivate::hname

Definition at line 155 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().

◆ port

int QSqlDatabasePrivate::port

Definition at line 157 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().

◆ precisionPolicy

QSql::NumericalPrecisionPolicy QSqlDatabasePrivate::precisionPolicy

Definition at line 160 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().

◆ pword

QString QSqlDatabasePrivate::pword

Definition at line 154 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().

◆ q

QSqlDatabase* QSqlDatabasePrivate::q

Definition at line 150 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().

◆ ref

QAtomicInt QSqlDatabasePrivate::ref

Definition at line 149 of file qsqldatabase.cpp.

Referenced by invalidateDb().

◆ uname

QString QSqlDatabasePrivate::uname

Definition at line 153 of file qsqldatabase.cpp.

Referenced by copy(), and QSqlDatabasePrivate().


The documentation for this class was generated from the following file: