当前位置: 首页>>代码示例>>C++>>正文


C++ QSqlQuery::finish方法代码示例

本文整理汇总了C++中QSqlQuery::finish方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQuery::finish方法的具体用法?C++ QSqlQuery::finish怎么用?C++ QSqlQuery::finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QSqlQuery的用法示例。


在下文中一共展示了QSqlQuery::finish方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: slotInsertOrUpdateRecords

void Priorities::slotInsertOrUpdateRecords(void)
{
    QList<QVariant> list;
    QSqlQuery       stored;

    if (m_rad == RecordActionDatabase::ardInsert){
        list.append(dictionaryDialog->ui->lineEditItem->text());
        list.append((int)dictionaryDialog->ui->checkBoxActual->isChecked());
        list.append((int)(dictionaryDialog->ui->comboBoxIcon->currentIndex()));
        stored = execStored(currentDatabase(), "InsertPriorityType", storageHashTable(list));
        stored.finish();
    }
    else
    if (m_rad == RecordActionDatabase::ardUpdate){
        unsigned i(0);
        unsigned m_code = m_selectionModel->currentIndex().sibling(m_selectionModel->currentIndex().row(), i).data(Qt::DisplayRole).toUInt();

        list.append(m_code);
        list.append(dictionaryDialog->ui->lineEditItem->text());
        list.append((int)(dictionaryDialog->ui->checkBoxActual->isChecked()));
        list.append((int)(dictionaryDialog->ui->comboBoxIcon->currentIndex()));
        stored = execStored(currentDatabase(), "UpdatePriorityType", storageHashTable(list));
        stored.finish();
   }
   slotRefreshRecords();
   clearEditDialog(dictionaryDialog);
   m_selectedItem = false;
}
开发者ID:Gonchar64,项目名称:Rline,代码行数:28,代码来源:priorities.cpp

示例2: deleteUser

void DataBase::deleteUser(QString twitterID, QString readerID)
{

    connect();
    QString queryString = "SELECT count() FROM readableUsers WHERE twitterID="+twitterID;
    QSqlQuery deleteUserQuery;
    deleteUserQuery.prepare(queryString);
    deleteUserQuery.exec();
    deleteUserQuery.first();
    int count = deleteUserQuery.value(0).toInt();
    if (count == 1)
    {
        deleteUserQuery.finish();
        queryString = "DELETE FROM tweets WHERE userID="+twitterID;
        deleteUserQuery.prepare(queryString);
        deleteUserQuery.exec();
        deleteUserQuery.finish();
        queryString = "DELETE FROM users WHERE usertype=0 AND twitterID="+twitterID;
        deleteUserQuery.prepare(queryString);
        deleteUserQuery.exec();
    }
    deleteUserQuery.finish();
    queryString = "DELETE FROM readableUsers WHERE twitterID="+twitterID + " AND userID="+readerID;
    deleteUserQuery.prepare(queryString);
    deleteUserQuery.exec();
    deleteUserQuery.finish();
    disconnect();
}
开发者ID:unix-admin,项目名称:ita_course,代码行数:28,代码来源:database.cpp

示例3: count

bool	start_mysql(qint64 rows, qint64 total_time, QSqlDatabase& db, QSqlQuery& query_1, QSqlQuery& query_2) {
	if ( query_1.exec("SELECT sha1 FROM hash LIMIT 10000;") == false ) {
		std::cerr << "Cannot select the hashes: " << query_1.lastError().text().toLatin1().constData() << std::endl;
		db.rollback();
		query_1.finish();
		return false;
	}

	// Infinite loop!
	while ( query_1.next() == true ) {
		QElapsedTimer	timer;
		QString		sql_query = "SELECT count(*) FROM hash WHERE sha1='";

		sql_query += query_1.value(0).toString();
		sql_query += "';";

		rows++;

		// This is what we want to benchmark
		timer.start();
		query_2.exec(sql_query);
		total_time += timer.elapsed();

		query_2.finish();
	}

	query_1.finish();
	
	return true;
}
开发者ID:mgrzybek,项目名称:nsrl-toolkit,代码行数:30,代码来源:rds_bench.cpp

示例4: QString

bool AM2DScanConfigurationGeneralView::canView(const QString &databaseName, const QString &tableName, int dbId){
	Q_UNUSED(dbId)
	AMDatabase *database = AMDatabase::database(databaseName);
	if(database){
		QSqlQuery q = database->query();
		q.prepare("PRAGMA table_info("%tableName%")");
		if(!database->execQuery(q)) {
			q.finish();
			AMErrorMon::report(AMErrorReport(0, AMErrorReport::Debug, -275003, QString("2D Scan Configuration Generl View: There was an error while trying to read meta data on table %1.").arg(tableName)));
		}
		else{
			QStringList columnNames;
			while(q.next()){
				columnNames << q.value(1).toString();
			}
			columnNames.removeFirst();
			q.finish();

			if(columnNames.contains("xStart") && columnNames.contains("xStep") && columnNames.contains("xEnd") &&
					columnNames.contains("yStart") && columnNames.contains("yStep") && columnNames.contains("yEnd") &&
					columnNames.contains("timeStep") && columnNames.contains("fastAxis") && columnNames.contains("slowAxis")){
				return true;
			}
		}
	}
	return false;
}
开发者ID:acquaman,项目名称:acquaman,代码行数:27,代码来源:AM2DScanConfigurationGeneralView.cpp

示例5: onProcessPacket

void DataManager::onProcessPacket(const mon_bin_get* packet)
{
	QSqlQuery packetQuery;
	packetQuery.prepare("INSERT INTO `packets` "
			"(urb_id, device, bus, endpoint, time, status) "
			"VALUES(?,?,?,?,?,?);");
	QSqlQuery dataQuery;
	dataQuery.prepare("INSERT INTO `data` "
				"(packet_id, data, type) "
				"VALUES(?, ?, ?);");
	packetQuery.bindValue(0, packet->header->id);
	packetQuery.bindValue(1, packet->header->device);
	packetQuery.bindValue(2, packet->header->bus);
	packetQuery.bindValue(3, packet->header->endpoint);
	packetQuery.bindValue(4, QDateTime::fromTime_t(packet->header->ts_sec).addMSecs(packet->header->ts_usec/1000).toString("hh:mm:ss.zzz"));
	packetQuery.bindValue(5, (unsigned char)packet->header->status);

	if(!packetQuery.exec())
		goto error;

	dataQuery.bindValue(0, packetQuery.lastInsertId().toUInt());
	packetQuery.finish();

	if(packet->header->flag_setup == 0)
	{
		QByteArray setupData((const char*) packet->header->setup, 8);
		dataQuery.bindValue(1, setupData);
		dataQuery.bindValue(2, "Setup");
	}
	else if(packet->header->lengthCaptured > 0)
	{
		QByteArray data((const char*) packet->data, packet->header->lengthCaptured);
		dataQuery.bindValue(1, data);
		dataQuery.bindValue(2, "Data");
	}

	if(dataQuery.boundValues().size() == 3 && !dataQuery.exec())
		goto error;

	dataQuery.finish();
	goto cleanup;

error:
	database.rollback();
	qDebug() << "Database error: " << database.lastError().databaseText() << database.lastError().driverText();
	goto cleanup;

cleanup:
	delete packet->header;
	delete[] (char*)packet->data;
	delete packet;
	return;
}
开发者ID:triochi,项目名称:qusbmon,代码行数:53,代码来源:DataManager.cpp

示例6: exec

bool DbUpdater::exec(int version, QStringList queries) {
    bool ret;
    QSqlQuery q;

    qDebug() << "upgrading db schema (to version" << version << ")";
    this->start();

    for(int i = 0; i < queries.size(); i++) {
        qDebug() << "  exec" << queries.at(i);
        ret = q.exec(queries.at(i));
        if (!ret) {
            qDebug() << "  . failed: " << queries.at(i) << ", error " << q.lastError().text();
            this->rollback();
            return false;
        }

        q.finish();
    }

    // check foreign key contraints
    ret = q.exec("PRAGMA foreign_key_check");
    if (!ret) {
        qDebug() << "  . `PRAGMA foreign_key_check` failed: " << q.lastError();
        this->rollback();
        return false;
    }
    if (q.next()) {
        qDebug() << "  . FK conflicts:";
        do {
            qDebug() << "    -" << q.value(0).toString() << q.value(1).toLongLong() <<
                        q.value(2).toString();
        } while (q.next());

        this->rollback();
        return false;
    }
    q.finish();


    // updating db version
    q.prepare("UPDATE config SET value=:version WHERE key='version'");
    q.bindValue(":version", version);
    if (!q.exec()) {
        qDebug() << "upgrade version field failed:" << q.lastError().text();
        this->rollback();
        return false;
    }
    q.finish();

    this->commit();
    qDebug() << "  . succeed";
    return true;
}
开发者ID:gbour,项目名称:jolla-nextinpact,代码行数:53,代码来源:DbUpdater.cpp

示例7:

/**
 * Constructeur qui initialise le client par rapport au info contenu dans la BDD
 * @param identifiant, identifiant du client au sein de la BDD
 */
Customer::Customer(int identifiant){

    QSqlDatabase base = QSqlDatabase::database();
    QSqlQuery query;
    query.prepare("SELECT * FROM customer WHERE idCustomer=:id");
    query.bindValue(":id",identifiant);
    query.exec();

    query.next();
    QSqlRecord rec = query.record();

    m_name=rec.value("name").toString();
    m_adress=rec.value("adress").toString();
    m_adress2=rec.value("adress2").toString();
    m_city=rec.value("city").toString();
    m_country=rec.value("country").toString();
    m_email=rec.value("email").toString();
    m_phone=rec.value("phone").toString();
    m_postalCode=rec.value("postalCode").toInt();
    this->id=identifiant;

    query.finish();
    base.commit();

}
开发者ID:Ducatel,项目名称:QFacturation,代码行数:29,代码来源:customer.cpp

示例8: selects

void Widget::selects()
{
    QSqlQuery query;
    query.prepare("INSERT INTO Student (name ,age ) VALUES (?,?)");//query.exec();准备输出
    QVariantList names;//链表
    names <<"Tom "<< "Jacks" << "Jane" << "Jerry";
    query.addBindValue(names);//添加绑定链表
    QVariantList ages;
    ages << 20 << 23 << 22 << 25;
    query.addBindValue(ages);//按顺序添加绑定age
    if(!query.execBatch()){//批处理函数值
        QMessageBox::critical(0,QObject::tr("Databases Error"),query.lastError().text());
    }
    query.finish();
    QString janes = "jane";
    QString jane =QString("SELECT  sex FROM Student WHERE name = '%1'").arg(janes);
    query.exec(jane);//执行完这句话,
    QString name,sex;
    while (query.next())
    {
         //name = query.value(0).toString();
          sex = query.value(0).toString();
//        cout<<name.toStdString() <<":"<<age.toStdString()<<endl;
          cout<<sex.toStdString()<<endl;
    }
//    cout<<name.toStdString() <<":"<<age.toStdString()<<endl;
}
开发者ID:youngjeff,项目名称:qt,代码行数:27,代码来源:widget.cpp

示例9: removePlaylist

bool PlaylistManager::removePlaylist(int playlistID)
{
    QSqlDatabase musicDB = QSqlDatabase::addDatabase("QSQLITE",connectionName);
    musicDB.setDatabaseName(databaseName);
    bool opened = musicDB.open();
    if(opened)
    {
        QSqlQuery musicQuery = QSqlQuery(musicDB);
        musicQuery.exec("BEGIN TRANSACTION");
        musicQuery.exec(QString("DELETE  * FROM  PlaylistTrack  WHERE trackplaylistID='%1' ;").arg(QString::number(playlistID)));
        musicQuery.exec(QString("DELETE  * FROM  Playlist  WHERE playlistID='%1' ;").arg(QString::number(playlistID)));
        Q_EMIT playlistsModelChanged();
        musicQuery.exec("END TRANSACTION");

        musicQuery.finish();
        musicDB.close();
        Q_EMIT playlistsModelChanged();
        return true;
    }


    else
    {
        qDebug() << "PlaylistManager::removePlaylist: Database is not opened";
        return false;
    }
}
开发者ID:cyrildzumts,项目名称:playermodules,代码行数:27,代码来源:playlistmanager.cpp

示例10: createEntry

bool ValidDocument::createEntry(){
    QSqlDatabase base = QSqlDatabase::database();
    bool retour=false;

    QSqlQuery query;
    query.prepare("INSERT INTO DocumentValide (idCustomer,price,type,payment,date,view,tva) VALUES (:idCustomer,:price,:type,:payment,:date,:view,:tva )");
    query.bindValue(":idCustomer",idCustomer);
    query.bindValue(":price",price);
    query.bindValue(":type",docType);
    query.bindValue(":payment",payment);
    query.bindValue(":date",mdate.toString("yyyy-MM-dd"));
    query.bindValue(":view",view);
    query.bindValue(":tva",tva);

    retour=query.exec();

    if(retour)
        id=query.lastInsertId().toInt();

    query.finish();
    base.commit();


    Document d(idDocument);
    d.remove();


    return retour;

}
开发者ID:Ducatel,项目名称:QFacturation,代码行数:30,代码来源:validdocument.cpp

示例11: slotPushSelectRecordData

void Positions::slotPushSelectRecordData(void)
{
    QList<QVariant> list;
    QSqlQuery       stored;
    QString         userName;

    if (m_rad == RecordActionDatabase::ardInsert) {
        dictionaryDialog->ui->labelUserD->setText(currentUser());
        dictionaryDialog->ui->labelDateD->setText(QString(tr("Не определено")).trimmed());
    }
    else if (m_rad == RecordActionDatabase::ardUpdate) {
        unsigned i(1);
        QString m_item = m_selectionModel->currentIndex().sibling(m_selectionModel->currentIndex().row(), i).data(Qt::DisplayRole).toString();
        dictionaryDialog->setWindowTitle(QString(dictionaryDialog->windowTitle() + " запись - [ %1 ]").arg(m_item));
        dictionaryDialog->ui->lineEditItem->setText(QString(m_item).trimmed());

        unsigned c(2);
        unsigned m_check = m_selectionModel->currentIndex().sibling(m_selectionModel->currentIndex().row(), c).data(Qt::DisplayRole).toUInt();
        dictionaryDialog->ui->checkBoxActual->setChecked((bool)m_check);

        unsigned u(3);
        unsigned m_muser = m_selectionModel->currentIndex().sibling(m_selectionModel->currentIndex().row(), u).data(Qt::DisplayRole).toUInt();
        list.append(m_muser);
        stored = execStored(currentDatabase(), "ReadCurrentUser", storageHashTable(list));
        while (stored.next()) {
            userName = stored.record().field("opt_name_first").value().toString();
        }
        dictionaryDialog->ui->labelUserD->setText(userName);
        stored.finish();

        unsigned d(4);
        QString m_mdate = m_selectionModel->currentIndex().sibling(m_selectionModel->currentIndex().row(), d).data(Qt::DisplayRole).toString();
        dictionaryDialog->ui->labelDateD->setText(m_mdate);
    }
}
开发者ID:Gonchar64,项目名称:Rline,代码行数:35,代码来源:positions.cpp

示例12: slotDeleteProducer

void CSupplierDialog::slotDeleteProducer()
{
    QList<QVariant> list;
    QSqlQuery       stored;

    if (focusWidget()->objectName() == ui->treeProducer->objectName()){
        if (modelSelectionProducer->selection().isEmpty()){
            CCommunicate::showing(QString("Не удается выполнить, производитель не выбран"));
            return;
        }
    }

    CMessage answer(this, "Удаление", "Подтверждаете удаление?");
    QPushButton *buttonSave    = answer.addButton(QString("Удалить"), QMessageBox::ActionRole);
    QPushButton *buttonCancel  = answer.addButton(QString("Отмена"),  QMessageBox::ActionRole);

    answer.exec();

    if (answer.clickedButton() == buttonSave){
        const unsigned code = modelSelectionProducer->currentIndex().sibling(modelSelectionProducer->currentIndex().row(), 0).data().toUInt();
        list.append(code);

        stored = CDictionaryCore::execStored(CDictionaryCore::currentDatabase(), "DeleteProducerGroup", CDictionaryCore::storageHashTable(list));
        stored.finish();

        modelProducer->removeRows(modelSelectionProducer->currentIndex().row(), 1, QModelIndex());

        removable = true;

    } else if (answer.clickedButton() == buttonCancel){
        answer.reject();
    }
}
开发者ID:dekalo64,项目名称:RLine,代码行数:33,代码来源:dlg_supplier.cpp

示例13: slotDeleteRecords

void CTaskType::slotDeleteRecords(void)
{
    QList<QVariant> list;
    QSqlQuery       stored;

    if (currentDatabase().isOpen()) {

        int code = modelSelectionTask->currentIndex().sibling(modelSelectionTask->currentIndex().row(), 0).data().toUInt();

        if (!modelSelectionTask->selection().isEmpty()) {
            CMessage answer(this, "Удаление", "Подтверждаете удаление?");
            QPushButton *_delete = answer.addButton(QString("Удалить"), QMessageBox::ActionRole);
            QPushButton *cancel = answer.addButton(QString("Отмена"),  QMessageBox::ActionRole);

            answer.exec();

            if (answer.clickedButton() == _delete){
                list.append((int)code);
                stored.setForwardOnly(true);
                stored = execStored(currentDatabase(), "DeleteTaskType", storageHashTable(list));
                stored.finish();

                slotRefreshRecords(); // refresh

            } else if (answer.clickedButton() == cancel){
                treeCppsst->clearSelection();
                answer.reject();
            }
        } else
            CCommunicate::showing(QString("Не удается выполнить, запись не выбрана"));
    } else
        CCommunicate::showing(QString("Не удается выполнить, база данных не доступна"));

}
开发者ID:dekalo64,项目名称:RLine,代码行数:34,代码来源:dct_task.cpp

示例14: loadKTSs

bool SvDeviceEditor::loadKTSs()
{
  QSqlQuery* q = new QSqlQuery(SQLITE->db);
  QSqlError serr = SQLITE->execSQL(QString(SQL_SELECT_KTSS_LIST), q); 
  if(QSqlError::NoError != serr.type()) {
    
    _last_error = serr.text();
    delete q;
    return false;
  }

  while(q->next())
    ui->cbDeviceType->addItem(q->value("kts_name").toString(), q->value("kts_id").toUInt());
  
  q->finish();
  delete q;
  
  if(ui->cbDeviceType->count()) ui->cbDeviceType->setCurrentIndex(0);
  ui->bnSave->setEnabled(!ui->cbDeviceType->currentData().isNull());
  
  connect(ui->cbDeviceType, SIGNAL(currentIndexChanged(int)), this, SLOT(updateKTSInfo(int)));
  
  return true;
  
}
开发者ID:breton75,项目名称:niirpi,代码行数:25,代码来源:sv_device_editor.cpp

示例15: createDatabase

/**
 * @brief Creates the database.
 * @return True if the database was created successfully.
 */
bool SQLiteManager::createDatabase() {
	QString sqlAssets, sqlPortfolios, sqlReports, sqlWeights;
	bool result = true;
	QSqlQuery query;
	sqlAssets = "CREATE TABLE assets("
		"id INTEGER PRIMARY KEY AUTOINCREMENT,"
		"name TEXT UNIQUE NOT NULL,"
		"file TEXT UNIQUE NOT NULL,"
		"origin TEXT,"
		"first_date INTEGER,"
		"last_date INTEGER);";
	result &= query.exec(sqlAssets);
	sqlPortfolios = "CREATE TABLE portfolios("
		"id INTEGER PRIMARY KEY AUTOINCREMENT,"
		"name TEXT UNIQUE NOT NULL,"
		"parent INTEGER);";
	result &= query.exec(sqlPortfolios);
	sqlWeights = "CREATE TABLE weights("
		"asset INTEGER NOT NULL REFERENCES assets(id),"
		"portfolio INTEGER NOT NULL REFERENCES portfolio(id),"
		"weight INTEGER NOT NULL,"
		"PRIMARY KEY(asset, portfolio));";
	result &= query.exec(sqlWeights);
	sqlReports = "CREATE TABLE reports("
		"id INTEGER PRIMARY KEY AUTOINCREMENT,"
		"portfolio INTEGER NOT NULL REFERENCES portfolios(id),"
		"file TEXT UNIQUE NOT NULL,"
		"type INTEGER NOT NULL);";
	result &= query.exec(sqlReports);
	query.finish();
	return result;
}
开发者ID:YunhaiZhou,项目名称:VaRSoft,代码行数:36,代码来源:SQLiteManager.cpp


注:本文中的QSqlQuery::finish方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。