QSqlDatabase::removeDatabase(QSqlDatabase::connectionName());QSqlDatabase::close();
{ QSqlDatabase db = QSqlDatabase::database("sales"); QSqlQuery query("SELECT NAME, DOB FROM EMPLOYEES", db); } // Both "db" and "query" are destroyed because they are out of scope QSqlDatabase::removeDatabase("sales"); // correct
QSqlDatabase::close();QSqlDatabase::~QSqlDatabase();QSqlDatabase::removeDatabase();
void QSQLite2Driver::close(){ if (isOpen()) { sqlite_close(d->access); d->access = 0; setOpen(false); setOpenError(false); }}
#include <QtCore/QCoreApplication>#include <QSqlDatabase>#include <QtDebug>#include <QFile>#include <QStringList>void init() { QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName("custom.db"); Q_ASSERT_X(db.open(), "init()","Can't open db"); qDebug() << "[init]\tSUCCES"; qDebug() << "[init]\t" << db.tables();}void close() { QSqlDatabase db = QSqlDatabase::database(); db.close(); qDebug() << "[close]\tclose Invoked";}void remove_db() { if(QFile::remove("custom.db")) qDebug() << "[remove_db]\tSUCCES"; else qDebug() << "[remove_db]\tFAILURE";}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); init(); remove_db(); close(); remove_db(); return a.exec();}
QSqlQuery query(database);foreach (QString table, QSqlDatabase::tables()) query.exec(QString("TRUNCATE TABLE %1").arg(table));foreach (QString table, QSqlDatabase::tables()) query.exec(QString("DROP TABLE %1").arg(table));