From 91b7b345571a7b7ea4f5d38c7431dc154d364f14 Mon Sep 17 00:00:00 2001 From: Roland Bock Date: Sat, 11 Dec 2021 19:31:25 +0100 Subject: [PATCH] Fix broken test code, see #400 --- tests/mysql/usage/Sample.cpp | 50 +++++++++++++++++++----------------- tests/mysql/usage/Select.cpp | 25 ++++++++++-------- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/tests/mysql/usage/Sample.cpp b/tests/mysql/usage/Sample.cpp index f4f0b12d..39fe56ed 100644 --- a/tests/mysql/usage/Sample.cpp +++ b/tests/mysql/usage/Sample.cpp @@ -31,9 +31,6 @@ #include #include -SQLPP_ALIAS_PROVIDER(left) -SQLPP_ALIAS_PROVIDER(right) - namespace mysql = sqlpp::mysql; int Sample(int, char*[]) { @@ -118,29 +115,34 @@ int Sample(int, char*[]) db(dynin); // 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; - } - 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; + db(remove_from(tab).where(tab.alpha == tab.alpha + 3)); - 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 << __LINE__ << " row.alpha: " << a << ", row.max: " << m << std::endl; + 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; + } + 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; + } + + // 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; 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; - ps.params.gamma = "false"; + ps.params.gamma = false; for (const auto& row : db(ps)) { std::cerr << "bound result: alpha: " << row.alpha << std::endl; diff --git a/tests/mysql/usage/Select.cpp b/tests/mysql/usage/Select.cpp index d7787065..6472d4a8 100644 --- a/tests/mysql/usage/Select.cpp +++ b/tests/mysql/usage/Select.cpp @@ -39,8 +39,6 @@ const auto library_raii = sqlpp::mysql::scoped_library_initializer_t{0, nullptr, nullptr}; -SQLPP_ALIAS_PROVIDER(left) - namespace sql = sqlpp::mysql; 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{1, 2, 3, 4})))); // remove + { db(remove_from(tab).where(tab.alpha == tab.alpha + 3)); 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::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) {