Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/SOCI/soci
Browse files Browse the repository at this point in the history
  • Loading branch information
vnaydionov committed Feb 13, 2013
2 parents a061013 + 1be2d96 commit 7a49b20
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/backends/odbc/test/CMakeLists.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/backends/odbc/test/test-access.dsn
Expand Up @@ -10,4 +10,4 @@ MaxBufferSize=2048
FIL=MS Access
DriverId=25
DefaultDir=.\
DBQ=.\soci.mdb
DBQ=.\soci_test.mdb
2 changes: 1 addition & 1 deletion 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
Expand Down
2 changes: 1 addition & 1 deletion 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
3 changes: 1 addition & 2 deletions src/backends/odbc/test/test-odbc-mssql.cpp
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/backends/odbc/test/test-odbc-mysql.cpp
Expand Up @@ -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
Expand All @@ -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, "
Expand All @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/backends/postgresql/statement.cpp
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
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 7a49b20

Please sign in to comment.