本文整理汇总了C++中QueryBuilder::addValueCondition方法的典型用法代码示例。如果您正苦于以下问题:C++ QueryBuilder::addValueCondition方法的具体用法?C++ QueryBuilder::addValueCondition怎么用?C++ QueryBuilder::addValueCondition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::addValueCondition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testQueryBuilder_data
void QueryBuilderTest::testQueryBuilder_data()
{
qRegisterMetaType<QVector<QVariant> >();
mBuilders.clear();
QTest::addColumn<int>("qbId");
QTest::addColumn<QString>("sql");
QTest::addColumn<QVector<QVariant> >("bindValues");
QueryBuilder qb("table", QueryBuilder::Select);
qb.addColumn("col1");
mBuilders << qb;
QTest::newRow("simple select") << mBuilders.count() << QString("SELECT col1 FROM table") << QVector<QVariant>();
qb.addColumn("col2");
mBuilders << qb;
QTest::newRow("simple select 2") << mBuilders.count() << QString("SELECT col1, col2 FROM table") << QVector<QVariant>();
qb.addValueCondition("col1", Query::Equals, QVariant(5));
QVector<QVariant> bindVals;
bindVals << QVariant(5);
mBuilders << qb;
QTest::newRow("single where") << mBuilders.count() << QString("SELECT col1, col2 FROM table WHERE ( col1 = :0 )") << bindVals;
qb.addColumnCondition("col1", Query::LessOrEqual, "col2");
mBuilders << qb;
QTest::newRow("flat where") << mBuilders.count() << QString("SELECT col1, col2 FROM table WHERE ( col1 = :0 AND col1 <= col2 )") << bindVals;
qb.setSubQueryMode(Query::Or);
mBuilders << qb;
QTest::newRow("flat where 2") << mBuilders.count() << QString("SELECT col1, col2 FROM table WHERE ( col1 = :0 OR col1 <= col2 )") << bindVals;
Condition subCon;
subCon.addColumnCondition("col1", Query::Greater, "col2");
subCon.addValueCondition("col1", Query::NotEquals, QVariant());
qb.addCondition(subCon);
mBuilders << qb;
QTest::newRow("hierarchical where") << mBuilders.count() << QString("SELECT col1, col2 FROM table WHERE ( col1 = :0 OR col1 <= col2 OR ( col1 > col2 AND col1 <> NULL ) )") << bindVals;
qb = QueryBuilder("table");
qb.addAggregation("col1", "count");
mBuilders << qb;
QTest::newRow("single aggregation") << mBuilders.count() << QString("SELECT count(col1) FROM table") << QVector<QVariant>();
qb = QueryBuilder("table");
qb.addColumn("col1");
qb.addSortColumn("col1");
mBuilders << qb;
QTest::newRow("single order by") << mBuilders.count() << QString("SELECT col1 FROM table ORDER BY col1 ASC") << QVector<QVariant>();
qb.addSortColumn("col2", Query::Descending);
mBuilders << qb;
QTest::newRow("multiple order by") << mBuilders.count() << QString("SELECT col1 FROM table ORDER BY col1 ASC, col2 DESC") << QVector<QVariant>();
qb = QueryBuilder("table");
qb.addColumn("col1");
QStringList vals;
vals << "a" << "b" << "c";
qb.addValueCondition("col1", Query::In, vals);
bindVals.clear();
bindVals << QString("a") << QString("b") << QString("c");
mBuilders << qb;
QTest::newRow("where in") << mBuilders.count() << QString("SELECT col1 FROM table WHERE ( col1 IN ( :0, :1, :2 ) )") << bindVals;
qb = QueryBuilder("table", QueryBuilder::Select);
qb.setDatabaseType(DbType::MySQL);
qb.addColumn("col1");
qb.setLimit(1);
mBuilders << qb;
QTest::newRow("SELECT with LIMIT") << mBuilders.count() << QString("SELECT col1 FROM table LIMIT 1") << QVector<QVariant>();
qb = QueryBuilder("table", QueryBuilder::Update);
qb.setColumnValue("col1", QString("bla"));
bindVals.clear();
bindVals << QString("bla");
mBuilders << qb;
QTest::newRow("update") << mBuilders.count() << QString("UPDATE table SET col1 = :0") << bindVals;
qb = QueryBuilder("table1", QueryBuilder::Update);
qb.setDatabaseType(DbType::MySQL);
qb.addJoin(QueryBuilder::InnerJoin, "table2", "table1.id", "table2.id");
qb.addJoin(QueryBuilder::InnerJoin, "table3", "table1.id", "table3.id");
qb.setColumnValue("col1", QString("bla"));
bindVals.clear();
bindVals << QString("bla");
mBuilders << qb;
QTest::newRow("update multi table MYSQL") << mBuilders.count() << QString("UPDATE table1, table2, table3 SET col1 = :0 WHERE ( ( table1.id = table2.id ) AND ( table1.id = table3.id ) )")
<< bindVals;
qb = QueryBuilder("table1", QueryBuilder::Update);
qb.setDatabaseType(DbType::PostgreSQL);
qb.addJoin(QueryBuilder::InnerJoin, "table2", "table1.id", "table2.id");
qb.addJoin(QueryBuilder::InnerJoin, "table3", "table1.id", "table3.id");
qb.setColumnValue("col1", QString("bla"));
mBuilders << qb;
QTest::newRow("update multi table PSQL") << mBuilders.count() << QString("UPDATE table1 SET col1 = :0 FROM table2 JOIN table3 WHERE ( ( table1.id = table2.id ) AND ( table1.id = table3.id ) )")
<< bindVals;
///TODO: test for subquery in SQLite case
qb = QueryBuilder("table", QueryBuilder::Insert);
qb.setColumnValue("col1", QString("bla"));
//.........这里部分代码省略.........