2021-11-14 00:54:54 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <sqlpp11/postgresql/postgresql.h>
|
|
|
|
#include <sqlpp11/sqlpp11.h>
|
2024-04-13 18:04:41 +08:00
|
|
|
#include "../../include/test_helpers.h"
|
2021-11-14 00:54:54 +08:00
|
|
|
|
2024-06-17 00:45:26 +08:00
|
|
|
#include "Tables.h"
|
2021-11-14 00:54:54 +08:00
|
|
|
#include "make_test_connection.h"
|
|
|
|
|
|
|
|
int Returning(int, char*[])
|
|
|
|
{
|
|
|
|
namespace sql = sqlpp::postgresql;
|
|
|
|
|
|
|
|
sql::connection db = sql::make_test_connection();
|
|
|
|
|
2024-06-17 00:45:26 +08:00
|
|
|
test::TabFoo foo = {};
|
2021-11-14 00:54:54 +08:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2024-06-17 00:45:26 +08:00
|
|
|
test::createTabFoo(db);
|
2021-11-14 00:54:54 +08:00
|
|
|
|
|
|
|
std::cout
|
2024-06-17 00:45:26 +08:00
|
|
|
<< db(sqlpp::postgresql::insert_into(foo).set(foo.textNnD = "dsa").returning(foo.doubleN)).front().doubleN
|
2021-11-14 00:54:54 +08:00
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
std::cout
|
2024-06-17 00:45:26 +08:00
|
|
|
<< db(sqlpp::postgresql::insert_into(foo).set(foo.textNnD = "asd").returning(std::make_tuple(foo.doubleN))).front().doubleN
|
2021-11-14 00:54:54 +08:00
|
|
|
<< std::endl;
|
|
|
|
|
2024-06-09 00:33:40 +08:00
|
|
|
#warning need to add optinal insert tests
|
2021-11-14 00:54:54 +08:00
|
|
|
|
|
|
|
auto updated =
|
2024-06-17 00:45:26 +08:00
|
|
|
db(sqlpp::postgresql::update(foo).set(foo.intN = 0).unconditionally().returning(foo.textNnD, foo.intN));
|
2021-11-14 00:54:54 +08:00
|
|
|
for (const auto& row : updated)
|
2024-06-17 00:45:26 +08:00
|
|
|
std::cout << "Gamma: " << row.textNnD << " Beta: " << row.intN << std::endl;
|
2021-11-14 00:54:54 +08:00
|
|
|
|
2023-10-31 13:44:17 +08:00
|
|
|
auto removed =
|
2024-06-17 00:45:26 +08:00
|
|
|
db(sqlpp::postgresql::remove_from(foo).where(foo.intN == 0).returning(foo.textNnD, foo.intN));
|
2023-10-31 13:44:17 +08:00
|
|
|
for (const auto& row : removed)
|
2024-06-17 00:45:26 +08:00
|
|
|
std::cout << "Gamma: " << row.textNnD << " Beta: " << row.intN << std::endl;
|
2023-10-31 13:44:17 +08:00
|
|
|
|
2024-06-17 00:45:26 +08:00
|
|
|
auto multi_insert = sqlpp::postgresql::insert_into(foo).columns(foo.intN).returning(foo.id, foo.intN);
|
|
|
|
multi_insert.add_values(foo.intN = 1);
|
|
|
|
multi_insert.add_values(foo.intN = 2);
|
2021-11-14 00:54:54 +08:00
|
|
|
auto inserted = db(multi_insert);
|
|
|
|
|
|
|
|
for (const auto& row : inserted)
|
2024-06-17 00:45:26 +08:00
|
|
|
std::cout << row.intN << std::endl;
|
2021-11-14 00:54:54 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (const sql::failure&)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|