我正在寻找一个c ++库,它提供与c#SelectQueryBuilder库类似的功能
http://www.codeproject.com/Articles/13419/SelectQueryBuilder-Building-complex-and-flexible-S
即。它允许一个人摆脱构建可怕的连接字符串以形成动态SQL查询,而是拥有一个提供接口的库,通过它传递表,要从表中选择的元素等,以及它以字符串形式返回SQL查询。
任何帮助非常感谢
编辑:我正在构建的示例查询....我们不知道选择的实际列,直到运行时,例如不知道会有多少VAR1 ... VARx以及它们究竟是什么。
SELECT * FROM
(
SELECT
table_1.id,
table_2.name,
(select(COALESCE(sum(table_1.col_1 * 1.0) / NULLIF(sum(table_1.col_2 - table_1.col_3),0) * 100,0))) as VAR1,
(select(COALESCE(sum(table_1.col_4 * 1.0) / NULLIF(sum(table_1.col_5),0) * 100,0))) as VAR2,
sum(table_1.col_2) as VAR3
FROM table_1, table_2
WHERE table_1.id = table_2.id
GROUP BY table_1.id, table_2.name
) VARIABLES
WHERE VAR3 > 1000
答案 0 :(得分:1)
使用QSqlQuery,您可以使用占位符并将值绑定到它们:
QSqlQuery query;
query.prepare("INSERT INTO person (id, forename, surname) "
"VALUES (:id, :forename, :surname)");
query.bindValue(":id", 1001);
query.bindValue(":forename", "Bart");
query.bindValue(":surname", "Simpson");
query.exec();
或
QSqlQuery query;
query.prepare("INSERT INTO person (id, forename, surname) "
"VALUES (?, ?, ?)");
query.addBindValue(1001);
query.addBindValue("Bart");
query.addBindValue("Simpson");
query.exec();
http://qt-project.org/doc/qt-5.0/qtsql/qsqlquery.html#approaches-to-binding-values