-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Perform a column alias mapping (#29)
* Perform a column alias mapping * Use debug build to enable tiny output * Read query while there's data to read rather then after all data has been readt. * Rebase vcpkg to TinyORM upstream port PR for 3.36.4
- Loading branch information
1 parent
b34683f
commit 6462ecf
Showing
5 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
#include <QtCore/QJsonDocument> | ||
#include <QtCore/QJsonObject> | ||
#include <QtSql/QSqlRecord> | ||
|
||
#include "TinyOrmQueryTest.hpp" | ||
|
||
namespace MyNamespace | ||
|
@@ -120,6 +124,64 @@ namespace MyNamespace | |
QVERIFY(exceptionReceived); | ||
QCOMPARE(rowCount, 2); | ||
} | ||
|
||
void MyTinyTest::columnAlias() | ||
{ | ||
try { | ||
|
||
Orm::DB::beginTransaction(); | ||
Orm::Schema::create( | ||
"users", | ||
[](Orm::SchemaNs::Blueprint &table) | ||
{ | ||
table.id(); | ||
table.text("email").nullable(); | ||
table.text("name").nullable(); | ||
} | ||
); | ||
|
||
Orm::DB::table("users")->insertGetId( | ||
QVariantMap{ | ||
{"name", "John Doe"}, | ||
{"email", "[email protected]"} | ||
} | ||
); | ||
|
||
Orm::DB::table("users")->insertGetId( | ||
QVariantMap{ | ||
{"name", "Jane Doe"}, | ||
{"email", "[email protected]"} | ||
} | ||
); | ||
|
||
QSqlQuery query = Orm::DB::table("users") | ||
->select({"name", "email AS user_email"}) | ||
.get(); | ||
|
||
for(int n=0; query.next(); ++n) { | ||
QSqlRecord record(query.record()); | ||
for(int i=0; i<record.count(); ++i) { | ||
qDebug() << QJsonDocument( | ||
QJsonObject{ | ||
{ "row number", n }, | ||
{ "column index", i }, | ||
{ "column name", record.fieldName(i) }, | ||
{ "column value", query.value(record.fieldName(i)).toString() } | ||
}).toJson().constData(); | ||
} | ||
|
||
QVERIFY((QStringList() << "[email protected]" << "[email protected]").contains(query.value("user_email"))); | ||
} | ||
|
||
Orm::Schema::drop("users"); | ||
Orm::DB::commit(); | ||
} | ||
catch (const std::exception &ex) | ||
{ | ||
Orm::DB::rollBack(); | ||
qCritical() << ex.what(); | ||
} | ||
} | ||
} | ||
|
||
QTEST_MAIN(MyNamespace::MyTinyTest); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters