C++ (Qt)QSqlQuery DataBaseDialog::getPreparedRollMetalQuery(const RollMetall &rollMetall, const QString& tableName) const{ QSqlQuery query; query.prepare(QString("SELECT NAME " "FROM %1 " "WHERE H = :h AND B = :b AND S = :s AND R1 = :r1 AND R2 = :r2 ").arg(tableName)); query.bindValue(":table", tableName); query.bindValue(":h", rollMetall.h); query.bindValue(":b", rollMetall.b); query.bindValue(":s", rollMetall.s); query.bindValue(":r1", rollMetall.r1); query.bindValue(":r2", rollMetall.r2); qDebug() << query.boundValues(); return query;} QString DataBaseDialog::getChannelName(const Channel &channel) const{ static const QString tableName = "Channels"; QSqlQuery query = getPreparedRollMetalQuery(channel, tableName); const QString queryTemplate = query.lastQuery() + "AND T = :t AND ALPHA = :alpha AND GN = :gn"; query.prepare(queryTemplate); query.bindValue(":t", channel.t); query.bindValue(":alpha", channel.alpha); query.bindValue(":gn", channel.gN); qDebug() << query.boundValues(); if(query.exec() && query.next()){ return query.value(0).toString(); } return QString();}
bool QSqlResult::savePrepare(const QString& query){ Q_D(QSqlResult); if (!driver()) return false; d->clear(); d->sql = query; if (!driver()->hasFeature(QSqlDriver::PreparedQueries)) return prepare(query); // parse the query to memorize parameter location d->executedQuery = d->namedToPositionalBinding(query); if (driver()->hasFeature(QSqlDriver::NamedPlaceholders)) d->executedQuery = d->positionalToNamedBinding(query); return prepare(d->executedQuery);}
C++ (Qt) qDebug() << query.boundValues(); qDebug() << query.lastQuery(); if(query.exec()){ if(query.next()){ return query.value(0).toString(); }} qDebug() << query.executedQuery();
QMap((":alpha", QVariant(double, 0))(":b", QVariant(double, 0))(":gn", QVariant(double, 0))(":h", QVariant(double, 0))(":r1", QVariant(double, 0))(":r2", QVariant(double, 0))(":s", QVariant(double, 0))(":t", QVariant(double, 0))(":table", QVariant(QString, "Channels")))"SELECT NAME FROM :table WHERE H = :h AND B = :b AND S = :s AND R1 = :r1 AND R2 = :r2 AND T = :t AND ALPHA = :alpha AND GN = :gn""SELECT NAME FROM ? WHERE H = ? AND B = ? AND S = ? AND R1 = ? AND R2 = ? AND T = ? AND ALPHA = ? AND GN = ?"QSqlError("", "Parameter count mismatch", "")