21 void OralTest_SimpleRecord::testSimpleRecordInsertSelect ()
24 const auto& list = adapted->Select ();
25 QCOMPARE (list, (QList<SimpleRecord> { { 0,
"0" }, { 1,
"1" }, { 2,
"2" } }));
28 void OralTest_SimpleRecord::testSimpleRecordInsertReplaceSelect ()
33 for (
int i = 0; i < 3; ++i)
36 const auto& list = adapted->Select ();
37 QCOMPARE (list, (QList<SimpleRecord> { { 0,
"2" } }));
40 void OralTest_SimpleRecord::testSimpleRecordInsertIgnoreSelect ()
45 for (
int i = 0; i < 3; ++i)
48 const auto& list = adapted->Select ();
49 QCOMPARE (list, (QList<SimpleRecord> { { 0,
"0" } }));
52 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos ()
55 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> == 1);
56 QCOMPARE (list, (QList<SimpleRecord> { { 1,
"1" } }));
59 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos2 ()
62 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2);
63 QCOMPARE (list, (QList<SimpleRecord> { { 0,
"0" }, { 1,
"1" } }));
66 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos3 ()
69 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2 && sph::f<&SimpleRecord::Value_> == QString {
"1" });
70 QCOMPARE (list, (QList<SimpleRecord> { { 1,
"1" } }));
73 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOneByPos ()
76 const auto& single = adapted->SelectOne (sph::f<&SimpleRecord::ID_> == 1);
77 QCOMPARE (single, (std::optional<SimpleRecord> { { 1,
"1" } }));
80 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields ()
83 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> == 1);
84 QCOMPARE (list, (QList<SimpleRecord> { { 1,
"1" } }));
87 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields2 ()
90 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2);
91 QCOMPARE (list, (QList<SimpleRecord> { { 0,
"0" }, { 1,
"1" } }));
94 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields3 ()
97 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2 && sph::f<&SimpleRecord::Value_> == QString {
"1" });
98 QCOMPARE (list, (QList<SimpleRecord> { { 1,
"1" } }));
101 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOneByFields ()
104 const auto& single = adapted->SelectOne (sph::f<&SimpleRecord::ID_> == 1);
105 QCOMPARE (single, (std::optional<SimpleRecord> { { 1,
"1" } }));
108 void OralTest_SimpleRecord::testSimpleRecordInsertSelectSingleFieldByFields ()
111 const auto& list = adapted->Select (sph::fields<&SimpleRecord::Value_>, sph::f<&SimpleRecord::ID_> < 2);
112 QCOMPARE (list, (QList<QString> {
"0",
"1" }));
115 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFields ()
118 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>, sph::f<&SimpleRecord::ID_> < 2);
119 QCOMPARE (list, (QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
122 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderAsc ()
125 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
126 sph::f<&SimpleRecord::ID_> < 2,
128 QCOMPARE (list, (QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
131 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderDesc ()
134 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
135 sph::f<&SimpleRecord::ID_> < 2,
137 QCOMPARE (list, (QList<std::tuple<int, QString>> { { 1,
"1" }, { 0,
"0" } }));
140 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderManyAsc ()
143 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
144 sph::f<&SimpleRecord::ID_> < 2,
145 oral::OrderBy<sph::asc<&SimpleRecord::Value_>, sph::desc<&SimpleRecord::ID_>>);
146 QCOMPARE (list, (QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
149 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderManyDesc ()
152 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
153 sph::f<&SimpleRecord::ID_> < 2,
154 oral::OrderBy<sph::desc<&SimpleRecord::Value_>, sph::asc<&SimpleRecord::ID_>>);
155 QCOMPARE (list, (QList<std::tuple<int, QString>> { { 1,
"1" }, { 0,
"0" } }));
158 void OralTest_SimpleRecord::testSimpleRecordInsertSelectNoOffsetLimit ()
161 const auto& list = adapted->Select.Build ().Limit (2) ();
162 QCOMPARE (list, (QList<SimpleRecord> { { 0,
"0" }, { 1,
"1" } }));
174 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOffsetLimit ()
177 const auto& list = adapted->Select.Build ().Offset (5).Limit (2) ();
178 QCOMPARE (list, (QList<SimpleRecord> { { 5,
"5" }, { 6,
"6" } }));
181 void OralTest_SimpleRecord::testSimpleRecordInsertSelectCount ()
184 const auto count = adapted->Select (sph::count<>);
188 void OralTest_SimpleRecord::testSimpleRecordInsertSelectCountByFields ()
191 const auto count = adapted->Select (sph::count<>, sph::f<&SimpleRecord::ID_> < 2);
195 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMin ()
198 const auto min = adapted->Select (sph::min<&SimpleRecord::ID_>);
202 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMax ()
205 const auto max = adapted->Select (sph::max<&SimpleRecord::ID_>);
209 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMinPlusMax ()
212 const auto minMax = adapted->Select (sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>);
213 QCOMPARE (minMax, (std::tuple { 0, 2 }));
216 void OralTest_SimpleRecord::testSimpleRecordInsertSelectValuePlusMinPlusMax ()
219 for (
int i = 0; i < 3; ++i)
220 adapted->Insert ({ i,
"0" });
221 for (
int i = 3; i < 6; ++i)
222 adapted->Insert ({ i,
"1" });
224 const auto allMinMax = adapted->Select.Build ()
225 .Select (sph::fields<&SimpleRecord::Value_> + sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>)
228 QCOMPARE (allMinMax, (QList<std::tuple<QString, int, int>> { { {
"0" }, 0, 2 }, { {
"1" }, 3, 5 } }));
231 void OralTest_SimpleRecord::testSimpleRecordInsertSelectAllPlusMinPlusMax ()
234 const auto allMinMax = adapted->Select.Build ()
235 .Select (sph::all + sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>)
238 QCOMPARE (allMinMax, (QList<std::tuple<SimpleRecord, int, int>> { { { 0,
"0" }, 0, 0 }, { { 1,
"1" }, 1, 1 } }));
241 void OralTest_SimpleRecord::testSimpleRecordInsertSelectLike ()
243 using namespace oral::infix;
246 adapted->Insert ({ 0,
"foo" });
247 adapted->Insert ({ 1,
"bar" });
248 adapted->Insert ({ 2,
"foobar" });
249 const auto& list = adapted->Select (sph::f<&SimpleRecord::Value_> |like| QString {
"%oo%" });
250 QCOMPARE (list, (QList<SimpleRecord> { { 0,
"foo" }, { 2,
"foobar" } }));
253 void OralTest_SimpleRecord::testSimpleRecordUpdate ()
256 adapted->Update ({ 0,
"meh" });
257 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 0);
258 QCOMPARE (updated, (QList<SimpleRecord> { { 0,
"meh" } }));
261 void OralTest_SimpleRecord::testSimpleRecordUpdateExprTree ()
264 adapted->Update (sph::f<&SimpleRecord::Value_> = QString {
"meh" }, sph::f<&SimpleRecord::ID_> == 0);
265 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 0);
266 QCOMPARE (updated, (QList<SimpleRecord> { { 0,
"meh" } }));
269 void OralTest_SimpleRecord::testSimpleRecordUpdateMultiExprTree ()
272 adapted->Update ((sph::f<&SimpleRecord::Value_> = QString {
"meh" }, sph::f<&SimpleRecord::ID_> = 10),
273 sph::f<&SimpleRecord::ID_> == 0);
274 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 10);
275 QCOMPARE (updated, (QList<SimpleRecord> { { 10,
"meh" } }));
constexpr detail::AggregateType< detail::AggregateFunction::Count, Ptr > count
constexpr detail::AggregateType< detail::AggregateFunction::Min, Ptr > min
constexpr detail::AggregateType< detail::AggregateFunction::Max, Ptr > max
ObjectInfo_ptr< T > AdaptPtr(const QSqlDatabase &db)
constexpr detail::OrderBy< Orders... > OrderBy
constexpr detail::GroupBy< Ptrs... > GroupBy
auto PrepareRecords(QSqlDatabase db, int count=3)
QSqlDatabase MakeDatabase(const QString &name=":memory:")
static constexpr struct LC::Util::oral::InsertAction::Replace::PKeyType PKey
static constexpr struct LC::Util::oral::InsertAction::IgnoreTag Ignore
lco::PKey< int, lco::NoAutogen > ID_