diff --git a/src/backends/odbc/test/CMakeLists.txt b/src/backends/odbc/test/CMakeLists.txt index 59a89ec69..0bd29b4a2 100644 --- a/src/backends/odbc/test/CMakeLists.txt +++ b/src/backends/odbc/test/CMakeLists.txt @@ -4,6 +4,18 @@ soci_backend_test( SOURCE test-odbc-access.cpp CONNSTR "test-access.dsn") +soci_backend_test( + NAME mssql + BACKEND ODBC + SOURCE test-odbc-mssql.cpp + CONNSTR "test-mssql.dsn") + +soci_backend_test( + NAME mysql + BACKEND ODBC + SOURCE test-odbc-mysql.cpp + CONNSTR "test-mysql.dsn") + soci_backend_test( NAME postgresql BACKEND ODBC diff --git a/src/backends/odbc/test/test-access.dsn b/src/backends/odbc/test/test-access.dsn index d695319f0..597ff131d 100644 --- a/src/backends/odbc/test/test-access.dsn +++ b/src/backends/odbc/test/test-access.dsn @@ -10,4 +10,4 @@ MaxBufferSize=2048 FIL=MS Access DriverId=25 DefaultDir=.\ -DBQ=.\soci.mdb +DBQ=.\soci_test.mdb diff --git a/src/backends/odbc/test/test-mssql.dsn b/src/backends/odbc/test/test-mssql.dsn index aef33476f..f96dc7011 100644 --- a/src/backends/odbc/test/test-mssql.dsn +++ b/src/backends/odbc/test/test-mssql.dsn @@ -1,7 +1,7 @@ [ODBC] DRIVER=SQL Native Client UID=David -DATABASE=socitest +DATABASE=soci_test WSID=NANO APP=Microsoft Data Access Components Trusted_Connection=Yes diff --git a/src/backends/odbc/test/test-mysql.dsn b/src/backends/odbc/test/test-mysql.dsn index 3e7c7a40b..edb0011e8 100644 --- a/src/backends/odbc/test/test-mysql.dsn +++ b/src/backends/odbc/test/test-mysql.dsn @@ -1,6 +1,6 @@ [ODBC] DRIVER=MySQL ODBC 3.51 Driver -DATABASE=socitest +DATABASE=soci_test USER=root PORT=0 OPTION=0 diff --git a/src/backends/odbc/test/test-odbc-mssql.cpp b/src/backends/odbc/test/test-odbc-mssql.cpp index bf26f9026..38db4fd5f 100644 --- a/src/backends/odbc/test/test-odbc-mssql.cpp +++ b/src/backends/odbc/test/test-odbc-mssql.cpp @@ -18,8 +18,7 @@ using namespace soci; using namespace soci::tests; std::string connectString; -backend_factory const &backEnd = odbc; - +backend_factory const &backEnd = *soci::factory_odbc(); // DDL Creation objects for common tests struct table_creator_one : public table_creator_base diff --git a/src/backends/odbc/test/test-odbc-mysql.cpp b/src/backends/odbc/test/test-odbc-mysql.cpp index d4fe31bc3..437234fb4 100644 --- a/src/backends/odbc/test/test-odbc-mysql.cpp +++ b/src/backends/odbc/test/test-odbc-mysql.cpp @@ -18,7 +18,7 @@ using namespace soci; using namespace soci::tests; std::string connectString; -backend_factory const &backEnd = odbc; +backend_factory const &backEnd = *soci::factory_odbc(); // DDL Creation objects for common tests struct table_creator_one : public table_creator_base @@ -45,7 +45,7 @@ struct table_creator_two : public table_creator_base struct table_creator_three : public table_creator_base { - table_creator_three(ession & sql) + table_creator_three(session & sql) : table_creator_base(sql) { sql << "create table soci_test(name varchar(100) not null, " @@ -69,12 +69,17 @@ class test_context : public test_context_base return new table_creator_one(s); } - table_creator_base * tableCreator2(session& s) const + table_creator_base * table_creator_2(session& s) const { return new table_creator_two(s); } - table_creator_base * tableCreator3(session& s) const + table_creator_base * table_creator_3(session& s) const + { + return new table_creator_three(s); + } + + table_creator_base * table_creator_4(session& s) const { return new table_creator_three(s); } diff --git a/src/backends/postgresql/statement.cpp b/src/backends/postgresql/statement.cpp index 26daca8b2..402a8e91c 100644 --- a/src/backends/postgresql/statement.cpp +++ b/src/backends/postgresql/statement.cpp @@ -504,6 +504,7 @@ void postgresql_statement_backend::describe_column(int colNum, data_type & type, case 18: // char case 1042: // bpchar case 142: // xml + case 17: // bytea type = dt_string; break; @@ -533,7 +534,7 @@ void postgresql_statement_backend::describe_column(int colNum, data_type & type, case 20: // int8 type = dt_long_long; break; - + default: { std::stringstream message; diff --git a/src/backends/postgresql/test/test-postgresql.cpp b/src/backends/postgresql/test/test-postgresql.cpp index ccc863268..70827d880 100644 --- a/src/backends/postgresql/test/test-postgresql.cpp +++ b/src/backends/postgresql/test/test-postgresql.cpp @@ -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(&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(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;