本文整理汇总了C++中QSqlDatabase函数的典型用法代码示例。如果您正苦于以下问题:C++ QSqlDatabase函数的具体用法?C++ QSqlDatabase怎么用?C++ QSqlDatabase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QSqlDatabase函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: tr
void FrmTrip::initModels()
{
if (viewTrips!=0) delete viewTrips;
viewTrips = new QSqlQueryModel;
viewTrips->setHeaderData(0, Qt::Horizontal, tr("Sampler"));
viewTrips->setHeaderData(1, Qt::Horizontal, tr("Start Date"));
viewTrips->setHeaderData(2, Qt::Horizontal, tr("Start Time"));
viewTrips->setHeaderData(3, Qt::Horizontal, tr("End Date"));
viewTrips->setHeaderData(4, Qt::Horizontal, tr("End Time"));
if (tRefGears!=0) delete tRefGears;
tRefGears = new QSqlQueryModel;
tRefGears->setQuery(
"SELECT ID, Name"
" FROM dbo.Ref_Gears ORDER BY ID ASC"
);
if (tTripGears!=0) delete tTripGears;
tTripGears=new QSqlTableModel();
tTripGears->setTable(QSqlDatabase().driver()->escapeIdentifier("Sampled_Fishing_Trips_Gears",
QSqlDriver::TableName));
tTripGears->setEditStrategy(QSqlTableModel::OnManualSubmit);
tTripGears->sort(0,Qt::AscendingOrder);
tTripGears->select();
QString strDep="select count(id) from Sampled_Fishing_operations WHERE (id_fishing_trip=:id)";
multiModelI=new MultiModelI(listGears,tRefGears,tTripGears,
strDep);
if (tRefZones!=0) delete tRefZones;
tRefZones = new QSqlQueryModel;
tRefZones->setQuery(
"SELECT ID, Name"
" FROM dbo.Ref_Fishing_zones ORDER BY ID ASC"
);
if (tTripZones!=0) delete tTripZones;
tTripZones=new QSqlTableModel();
tTripZones->setTable(QSqlDatabase().driver()->escapeIdentifier("Sampled_fishing_trips_zones",
QSqlDriver::TableName));
tTripZones->setEditStrategy(QSqlTableModel::OnManualSubmit);
tTripZones->sort(0,Qt::AscendingOrder);
tTripZones->select();
multiModelI2=new MultiModelI(listZones,tRefZones,tTripZones,
strDep);
}
开发者ID:doublebyte1,项目名称:app_solution,代码行数:53,代码来源:frmtrip.cpp
示例2: locker
QSqlDatabase ConnectionManager::threadConnection() const
{
QMutexLocker locker(&_mutex);
QThread* curThread = QThread::currentThread();
QSqlDatabase ret = _conns.value(curThread, QSqlDatabase());
return ret;
}
开发者ID:misje,项目名称:QtAsyncSql,代码行数:7,代码来源:ConnectionManager.cpp
示例3: QSqlDatabase
void MysqlConection::desconectar()
{
QString nombreConeccion = db.connectionName();
db.close();
db = QSqlDatabase();
QSqlDatabase::removeDatabase(nombreConeccion);
}
开发者ID:vialrogo,项目名称:TutorialCPP,代码行数:7,代码来源:MysqlConection.cpp
示例4: QSqlDatabase
QSqlDatabase XSqlTableModelProto::database() const
{
XSqlTableModel *item = qscriptvalue_cast<XSqlTableModel*>(thisObject());
if (item)
return item->database();
return QSqlDatabase();
}
开发者ID:AlFoX,项目名称:qt-client,代码行数:7,代码来源:xsqltablemodelproto.cpp
示例5: Q_ASSERT
QSqlDatabase ibanBicData::createDatabaseConnection(const QString& database)
{
Q_ASSERT(QSqlDatabase::drivers().contains("QSQLITE"));
// Try to use already created connection
const QString connectionName = QLatin1String("ibanBicData/") + database;
QSqlDatabase storedConnection = QSqlDatabase::database(connectionName);
if (storedConnection.isValid() && storedConnection.isOpen())
return storedConnection;
// Need to create new connection, locate database
QString path = QStandardPaths::locate(QStandardPaths::DataLocation, QLatin1String("kmymoney/ibanbicdata/") + database);
if (path.isEmpty()) {
qWarning() << QString("Could not locate database file \"%1\" to receive IBAN and BIC data.").arg(database);
return QSqlDatabase();
}
// Connect
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", connectionName);
db.setDatabaseName(path);
db.setConnectOptions("QSQLITE_OPEN_READONLY=1;QSQLITE_ENABLE_SHARED_CACHE=1;");
const bool opened = db.open();
if (!opened) {
qWarning() << QString("Could not open database \"%1\" to receive IBAN and BIC data.").arg(path);
}
return db;
}
开发者ID:KDE,项目名称:kmymoney,代码行数:28,代码来源:ibanbicdata.cpp
示例6: ctkDICOMModelTest1
/* Test from build directory:
./CTK-build/bin/CTKDICOMCoreCxxTests ctkDICOMModelTest1 test.db ../CTK/Libs/DICOM/Core/Resources/dicom-sample.sql
If you want a test with a GUI, look at ctkDICOMTest2 in DICOM/Widgets
*/
int ctkDICOMModelTest1( int argc, char * argv [] )
{
QCoreApplication app(argc, argv);
if (argc <= 2)
{
std::cerr << "Warning, no sql file given. Test stops" << std::endl;
std::cerr << "Usage: qctkDICOMModelTest1 <scratch.db> <dumpfile.sql>" << std::endl;
return EXIT_FAILURE;
}
try
{
ctkDICOMDatabase myCTK( argv[1] );
if (!myCTK.initializeDatabase(argv[2]))
{
std::cerr << "Error when initializing the data base: " << argv[2]
<< " error: " << myCTK.lastError().toStdString();
}
/*
QSqlQuery toto("SELECT PatientsName as 'Name tt' FROM Patients ORDER BY \"Name tt\" ASC", myCTK.database());
qDebug() << "toto: " << myCTK.lastError() ;
qDebug()<< toto.seek(0) << myCTK.lastError();
qDebug() << toto.value(0).toString() << myCTK.lastError();
QSqlQuery titi("SELECT StudyID as UID, StudyDescription as Name, ModalitiesInStudy as Scan, StudyDate as Date, AccessionNumber as Number, ReferringPhysician as Institution, ReferringPhysician as Referrer, PerformingPysiciansName as Performer FROM Studies WHERE PatientsUID='14'", myCTK.database());
qDebug() << "titi: " << titi.seek(0) << myCTK.lastError();
QSqlQuery tata("SELECT SeriesInstanceUID as UID, BodyPartExamined as Scan, SeriesDate as Date, AcquisitionNumber as Number FROM Series WHERE StudyInstanceUID='1.2.826.0.1.3680043.2.1125.1.73379483469717886505187028001198162'", myCTK.database());
qDebug() << "tata: " << tata.seek(0) << myCTK.lastError();
QSqlQuery tutu("SELECT SOPInstanceUID as UID, Filename as Name, SeriesInstanceUID as Date FROM Images WHERE SeriesInstanceUID='%1'", myCTK.database());
qDebug() << "tutu: " << tutu.seek(0) << myCTK.lastError();
*/
ctkModelTester tester;
tester.setNestedInserts(true);
tester.setThrowOnError(false);
ctkDICOMModel model;
tester.setModel(&model);
model.setDatabase(myCTK.database());
model.setDatabase(QSqlDatabase());
model.setDatabase(myCTK.database());
model.rowCount();
qDebug() << model.rowCount() << model.columnCount();
qDebug() << model.index(0,0);
return EXIT_SUCCESS;
}
catch (std::exception e)
{
std::cerr << "Error when opening the data base file: " << argv[1]
<< " error: " << e.what();
return EXIT_FAILURE;
}
}
开发者ID:151706061,项目名称:CTK,代码行数:64,代码来源:ctkDICOMModelTest1.cpp
示例7: QObject
DatabaseManager::DatabaseManager(QObject *parent): QObject(parent){
db = QSqlDatabase();
nomBib = "hao";
nomTable = "";
path = "";
tableRead = 0;
nombreTable = 0;
}
开发者ID:flyingmouse,项目名称:Library,代码行数:8,代码来源:database.cpp
示例8: QSqlDatabase
bool db::disconnect()
{
m_db.close();
m_db = QSqlDatabase();
m_db.removeDatabase(QSqlDatabase::defaultConnection);
return true;
}
开发者ID:ThilinaPeiris,项目名称:ActivityManager,代码行数:8,代码来源:database.cpp
示例9: QSqlDatabase
QSqlDatabase DummyMetadataDbManager::open(void)
{
if(allowOpen())
{
m_opened = true;
}
return QSqlDatabase();
}
开发者ID:cmacq2,项目名称:factorkey,代码行数:8,代码来源:dummy-metadb.cpp
示例10: QSqlDatabase
void TActionProcess::closeDatabase()
{
if (sqlDatabase.isValid()) {
sqlDatabase.rollback();
sqlDatabase.close();
sqlDatabase = QSqlDatabase(); // Sets an invalid object
}
}
开发者ID:AbhimanyuAryan,项目名称:treefrog-framework,代码行数:8,代码来源:tactionprocess.cpp
示例11: QSqlDatabase
/*!
* \brief Edict2::desconnect Desconnect edict2verbs.db SqLite database
*
* It looks for a connection name called "dbverbs", if found we remove it.
*/
void Edict2::desconnect()
{
if (QSqlDatabase::contains("dbverbs"))
{
// suppress "database in use" warning
verbdb = QSqlDatabase();
QSqlDatabase::removeDatabase("dbverbs");
}
}
开发者ID:pindamonhangaba,项目名称:JapKatsuyouCLI,代码行数:14,代码来源:edict2.cpp
示例12: QSqlDatabase
void DbConnection::disconnect (class DbList &dblist) {
if (db.isOpen ()) {
db.close ();
db = QSqlDatabase ();
QSqlDatabase::removeDatabase (dbuuid.toString ());
}
dblist.tablelist_clear (*this);
}
开发者ID:Typz,项目名称:qtc-dbviewer,代码行数:9,代码来源:WMain.cpp
示例13: while
void SignIn::on_PushButton_SignIn_clicked()
{
path = QDir::currentPath() + "\\TrainingTracker.sqlite";
m_db = QSqlDatabase::addDatabase("QSQLITE");
m_db.setDatabaseName(path);
QString username = ui->LineEdit_UserName->text();
QString password = ui->LineEdit_Password->text();
if (!m_db.open())
{
//qDebug() << "Error: connection with database fail";
//Error Handle
}
else
{
//qDebug() << "Database: connection ok";
QSqlQuery qry;
if(qry.exec("select * from users where name='" + username + "' and password='" + password +"'"))
{
int count = 0;
while(qry.next())
{
count++;
}
if(count == 1)
{
m_db.close();
m_db = QSqlDatabase();
m_db.removeDatabase(QSqlDatabase::defaultConnection);
this->hide();
MainWindow mainwindow;
mainwindow.setModal(true);
mainwindow.exec();
}else
{
//username and password doesn't match.
statusBar()->showMessage("Invalid Username or Password! Try Again!");
}
}
}
// if(QString::compare(username, "Bhagy") == 0 && QString::compare(password, "123") == 0)
// {
// this->hide();
// MainWindow mainwindow;
// mainwindow.setModal(true);
// mainwindow.exec();
// }else
// {
// statusBar()->showMessage("Invalid Username or Password! Try Again!");
// }
}
开发者ID:ThilinaPeiris,项目名称:Training-Tracker,代码行数:56,代码来源:signin.cpp
示例14: QSqlRelationalTableModel
void FrmFrame::initModels()
{
//Frame
tRefFrame=new QSqlRelationalTableModel();
tRefFrame->setTable(QSqlDatabase().driver()->escapeIdentifier(tr("FR_Frame"),
QSqlDriver::TableName));
tRefFrame->setRelation(0, QSqlRelation(tr("FR_Frame"), tr("ID"), tr("Name")));
tRefFrame->sort(0,Qt::AscendingOrder);
tRefFrame->select();
filterTable(tRefFrame->relationModel(0));
//Frame_Time (Physical frame + time frame!)
tFrameTime=new QSqlTableModel();
tFrameTime->setTable(QSqlDatabase().driver()->escapeIdentifier(tr("FR_Time"),
QSqlDriver::TableName));
tFrameTime->setEditStrategy(QSqlTableModel::OnManualSubmit);
tFrameTime->sort(0,Qt::AscendingOrder);
tFrameTime->select();
}
开发者ID:doublebyte1,项目名称:medfisis_nix,代码行数:19,代码来源:frmframe.cpp
示例15: databaseName
/*!
Clones the database connection \a other and and stores it as \a
connectionName. All the settings from the original database, e.g.
databaseName(), hostName(), etc., are copied across. Does nothing
if \a other is an invalid database. Returns the newly created
database connection.
\note The new connection has not been opened. Before using the new
connection, you must call open().
*/
QSqlDatabase QSqlDatabase::cloneDatabase(const QSqlDatabase &other, const QString &connectionName)
{
if (!other.isValid())
return QSqlDatabase();
QSqlDatabase db(other.driverName());
db.d->copy(other.d);
QSqlDatabasePrivate::addDatabase(db, connectionName);
return db;
}
开发者ID:fluxer,项目名称:katie,代码行数:20,代码来源:qsqldatabase.cpp
示例16: init
void FrmChangeReasons::init ()
{
tChanges=new QSqlTableModel;
tChanges->setTable(QSqlDatabase().driver()->escapeIdentifier(tr("Ref_Changes"),
QSqlDriver::TableName));
tChanges->select();
cmbChanges->setModel(tChanges);
cmbChanges->setModelColumn(2);
}
开发者ID:doublebyte1,项目名称:faocas_qc,代码行数:11,代码来源:frmchangereasons.cpp
示例17: tr
void BankEditDialog::deleteBank()
{
int row = tableWidget->currentRow();
if(row < 0)
return;
QString title;
if( tableWidget->item(row, 0) )
title = tableWidget->item(row, 0)->text();
if( title.isEmpty() )
{
tableWidget->removeRow(row);
return;
}
int res = QMessageBox::warning(this, tr("Warning!"), tr("Are you sure want to delete bank from the database?"),
QMessageBox::Ok,
QMessageBox::Cancel);
if(res == QMessageBox::Cancel)
return;
QSqlDatabase::database().transaction();
QSqlQuery query("DELETE FROM work.bank WHERE bank.title = '" + title + "';");
if(query.numRowsAffected() < 0)
{
QString error = "<table cellspacing=15><tr><td></td><td><b>Firm name</b></td><td><b>Bank title</b></td></tr>";
QSqlQuery q("SELECT owners.name, bank.title FROM work.owners "
"INNER JOIN work.bank ON owners.firm_bank = bank.id WHERE bank.title='" + title + "';");
int i = 1;
while(q.next())
{
error += "<tr><td><b>";
error += QString::number(i);
error += "</b></td><td>";
error += q.value(0).toString();
error += "</td><td>";
error += q.value(1).toString();
error += "</td></tr>";
i++;
}
error += "</table>";
QMessageBox::warning(this, tr("Warning!"), tr("Could not delete item from database, because the database "
"has some records connected with selected. <p>You have to delete them at first:<br>%1").arg(error));
}
else
tableWidget->removeRow(row);
QSqlDatabase().commit();
}
开发者ID:petrpopov,项目名称:db_transactions,代码行数:53,代码来源:bankeditdialog.cpp
示例18: QSqlDatabase
MSqlDatabase::~MSqlDatabase()
{
if (m_db.isOpen())
{
m_db.close();
m_db = QSqlDatabase(); // forces a destroy and must be done before
// removeDatabase() so that connections
// and queries are cleaned up correctly
QSqlDatabase::removeDatabase(m_name);
LOG(VB_DATABASE, LOG_INFO, "Database object deleted: " + m_name);
}
}
开发者ID:DaveDaCoda,项目名称:mythtv,代码行数:12,代码来源:mythdbcon.cpp
示例19: locker
void PersistentStore::deinit()
{
QMutexLocker locker(&_mutex);
if(_initialized)
{
_db.close();
_db = QSqlDatabase();
_db.removeDatabase("tarsnap");
_initialized = false;
}
}
开发者ID:shinnok,项目名称:tarsnap-gui,代码行数:12,代码来源:persistentstore.cpp
示例20: tQueryLog
void TSqlTransaction::rollback()
{
for (int i = 0; i < databases.count(); ++i) {
QSqlDatabase &db = databases[i];
if (db.isValid()) {
if (db.rollback()) {
tQueryLog("[ROLLBACK] [databaseId:%d]", i);
}
}
db = QSqlDatabase();
}
}
开发者ID:deniskin82,项目名称:treefrog-framework,代码行数:12,代码来源:tsqltransaction.cpp
注:本文中的QSqlDatabase函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论