本文整理汇总了C++中QSqlQueryModel::query方法的典型用法代码示例。如果您正苦于以下问题:C++ QSqlQueryModel::query方法的具体用法?C++ QSqlQueryModel::query怎么用?C++ QSqlQueryModel::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QSqlQueryModel
的用法示例。
在下文中一共展示了QSqlQueryModel::query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exec
void Browser::exec()
{
last_query = sqlEdit->toPlainText();
tablelisten.clear();
QSqlDatabase currendb(connectionWidget->currentDatabase());
tablelisten = currendb.tables();
for (int i = 0; i < tablelisten.size(); ++i) {
QString tabi = tablelisten.at(i);
if (last_query.contains(tabi,Qt::CaseInsensitive)) {
runningtable = tabi;
}
}
QSqlQueryModel *model = new QSqlQueryModel(table);
model->setQuery(QSqlQuery(last_query,currendb));
table->setModel(model);
if (model->lastError().type() != QSqlError::NoError) {
emit statusMessage(model->lastError().text());
} else if (model->query().isSelect()) {
emit statusMessage(tr("Query OK on table %1").arg(runningtable));
emit registerQuerySuccess(last_query,runningtable); /* take last register table name .... */
} else {
emit statusMessage(tr("Query OK, number of affected rows: %1").arg(
model->query().numRowsAffected()));
}
updateActions();
}
示例2: handleTargetType
void CharacteristicAssignmentPrivate::handleTargetType()
{
QString charuseTargetType = targetType;
if (targetType == "I" || targetType == "ITEMGRP")
{
_template=true;
}
else if (targetType == "CT")
{
_template=true;
charuseTargetType = "C"; // bug 25940
}
else
parent->_default->hide();
if (targetType != "I")
parent->_listprice->hide();
parent->setWindowTitle(parent->tr("Characteristic: %1").arg(targetTypeMap.value(targetType)));
QSqlQueryModel *model = new QSqlQueryModel;
model->setQuery("SELECT char_id, char_name, char_type"
" FROM char JOIN charuse ON char_id = charuse_char_id"
" WHERE charuse_target_type = '" + charuseTargetType + "'"
" ORDER BY char_order, char_name");
parent->_char->setModel(model);
idCol = model->query().record().indexOf("char_id");
nameCol = model->query().record().indexOf("char_name");
typeCol = model->query().record().indexOf("char_type");
parent->_char->setModelColumn(nameCol); // char_name
parent->sHandleChar();
}
示例3: exec
void Browser::exec()
{
QSqlQueryModel *model = new QSqlQueryModel(table);
model->setQuery(QSqlQuery(sqlEdit->toPlainText(), connectionWidget->currentDatabase()));
table->setModel(model);
if (model->lastError().type() != QSqlError::NoError)
emit statusMessage(model->lastError().text());
else if (model->query().isSelect())
emit statusMessage(tr("Query OK."));
else
emit statusMessage(tr("Query OK, number of affected rows: %1").arg(
model->query().numRowsAffected()));
updateActions();
}
示例4: runQuery
void BairesWindow::runQuery(QString queryString) {
QSqlQueryModel *model = new QSqlQueryModel(ui.resultsTable);
QSqlQuery q(queryString, db);
model->setQuery(q);
if (model->lastError().type() != QSqlError::NoError) {
qDebug() << model->lastError().text();
qDebug() << tr("Query Error.");
} else if (model->query().isSelect())
qDebug() << tr("Query OK");
else
qDebug() << tr("Query OK, number of affected rows: %1").arg(model->query().numRowsAffected());
ui.resultsTable->setModel(model);
ui.resultsTable->horizontalHeader()->setStretchLastSection(true);
ui.resultsTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
}
示例5: getResiduesListFilial
void residuesFilialForm::getResiduesListFilial(){
//TODO: Create settings from column width
QSqlDatabase::database();
QSqlQueryModel *dataViewFilial = new QSqlQueryModel;
QString queryPrepare ;//= new QString;
queryPrepare = QString("%1 %2 %3").arg("SELECT d.id, "
"m.name, "
"d.counts, "
"d.countsp, "
"d.orders, "
"d.lastupdates, "
"d.timeleft "
"FROM ((dish d "
"LEFT JOIN menu m ON ((m.id = d.menu))) "
"LEFT JOIN users u ON ((u.id = d.users))) "
"WHERE (((d.deleted = false) AND (m.deleted = false)) AND (u.deleted = false))").arg("AND d.users=").arg("1");
dataViewFilial->setQuery(queryPrepare);
dataViewFilial->setHeaderData(0,Qt::Horizontal, QObject::trUtf8("ID"));
dataViewFilial->setHeaderData(1,Qt::Horizontal, QObject::trUtf8("Menu"));
dataViewFilial->setHeaderData(2,Qt::Horizontal, QObject::trUtf8("Count"));
dataViewFilial->setHeaderData(3,Qt::Horizontal, QObject::trUtf8("Emergency Count"));
dataViewFilial->setHeaderData(4,Qt::Horizontal, QObject::trUtf8("Orders"));
dataViewFilial->setHeaderData(5,Qt::Horizontal, QObject::trUtf8("Latest Update"));
dataViewFilial->setHeaderData(6,Qt::Horizontal, QObject::trUtf8("Expiry Date"));
// dataViewFilial->setFilter("users=1");
qDebug() << dataViewFilial->query().lastQuery();
ui->filialTableView->setModel(dataViewFilial);
ui->filialTableView->hideColumn(0);
ui->filialTableView->setColumnWidth(1,350);
ui->filialTableView->setColumnWidth(2,100);
ui->filialTableView->setColumnWidth(3,110);
ui->filialTableView->setColumnWidth(5,100);
ui->filialTableView->setColumnWidth(6,100);
ui->filialTableView->verticalHeader()->hide();
}
示例6: isDupe
/*!
Dupe checking subroutine.
- qso->worked returns with bits set according to bands worked
- DupeCheckingEveryBand controls whether calls can be worked on every band or only once.
@todo Multiple-mode contests not implemented yet
*/
bool Log::isDupe(Qso *qso, bool DupeCheckingEveryBand, bool FillWorked) const
{
// if called with no call, abort
if (qso->call.isEmpty()) return false;
bool dupe = false;
qso->worked = 0;
qso->prefill.clear();
QSqlQueryModel m;
// call can only be worked once on any band
if (!DupeCheckingEveryBand) {
#if QT_VERSION < 0x050000
m.setQuery("SELECT * FROM log WHERE valid='true' and CALL='" + qso->call + "'", db);
#else
m.setQuery("SELECT * FROM log WHERE valid=1 and CALL='" + qso->call + "'", db);
#endif
while (m.canFetchMore()) {
m.fetchMore();
}
if (m.rowCount()) {
dupe = true;
if (FillWorked) {
// mult not needed on any band
qso->worked = 63;
}
}
} else {
// if mobile station, check for mobile dupe option. In this
// case, count dupe only if exchange is identical
#if QT_VERSION < 0x050000
QString query="SELECT * FROM log WHERE valid='true' and call='" + qso->call + "' AND band=" + QString::number(qso->band);
#else
QString query="SELECT * FROM log WHERE valid=1 and call='" + qso->call + "' AND band=" + QString::number(qso->band);
#endif
if (qso->isMobile && csettings.value(c_mobile_dupes,c_mobile_dupes_def).toBool()) {
QString exch=qso->rcv_exch[csettings.value(c_mobile_dupes_col,c_mobile_dupes_col_def).toInt()-1];
// if exchange not entered, can't determine dupe status yet
if (exch.isEmpty()) {
return(false);
}
// if qso already has an assigned number in log (which is SQL primary key), only check
// qso's BEFORE this one
if (qso->nr) {
query=query+" AND (nr < "+QString::number(qso->nr)+") ";
}
query=query+ " AND ";
switch (csettings.value(c_mobile_dupes_col,c_mobile_dupes_col_def).toInt()) {
case 1:
query=query+"rcv1='"+exch+"'";
break;
case 2:
query=query+"rcv2='"+exch+"'";
break;
case 3:
query=query+"rcv3='"+exch+"'";
break;
case 4:
query=query+"rcv4='"+exch+"'";
break;
default:
return(false);
}
}
m.setQuery(query, db);
m.query().exec();
while (m.canFetchMore()) {
m.fetchMore();
}
if (m.rowCount()) {
dupe=true;
}
if (FillWorked) {
#if QT_VERSION < 0x050000
m.setQuery("SELECT * FROM log WHERE valid='true' and CALL='" + qso->call + "'", db);
#else
m.setQuery("SELECT * FROM log WHERE valid=1 and CALL='" + qso->call + "'", db);
#endif
for (int i = 0; i < m.rowCount(); i++) {
qso->worked += bits[m.record(i).value(SQL_COL_BAND).toInt()];
}
}
}
// if a dupe, set zero pts
if (dupe) qso->pts = 0;
return(dupe);
}