0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Fix broken test code, see #400

This commit is contained in:
Roland Bock 2021-12-11 19:31:25 +01:00
parent 36d3d30254
commit 91b7b34557
2 changed files with 40 additions and 35 deletions

View File

@ -31,9 +31,6 @@
#include <iostream> #include <iostream>
#include <vector> #include <vector>
SQLPP_ALIAS_PROVIDER(left)
SQLPP_ALIAS_PROVIDER(right)
namespace mysql = sqlpp::mysql; namespace mysql = sqlpp::mysql;
int Sample(int, char*[]) int Sample(int, char*[])
{ {
@ -118,29 +115,34 @@ int Sample(int, char*[])
db(dynin); db(dynin);
// remove // remove
db(remove_from(tab).where(tab.alpha == tab.alpha + 3));
std::cerr << "+++++++++++++++++++++++++++" << std::endl;
for (const auto& row : db(select(all_of(tab)).from(tab).unconditionally()))
{ {
std::cerr << __LINE__ << " row.beta: " << row.beta << std::endl; db(remove_from(tab).where(tab.alpha == tab.alpha + 3));
}
std::cerr << "+++++++++++++++++++++++++++" << std::endl;
decltype(db(select(all_of(tab)).from(tab).unconditionally())) result;
result = db(select(all_of(tab)).from(tab).unconditionally());
std::cerr << "Accessing a field directly from the result (using the current row): " << result.begin()->alpha
<< std::endl;
std::cerr << "Can do that again, no problem: " << result.begin()->alpha << std::endl;
auto tx = start_transaction(db); std::cerr << "+++++++++++++++++++++++++++" << std::endl;
if (const auto& row = for (const auto& row : db(select(all_of(tab)).from(tab).unconditionally()))
*db(select(all_of(tab), select(max(tab.alpha)).from(tab)).from(tab).unconditionally()).begin()) {
{ std::cerr << __LINE__ << " row.beta: " << row.beta << std::endl;
int a = row.alpha; }
int m = row.max; std::cerr << "+++++++++++++++++++++++++++" << std::endl;
std::cerr << __LINE__ << " row.alpha: " << a << ", row.max: " << m << std::endl; decltype(db(select(all_of(tab)).from(tab).unconditionally())) result;
result = db(select(all_of(tab)).from(tab).unconditionally());
std::cerr << "Accessing a field directly from the result (using the current row): " << result.begin()->alpha
<< std::endl;
std::cerr << "Can do that again, no problem: " << result.begin()->alpha << std::endl;
}
// transaction
{
auto tx = start_transaction(db);
auto result = db(select(all_of(tab), select(max(tab.alpha)).from(tab)).from(tab).unconditionally());
if (const auto& row = *result.begin())
{
long a = row.alpha;
long m = row.max;
std::cerr << __LINE__ << " row.alpha: " << a << ", row.max: " << m << std::endl;
}
tx.commit();
} }
tx.commit();
TabFoo foo; TabFoo foo;
for (const auto& row : db(select(tab.alpha).from(tab.join(foo).on(tab.alpha == foo.omega)).unconditionally())) for (const auto& row : db(select(tab.alpha).from(tab.join(foo).on(tab.alpha == foo.omega)).unconditionally()))
@ -169,7 +171,7 @@ int Sample(int, char*[])
} }
std::cerr << "--------" << std::endl; std::cerr << "--------" << std::endl;
ps.params.gamma = "false"; ps.params.gamma = false;
for (const auto& row : db(ps)) for (const auto& row : db(ps))
{ {
std::cerr << "bound result: alpha: " << row.alpha << std::endl; std::cerr << "bound result: alpha: " << row.alpha << std::endl;

View File

@ -39,8 +39,6 @@
const auto library_raii = sqlpp::mysql::scoped_library_initializer_t{0, nullptr, nullptr}; const auto library_raii = sqlpp::mysql::scoped_library_initializer_t{0, nullptr, nullptr};
SQLPP_ALIAS_PROVIDER(left)
namespace sql = sqlpp::mysql; namespace sql = sqlpp::mysql;
const auto tab = TabSample{}; const auto tab = TabSample{};
@ -149,22 +147,27 @@ int Select(int, char*[])
db(update(tab).set(tab.gamma = false).where(tab.alpha.in(sqlpp::value_list(std::vector<int>{1, 2, 3, 4})))); db(update(tab).set(tab.gamma = false).where(tab.alpha.in(sqlpp::value_list(std::vector<int>{1, 2, 3, 4}))));
// remove // remove
{
db(remove_from(tab).where(tab.alpha == tab.alpha + 3)); db(remove_from(tab).where(tab.alpha == tab.alpha + 3));
auto result = db(select(all_of(tab)).from(tab).unconditionally()); auto result = db(select(all_of(tab)).from(tab).unconditionally());
std::cerr << "Accessing a field directly from the result (using the current row): " << result.begin()->alpha std::cerr << "Accessing a field directly from the result (using the current row): " << result.begin()->alpha
<< std::endl; << std::endl;
std::cerr << "Can do that again, no problem: " << result.begin()->alpha << std::endl; std::cerr << "Can do that again, no problem: " << result.begin()->alpha << std::endl;
auto tx = start_transaction(db);
if (const auto& row =
*db(select(all_of(tab), select(max(tab.alpha)).from(tab)).from(tab).unconditionally()).begin())
{
int a = row.alpha;
int m = row.max;
std::cerr << "-----------------------------" << a << ", " << m << std::endl;
} }
tx.commit();
// transaction
{
auto tx = start_transaction(db);
auto result = db(select(all_of(tab), select(max(tab.alpha)).from(tab)).from(tab).unconditionally());
if (const auto& row = *result.begin())
{
long a = row.alpha;
long m = row.max;
std::cerr << "-----------------------------" << a << ", " << m << std::endl;
}
tx.commit();
}
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {