Skip to content

Commit

Permalink
Merge pull request #61 from mloskot/issue-46
Browse files Browse the repository at this point in the history
Add PostgreSQL test for bytea to pull request #46
  • Loading branch information
mloskot committed Feb 11, 2013
2 parents 2b42fbc + 4962b59 commit 2deef98
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 2deef98

Please sign in to comment.