Commit 662deecb authored by Mateusz Loskot's avatar Mateusz Loskot

PostgreSQL test for bytea - #46. Use case of bytea to dt_string mapping is...

PostgreSQL test for bytea - #46. Use case of bytea to dt_string mapping is unclear, so it needs to be confirmed if the ida is to allow the semantic as presented in the test_bytea() that data != (bin1 == bin1).
parent ca0d73bc
......@@ -544,6 +544,49 @@ void test12()
std::cout << "test 12 passed" << std::endl;
}
struct bytea_table_creator : public table_creator_base
{
bytea_table_creator(session& sql)
: table_creator_base(sql)
{
sql << "drop table if exists soci_test;";
sql << "create table soci_test ( val bytea null )";
}
};
void test_bytea()
{
{
session sql(backEnd, connectString);
bytea_table_creator tableCreator(sql);
int v = 0x0A0B0C0D;
unsigned char* b = reinterpret_cast<unsigned char*>(&v);
std::string data;
std::copy(b, b + sizeof(v), std::back_inserter(data));
{
sql << "insert into soci_test(val) values(:val)", use(data);
// 1) into string, no Oid mapping
std::string bin1;
sql << "select val from soci_test", into(bin1);
assert(bin1 == "\\x0d0c0b0a");
// 2) Oid-to-dt_string mapped
row r;
sql << "select * from soci_test", into(r);
assert(r.size() == 1);
column_properties const& props = r.get_properties(0);
assert(props.get_data_type() == soci::dt_string);
std::string bin2 = r.get<std::string>(0);
assert(bin2 == "\\x0d0c0b0a");
}
}
std::cout << "test_bytea passed" << std::endl;
}
// DDL Creation objects for common tests
struct table_creator_one : public table_creator_base
{
......@@ -637,6 +680,8 @@ int main(int argc, char** argv)
try
{
test_bytea();
test_context tc(backEnd, connectString);
common_tests tests(tc);
tests.run();
......@@ -658,6 +703,7 @@ int main(int argc, char** argv)
test10();
test11();
test12();
test_bytea();
std::cout << "\nOK, all tests passed.\n\n";
return EXIT_SUCCESS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment