40 namespace sph = oral::sph;
42 void OralTest_SimpleRecord::testSimpleRecordInsertSelect ()
44 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
45 const auto& list = adapted->Select ();
49 void OralTest_SimpleRecord::testSimpleRecordInsertReplaceSelect ()
53 auto adapted = Util::oral::AdaptPtr<SimpleRecord, OralFactory> (db);
54 for (
int i = 0; i < 3; ++i)
55 adapted->Insert ({ 0, QString::number (i) }, lco::InsertAction::Replace::PKey<SimpleRecord>);
57 const auto& list = adapted->Select ();
61 void OralTest_SimpleRecord::testSimpleRecordInsertIgnoreSelect ()
65 auto adapted = Util::oral::AdaptPtr<SimpleRecord, OralFactory> (db);
66 for (
int i = 0; i < 3; ++i)
69 const auto& list = adapted->Select ();
73 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos ()
75 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
76 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> == 1);
80 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos2 ()
82 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
83 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2);
87 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByPos3 ()
89 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
90 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2 && sph::f<&SimpleRecord::Value_> == QString {
"1" });
94 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOneByPos ()
96 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
97 const auto& single = adapted->SelectOne (sph::f<&SimpleRecord::ID_> == 1);
98 QCOMPARE (single, (std::optional<SimpleRecord> { { 1,
"1" } }));
101 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields ()
103 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
104 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> == 1);
108 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields2 ()
110 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
111 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2);
115 void OralTest_SimpleRecord::testSimpleRecordInsertSelectByFields3 ()
117 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
118 const auto& list = adapted->Select (sph::f<&SimpleRecord::ID_> < 2 && sph::f<&SimpleRecord::Value_> == QString {
"1" });
122 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOneByFields ()
124 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
125 const auto& single = adapted->SelectOne (sph::f<&SimpleRecord::ID_> == 1);
126 QCOMPARE (single, (std::optional<SimpleRecord> { { 1,
"1" } }));
129 void OralTest_SimpleRecord::testSimpleRecordInsertSelectSingleFieldByFields ()
131 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
132 const auto& list = adapted->Select (sph::fields<&SimpleRecord::Value_>, sph::f<&SimpleRecord::ID_> < 2);
136 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFields ()
138 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
139 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>, sph::f<&SimpleRecord::ID_> < 2);
140 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
143 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderAsc ()
145 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
146 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
147 sph::f<&SimpleRecord::ID_> < 2,
149 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
152 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderDesc ()
154 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
155 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
156 sph::f<&SimpleRecord::ID_> < 2,
158 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 1,
"1" }, { 0,
"0" } }));
161 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderManyAsc ()
163 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
164 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
165 sph::f<&SimpleRecord::ID_> < 2,
166 oral::OrderBy<sph::asc<&SimpleRecord::Value_>, sph::desc<&SimpleRecord::ID_>>);
167 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 0,
"0" }, { 1,
"1" } }));
170 void OralTest_SimpleRecord::testSimpleRecordInsertSelectFieldsByFieldsOrderManyDesc ()
172 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
173 const auto& list = adapted->Select (sph::fields<&SimpleRecord::ID_, &SimpleRecord::Value_>,
174 sph::f<&SimpleRecord::ID_> < 2,
175 oral::OrderBy<sph::desc<&SimpleRecord::Value_>, sph::asc<&SimpleRecord::ID_>>);
176 QCOMPARE (list, (
QList<std::tuple<int, QString>> { { 1,
"1" }, { 0,
"0" } }));
179 void OralTest_SimpleRecord::testSimpleRecordInsertSelectNoOffsetLimit ()
181 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase (), 10);
182 const auto& list = adapted->Select.Build ().Limit ({ 2 }) ();
186 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOffsetNoLimit ()
188 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase (), 10);
189 const auto& list = adapted->Select.Build ().Offset ({ 8 }) ();
193 void OralTest_SimpleRecord::testSimpleRecordInsertSelectOffsetLimit ()
195 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase (), 10);
196 const auto& list = adapted->Select.Build ().Offset ({ 5 }).Limit ({ 2 }) ();
200 void OralTest_SimpleRecord::testSimpleRecordInsertSelectCount ()
202 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
203 const auto count = adapted->Select (sph::count<>);
207 void OralTest_SimpleRecord::testSimpleRecordInsertSelectCountByFields ()
209 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
210 const auto count = adapted->Select (sph::count<>, sph::f<&SimpleRecord::ID_> < 2);
214 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMin ()
216 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
217 const auto min = adapted->Select (sph::min<&SimpleRecord::ID_>);
221 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMax ()
223 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
224 const auto max = adapted->Select (sph::max<&SimpleRecord::ID_>);
228 void OralTest_SimpleRecord::testSimpleRecordInsertSelectMinPlusMax ()
230 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
231 const auto minMax = adapted->Select (sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>);
232 QCOMPARE (minMax, (std::tuple { 0, 2 }));
235 void OralTest_SimpleRecord::testSimpleRecordInsertSelectValuePlusMinPlusMax ()
237 auto adapted = oral::AdaptPtr<SimpleRecord, OralFactory> (
MakeDatabase ());
238 for (
int i = 0; i < 3; ++i)
239 adapted->Insert ({ i,
"0" });
240 for (
int i = 3; i < 6; ++i)
241 adapted->Insert ({ i,
"1" });
243 const auto allMinMax = adapted->Select.Build ()
244 .Select (sph::fields<&SimpleRecord::Value_> + sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>)
245 .Group (oral::GroupBy<&SimpleRecord::Value_>)
247 QCOMPARE (allMinMax, (
QList<std::tuple<QString, int, int>> { { {
"0" }, 0, 2 }, { {
"1" }, 3, 5 } }));
250 void OralTest_SimpleRecord::testSimpleRecordInsertSelectAllPlusMinPlusMax ()
252 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase (), 2);
253 const auto allMinMax = adapted->Select.Build ()
254 .Select (
sph::all + sph::min<&SimpleRecord::ID_> + sph::max<&SimpleRecord::ID_>)
257 QCOMPARE (allMinMax, (
QList<std::tuple<SimpleRecord, int, int>> { { { 0,
"0" }, 0, 0 }, { { 1,
"1" }, 1, 1 } }));
260 void OralTest_SimpleRecord::testSimpleRecordInsertSelectLike ()
262 using namespace oral::infix;
264 auto adapted = Util::oral::AdaptPtr<SimpleRecord, OralFactory> (
MakeDatabase ());
265 adapted->Insert ({ 0,
"foo" });
266 adapted->Insert ({ 1,
"bar" });
267 adapted->Insert ({ 2,
"foobar" });
268 const auto& list = adapted->Select (sph::f<&SimpleRecord::Value_> |
like| QString {
"%oo%" });
272 void OralTest_SimpleRecord::testSimpleRecordUpdate ()
274 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
275 adapted->Update ({ 0,
"meh" });
276 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 0);
280 void OralTest_SimpleRecord::testSimpleRecordUpdateExprTree ()
282 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
283 adapted->Update (sph::f<&SimpleRecord::Value_> = QString {
"meh" }, sph::f<&SimpleRecord::ID_> == 0);
284 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 0);
288 void OralTest_SimpleRecord::testSimpleRecordUpdateMultiExprTree ()
290 auto adapted = PrepareRecords<SimpleRecord> (
MakeDatabase ());
291 adapted->Update ((sph::f<&SimpleRecord::Value_> = QString {
"meh" }, sph::f<&SimpleRecord::ID_> = 10),
292 sph::f<&SimpleRecord::ID_> == 0);
293 const auto updated = adapted->Select (sph::f<&SimpleRecord::ID_> == 10);
lco::PKey< int, lco::NoAutogen > ID_
static struct LC::Util::oral::InsertAction::IgnoreTag Ignore
constexpr detail::AggregateType< detail::AggregateFunction::Count, Ptr > count
constexpr detail::OrderBy< Orders... > OrderBy
constexpr detail::AggregateType< detail::AggregateFunction::Max, Ptr > max
QSqlDatabase MakeDatabase(const QString &name=":memory:")
constexpr detail::InfixBinary< detail::ExprType::Like > like
constexpr detail::AggregateType< detail::AggregateFunction::Min, Ptr > min
constexpr detail::SelectWhole all