Skip to content

Commit

Permalink
PostgreSQL test for bytea - #46. Use case of bytea to dt_string mappi…
Browse files Browse the repository at this point in the history
…ng 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).
  • Loading branch information
mloskot committed Feb 12, 2013
1 parent ca0d73b commit 662deec
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/backends/postgresql/test/test-postgresql.cpp
Expand Up @@ -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
{
Expand Down Expand Up @@ -637,6 +680,8 @@ int main(int argc, char** argv)

try
{
test_bytea();

test_context tc(backEnd, connectString);
common_tests tests(tc);
tests.run();
Expand All @@ -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;
Expand Down

0 comments on commit 662deec

Please sign in to comment.