From d1e33b534a193ec692db585d3532bcf3b0a32694 Mon Sep 17 00:00:00 2001 From: Jacyking <791026912@qq.com> Date: Mon, 16 Oct 2023 22:42:11 +0800 Subject: [PATCH] fix pg --- include/postgresql.hpp | 40 +++--- include/utility.hpp | 5 +- tests/test_ormpp.cpp | 294 +++++++++++++++++++++-------------------- 3 files changed, 177 insertions(+), 162 deletions(-) diff --git a/include/postgresql.hpp b/include/postgresql.hpp index bc585278..40909fc7 100644 --- a/include/postgresql.hpp +++ b/include/postgresql.hpp @@ -39,9 +39,10 @@ class postgresql { template bool connect(Args &&...args) { reset_error(); - auto sql = ""s; - sql = generate_conn_sql(std::make_tuple(std::forward(args)...)); - + auto sql = generate_conn_sql(std::make_tuple(std::forward(args)...)); +#ifdef ORMPP_ENABLE_LOG + std::cout << sql << std::endl; +#endif con_ = PQconnectdb(sql.data()); if (PQstatus(con_) != CONNECTION_OK) { set_last_error(PQerrorMessage(con_)); @@ -177,7 +178,6 @@ class postgresql { template constexpr std::enable_if_t, std::vector> query( Args &&...args) { - reset_error(); std::string sql = generate_query_sql(args...); #ifdef ORMPP_ENABLE_LOG std::cout << sql << std::endl; @@ -213,7 +213,6 @@ class postgresql { template constexpr std::enable_if_t, std::vector> query( const Arg &s, Args &&...args) { - reset_error(); static_assert(iguana::is_tuple::value); constexpr auto SIZE = std::tuple_size_v; @@ -354,6 +353,12 @@ class postgresql { "dbname", "connect_timeout"), tp, std::make_index_sequence{}); } + else if constexpr (SIZE == 6) { + return generate_conn_sql( + std::make_tuple("host", "user", "password", "dbname", + "connect_timeout", "port"), + tp, std::make_index_sequence{}); + } else { return ""; } @@ -488,10 +493,11 @@ class postgresql { template bool prepare(const std::string &sql) { + reset_error(); res_ = PQprepare(con_, "", sql.data(), (int)iguana::get_value(), nullptr); if (PQresultStatus(res_) != PGRES_COMMAND_OK) { - std::cout << PQresultErrorMessage(res_) << std::endl; + set_last_error(PQresultErrorMessage(res_)); PQclear(res_); return false; } @@ -528,15 +534,18 @@ class postgresql { std::cout << sql << std::endl; #endif std::vector> param_values; - auto it = auto_key_map_.find(iguana::get_name().data()); + auto name = iguana::get_name().data(); + auto it = auto_key_map_.find(name); std::string auto_key = (it == auto_key_map_.end()) ? "" : it->second; - iguana::for_each(t, - [&t, ¶m_values, &auto_key, this](auto item, auto i) { - /*if(!auto_key.empty()&&auto_key==iguana::get_name(decltype(i)::value).data()) - return;*/ - set_param_values(param_values, t.*item); - }); + iguana::for_each( + t, [&t, ¶m_values, auto_key, name, this](auto item, auto i) { + if (!auto_key.empty() && + auto_key == iguana::get_name(decltype(i)::value).data()) { + return; + } + set_param_values(param_values, t.*item); + }); if (param_values.empty()) return INT_MIN; @@ -686,8 +695,9 @@ class postgresql { int index = 0; for (auto i = 0; i < SIZE; ++i) { std::string field_name = iguana::get_name(i).data(); - // if(it!=auto_key_map_.end()&&it->second==field_name) - // continue; + if (it != auto_key_map_.end() && it->second == field_name) { + continue; + } values += "$"; char temp[20] = {}; diff --git a/include/utility.hpp b/include/utility.hpp index 19af0c10..fc822dfb 100644 --- a/include/utility.hpp +++ b/include/utility.hpp @@ -136,11 +136,10 @@ inline void for_each0(const std::tuple &t, Func &&f, template >> inline std::string get_name() { #ifdef ORMPP_ENABLE_PG - std::string quota_name = "'" + std::string(iguana::get_name()) + "'"; + std::string quota_name = std::string(iguana::get_name()); #else std::string quota_name = "`" + std::string(iguana::get_name()) + "`"; #endif - return quota_name; } @@ -229,7 +228,6 @@ inline std::string generate_delete_sql(Args &&...where_conditon) { if (!is_empty(std::forward(where_conditon)...)) // fix for vs2017 append(sql, " where ", std::forward(where_conditon)...); } - return sql; } @@ -240,7 +238,6 @@ inline bool has_key(const std::string &s) { if (s.find(arr[i].data()) != std::string::npos) return true; } - return false; } diff --git a/tests/test_ormpp.cpp b/tests/test_ormpp.cpp index ea84b739..db0d7916 100644 --- a/tests/test_ormpp.cpp +++ b/tests/test_ormpp.cpp @@ -26,6 +26,7 @@ const char *password = "123456"; const char *password = ""; #endif const char *ip = "127.0.0.1"; +const char *username = "root"; const char *db = "test_ormppdb"; struct person { @@ -55,7 +56,7 @@ REFLECTION(simple, id, code, age); // TEST_CASE(mysql_performance){ // dbng mysql; // -// REQUIRE(mysql.connect(ip, "root", password, db)); +// REQUIRE(mysql.connect(ip, username, password, db)); // REQUIRE(mysql.execute("DROP TABLE IF EXISTS student")); // // ormpp_auto_increment_key auto_key{"code"}; @@ -102,7 +103,7 @@ REFLECTION(test_optional, id, name, age); TEST_CASE("test optional") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.create_datatable(ormpp_auto_key{"id"}); mysql.delete_records(); mysql.insert({0, "purecpp", 200}); @@ -147,7 +148,7 @@ REFLECTION(test_order, name, id); TEST_CASE("random_reflection_order") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db, + if (mysql.connect(ip, username, password, db, /*timeout_seconds=*/5, 3306)) { REQUIRE(mysql.execute( "create table if not exists `test_order` (id int, name text);")); @@ -172,7 +173,7 @@ REFLECTION_WITH_NAME(custom_name, "test_order", id, name); TEST_CASE("orm_custom_name") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { auto vec1 = mysql.query(); CHECK(vec1.size() > 0); auto vec2 = mysql.query(FID(custom_name::name), "=", "hello"); @@ -189,7 +190,7 @@ REFLECTION(dummy, id, name); // TEST_CASE("mysql_exist_tb") { // dbng mysql; -// REQUIRE(mysql.connect(ip, "root", password, db, +// REQUIRE(mysql.connect(ip, username, password, db, // /*timeout_seconds=*/5, 3306)); // dummy d{0, "tom"}; // dummy d1{0, "jerry"}; @@ -199,35 +200,77 @@ REFLECTION(dummy, id, name); // std::cout << v.size() << "\n"; // } -TEST_CASE("mysql_pool") { - // dbng sqlite; - // sqlite.connect(db); - // sqlite.create_datatable(ormpp_unique{{"name"}}); - // test_tb tb{ 1, "aa" }; - // sqlite.insert(tb); - // auto vt = sqlite.query(); - // auto vt1 = sqlite.query>("select * from test_tb"); - // auto& pool = connection_pool>::instance(); - // try { - // pool.init(1, ip, "root", password, db, 2); - // }catch(const std::exception& e){ - // std::cout<query>("select * from test_tb"); - // con->create_datatable(ormpp_unique{{"name"}}); - // for (int i = 0; i < 10; ++i) { - // auto conn = pool.get(); - //// conn_guard guard(conn); - // if(conn== nullptr){ - // std::cout<<"no available conneciton"<create_datatable(); - // } -} +// #ifdef ORMPP_ENABLE_MYSQL +// TEST_CASE("mysql_pool") { +// dbng sqlite; +// sqlite.connect(db); +// sqlite.create_datatable(ormpp_unique{{"name"}}); +// test_tb tb{ 1, "aa" }; +// sqlite.insert(tb); +// auto vt = sqlite.query(); +// auto vt1 = sqlite.query>("select * from test_tb"); +// auto& pool = connection_pool>::instance(); +// try { +// pool.init(1, ip, username, password, db, 2); +// }catch(const std::exception& e){ +// std::cout<query>("select * from test_tb"); +// con->create_datatable(ormpp_unique{{"name"}}); +// for (int i = 0; i < 10; ++i) { +// auto conn = pool.get(); +//// conn_guard guard(conn); +// if(conn== nullptr){ +// std::cout<<"no available conneciton"<create_datatable(); +// } +// } +// #endif + +// #ifdef ORMPP_ENABLE_PG +// TEST_CASE("postgres_pool") { +// auto &pool = connection_pool>::instance(); +// try { +// pool.init(3, ip, username, password, db, /*timeout_seconds=*/5, 5432); +// pool.init(7, ip, username, password, db, /*timeout_seconds=*/5, 5432); +// } catch (const std::exception &e) { +// std::cout << e.what() << std::endl; +// return; +// } + +// auto conn1 = pool.get(); +// auto conn2 = pool.get(); +// auto conn3 = pool.get(); + +// std::thread thd([conn2, &pool] { +// std::this_thread::sleep_for(std::chrono::seconds(15)); +// pool.return_back(conn2); +// }); + +// auto conn4 = pool.get(); // 10s later, timeout +// CHECK(conn4 == nullptr); +// auto conn5 = pool.get(); +// CHECK(conn5 != nullptr); + +// thd.join(); + +// for (int i = 0; i < 10; ++i) { +// auto conn = pool.get(); +// // conn_guard guard(conn); +// if (conn == nullptr) { +// std::cout << "no available conneciton" << std::endl; +// continue; +// } + +// bool r = conn->create_datatable(); +// } +// } +// #endif TEST_CASE("test_ormpp_cfg") { ormpp_cfg cfg{}; @@ -253,61 +296,21 @@ TEST_CASE("test_ormpp_cfg") { #endif } -#ifdef ORMPP_ENABLE_PG -TEST_CASE("postgres_pool") { - auto &pool = connection_pool>::instance(); - try { - pool.init(3, ip, "root", password, db, 2, 5432); - pool.init(7, ip, "root", password, db, 2, 5432); - } catch (const std::exception &e) { - std::cout << e.what() << std::endl; - return; - } - - auto conn1 = pool.get(); - auto conn2 = pool.get(); - auto conn3 = pool.get(); - - std::thread thd([conn2, &pool] { - std::this_thread::sleep_for(std::chrono::seconds(15)); - pool.return_back(conn2); - }); - - auto conn4 = pool.get(); // 10s later, timeout - CHECK(conn4 == nullptr); - auto conn5 = pool.get(); - CHECK(conn5 != nullptr); - - thd.join(); - - for (int i = 0; i < 10; ++i) { - auto conn = pool.get(); - // conn_guard guard(conn); - if (conn == nullptr) { - std::cout << "no available conneciton" << std::endl; - continue; - } - - bool r = conn->create_datatable(); - } -} -#endif - TEST_CASE("orm_connect") { int timeout = 5; #ifdef ORMPP_ENABLE_PG dbng postgres; - REQUIRE(postgres.connect(ip, "root", password, db)); + REQUIRE(postgres.connect(ip, username, password, db)); REQUIRE(postgres.disconnect()); - REQUIRE(postgres.connect(ip, "root", password, db, timeout)); + REQUIRE(postgres.connect(ip, username, password, db, timeout)); #endif #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - REQUIRE(mysql.connect(ip, "root", password, db)); + REQUIRE(mysql.connect(ip, username, password, db)); REQUIRE(mysql.disconnect()); - REQUIRE(mysql.connect(ip, "root", password, db, timeout)); + REQUIRE(mysql.connect(ip, username, password, db, timeout)); #endif #ifdef ORMPP_ENABLE_SQLITE3 @@ -325,7 +328,7 @@ TEST_CASE("orm_create_table") { #ifdef ORMPP_ENABLE_PG dbng postgres; - REQUIRE(postgres.connect(ip, "root", password, db)); + REQUIRE(postgres.connect(ip, username, password, db)); REQUIRE(postgres.create_datatable()); REQUIRE(postgres.create_datatable(key)); REQUIRE(postgres.create_datatable(not_null)); @@ -351,7 +354,7 @@ TEST_CASE("orm_create_table") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - REQUIRE(mysql.connect(ip, "root", password, db)); + REQUIRE(mysql.connect(ip, username, password, db)); REQUIRE(mysql.create_datatable()); REQUIRE(mysql.create_datatable(key)); REQUIRE(mysql.create_datatable(not_null)); @@ -375,33 +378,53 @@ TEST_CASE("orm_insert_query") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { - auto vec1 = mysql.query(FID(simple::id), "<", "5"); - auto vec2 = mysql.query(FID(simple::id), "<", 5); - auto vec3 = mysql.query(FID(person::name), "<", "5"); - auto vec4 = mysql.query(FID(person::name), "<", 5); + if (mysql.connect(ip, username, password, db)) { + auto vec = mysql.query(FID(person::id), "<", "5"); } #endif #ifdef ORMPP_ENABLE_PG dbng postgres; - if (postgres.connect(ip, "root", password, db)) { - auto vec = postgres.query(FID(simple::id), "<", "5"); + if (postgres.connect(ip, username, password, db)) { + auto vec = postgres.query(FID(person::id), "<", "5"); } #endif #ifdef ORMPP_ENABLE_SQLITE3 dbng sqlite; if (sqlite.connect(db)) { - auto vec = sqlite.query(FID(simple::id), "<", "5"); + auto vec = sqlite.query(FID(person::id), "<", "5"); } #endif // auto key { +#ifdef ORMPP_ENABLE_MYSQL + mysql.execute("drop table if exists student;"); + mysql.create_datatable(auto_key, not_null); + CHECK(mysql.insert(s) == 1); + auto vec1 = mysql.query("limit 3"); + CHECK(vec1.size() == 1); + CHECK(mysql.insert(s) == 1); + CHECK(mysql.insert(v) == 2); + auto vec2 = mysql.query(); + CHECK(vec2.size() == 4); + auto vec3 = mysql.query(); + CHECK(vec3.size() == 4); + v[0].code = 1; + v[1].code = 2; + CHECK(mysql.insert(s) == 1); + auto vec4 = mysql.query(); + CHECK(vec4.size() == 5); + mysql.delete_records(); + CHECK(mysql.insert(v) == 2); + auto vec5 = mysql.query(); + CHECK(vec5.size() == 2); +#endif + #ifdef ORMPP_ENABLE_PG + postgres.execute("drop table if exists student;"); postgres.create_datatable(auto_key, not_null); - postgres.delete_records(); CHECK(postgres.insert(s) == 1); auto vec = postgres.query(); CHECK(vec.size() == 1); @@ -409,8 +432,8 @@ TEST_CASE("orm_insert_query") { #endif #ifdef ORMPP_ENABLE_SQLITE3 - sqlite.create_datatable(auto_key); - sqlite.delete_records(); + sqlite.execute("drop table if exists student;"); + sqlite.create_datatable(auto_key, not_null); CHECK(sqlite.insert(s) == 1); auto vec1 = sqlite.query(); CHECK(vec1.size() == 1); @@ -425,44 +448,27 @@ TEST_CASE("orm_insert_query") { // key { #ifdef ORMPP_ENABLE_MYSQL - mysql.create_datatable(auto_key, not_null); - mysql.delete_records(); - CHECK(mysql.insert(s) == 1); - auto vec1 = mysql.query("limit 3"); - CHECK(vec1.size() == 1); - CHECK(mysql.insert(s) == 1); - CHECK(mysql.insert(v) == 2); - auto vec2 = mysql.query(); - CHECK(vec2.size() == 4); - auto vec3 = mysql.query(); - CHECK(vec3.size() == 4); - v[0].code = 1; - v[1].code = 2; + mysql.execute("drop table if exists student;"); + mysql.create_datatable(key, not_null); CHECK(mysql.insert(s) == 1); - auto vec4 = mysql.query(); - CHECK(vec4.size() == 5); - mysql.delete_records(); - CHECK(mysql.insert(v) == 2); - auto vec5 = mysql.query(); - CHECK(vec5.size() == 2); + auto result2 = mysql.query(); + CHECK(result2.size() == 1); #endif #ifdef ORMPP_ENABLE_PG + postgres.execute("drop table if exists student;"); postgres.create_datatable(key, not_null); CHECK(postgres.insert(s) == 1); auto result2 = postgres.query(); CHECK(result2.size() == 1); - postgres.delete_records(); - CHECK(postgres.insert(v) == 2); #endif #ifdef ORMPP_ENABLE_SQLITE3 - sqlite.create_datatable(auto_key); + sqlite.execute("drop table if exists student;"); + sqlite.create_datatable(key, not_null); CHECK(sqlite.insert(s) == 1); - auto result3 = sqlite.query(); - CHECK(result3.size() == 4); - sqlite.delete_records(); - CHECK(sqlite.insert(v) == 2); + auto result2 = sqlite.query(); + CHECK(result2.size() == 1); #endif } } @@ -479,7 +485,7 @@ TEST_CASE("orm_update") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.create_datatable(key, not_null); mysql.delete_records(); CHECK(mysql.insert(v) == 3); @@ -494,7 +500,7 @@ TEST_CASE("orm_update") { #ifdef ORMPP_ENABLE_PG dbng postgres; - if (postgres.connect(ip, "root", password, db)) { + if (postgres.connect(ip, username, password, db)) { postgres.create_datatable(key, not_null); postgres.delete_records(); CHECK(postgres.insert(v) == 3); @@ -535,8 +541,9 @@ TEST_CASE("orm_multi_update") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { - mysql.create_datatable(key, not_null); + if (mysql.connect(ip, username, password, db)) { + mysql.execute("drop table if exists student"); + mysql.create_datatable(auto_key, not_null); mysql.delete_records(); CHECK(mysql.insert(v) == 3); v[0].name = "test1"; @@ -550,8 +557,9 @@ TEST_CASE("orm_multi_update") { #ifdef ORMPP_ENABLE_PG dbng postgres; - if (postgres.connect(ip, "root", password, db)) { - postgres.create_datatable(key, not_null); + if (postgres.connect(ip, username, password, db)) { + postgres.execute("drop table if exists student"); + postgres.create_datatable(auto_key, not_null); CHECK(postgres.insert(v) == 3); v[0].name = "test1"; v[1].name = "test2"; @@ -565,8 +573,8 @@ TEST_CASE("orm_multi_update") { #ifdef ORMPP_ENABLE_SQLITE3 dbng sqlite; if (sqlite.connect(db)) { - sqlite.delete_records(); - sqlite.create_datatable(key); + sqlite.execute("drop table if exists student"); + sqlite.create_datatable(auto_key, not_null); CHECK(sqlite.insert(v) == 3); v[0].name = "test1"; v[1].name = "test2"; @@ -590,7 +598,7 @@ TEST_CASE("orm_delete") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.create_datatable(key, not_null); mysql.delete_records(); CHECK(mysql.insert(v) == 3); @@ -605,7 +613,7 @@ TEST_CASE("orm_delete") { #ifdef ORMPP_ENABLE_PG dbng postgres; - if (postgres.connect(ip, "root", password, db)) { + if (postgres.connect(ip, username, password, db)) { postgres.create_datatable(key, not_null); postgres.delete_records(); CHECK(postgres.insert(v) == 3); @@ -643,7 +651,7 @@ TEST_CASE("orm_query") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.create_datatable(key); mysql.delete_records(); CHECK(mysql.insert(v) == 3); @@ -656,13 +664,13 @@ TEST_CASE("orm_query") { #ifdef ORMPP_ENABLE_PG dbng postgres; - if (postgres.connect(ip, "root", password, db)) { + if (postgres.connect(ip, username, password, db)) { postgres.create_datatable(key); postgres.delete_records(); CHECK(postgres.insert(v) == 3); auto vec1 = postgres.query(); CHECK(vec1.size() == 3); - auto vec2 = postgres.query("where id=2"); + auto vec2 = postgres.query("id=2"); CHECK(vec2.size() == 1); } #endif @@ -693,7 +701,7 @@ TEST_CASE("orm_query_some") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.create_datatable(key, not_null); mysql.delete_records(); CHECK(mysql.insert(v) == 3); @@ -708,7 +716,7 @@ TEST_CASE("orm_query_some") { #ifdef ORMPP_ENABLE_PG dbng postgres; - if (postgres.connect(ip, "root", password, db)) { + if (postgres.connect(ip, username, password, db)) { postgres.create_datatable(key, not_null); postgres.delete_records(); CHECK(postgres.insert(v) == 3); @@ -755,7 +763,7 @@ TEST_CASE("orm_query_multi_table") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.create_datatable(key, not_null); mysql.create_datatable(key1, not_null); mysql.delete_records(); @@ -773,7 +781,7 @@ TEST_CASE("orm_query_multi_table") { #ifdef ORMPP_ENABLE_PG dbng postgres; - if (postgres.connect(ip, "root", password, db)) { + if (postgres.connect(ip, username, password, db)) { postgres.create_datatable(key, not_null); postgres.create_datatable(key1, not_null); postgres.delete_records(); @@ -820,7 +828,7 @@ TEST_CASE("orm_transaction") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.create_datatable(key, not_null); mysql.delete_records(); mysql.begin(); @@ -839,7 +847,7 @@ TEST_CASE("orm_transaction") { #ifdef ORMPP_ENABLE_PG dbng postgres; - if (postgres.connect(ip, "root", password, db)) { + if (postgres.connect(ip, username, password, db)) { postgres.create_datatable(key, not_null); postgres.delete_records(); postgres.begin(); @@ -907,7 +915,7 @@ struct validate { #ifdef ORMPP_ENABLE_MYSQL TEST_CASE("orm_aop") { // dbng mysql; - // auto r = mysql.wraper_connect(ip, "root", password, + // auto r = mysql.wraper_connect(ip, username, password, // db); REQUIRE(r); // r = mysql.wraper_execute("drop table if exists person"); @@ -931,7 +939,7 @@ REFLECTION(image, id, bin); TEST_CASE("orm_mysql_blob") { dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.execute("DROP TABLE IF EXISTS image"); mysql.create_datatable(); auto data = "this is a test binary stream\0, and ?..."; @@ -955,7 +963,7 @@ REFLECTION(image_ex, id, bin, time); TEST_CASE("orm_mysql_blob_tuple") { dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.execute("DROP TABLE IF EXISTS image_ex"); mysql.create_datatable(); auto data = "this is a test binary stream\0, and ?..."; @@ -984,7 +992,7 @@ TEST_CASE("orm_mysql_blob_tuple") { TEST_CASE("test create `table with unique and test query") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.execute("drop table if exists person"); mysql.create_datatable(ormpp_auto_key{"id"}, ormpp_unique{{"name", "age"}}); @@ -1020,7 +1028,7 @@ TEST_CASE("test create `table with unique and test query") { TEST_CASE("get_insert_id") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.execute("drop table if exists person"); mysql.create_datatable(ormpp_auto_key{"id"}); mysql.insert({0, "purecpp", 200}); @@ -1046,7 +1054,7 @@ TEST_CASE("get_insert_id") { // TEST_CASE("test delete_records") { // #ifdef ORMPP_ENABLE_MYSQL // dbng mysql; -// if (mysql.connect(ip, "root", password, db)) { +// if (mysql.connect(ip, username, password, db)) { // mysql.create_datatable(ormpp_auto_key{"id"}); // mysql.delete_records(); // mysql.insert({0, "other", 200}); @@ -1081,7 +1089,7 @@ REFLECTION_ALIAS(alias, "t_alias", FLDALIAS(&alias::id, "alias_id"), TEST_CASE("test alias") { #ifdef ORMPP_ENABLE_MYSQL dbng mysql; - if (mysql.connect(ip, "root", password, db)) { + if (mysql.connect(ip, username, password, db)) { mysql.create_datatable(ormpp_auto_key{"alias_id"}); mysql.delete_records(); mysql.insert({0, "purecpp"});