mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Squashed 'src/soci/' content from commit 6e9312c
git-subtree-dir: src/soci git-subtree-split: 6e9312c4bb3748907bd28d62c40feca42878cfef
This commit is contained in:
48
src/backends/odbc/test/CMakeLists.txt
Normal file
48
src/backends/odbc/test/CMakeLists.txt
Normal file
@@ -0,0 +1,48 @@
|
||||
###############################################################################
|
||||
#
|
||||
# This file is part of CMake configuration for SOCI library
|
||||
#
|
||||
# Copyright (C) 2010 Mateusz Loskot <mateusz@loskot.net>
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
#
|
||||
###############################################################################
|
||||
|
||||
if (WIN32)
|
||||
# MDBTools driver seems unreliable
|
||||
soci_backend_test(
|
||||
NAME access
|
||||
BACKEND ODBC
|
||||
SOURCE test-odbc-access.cpp
|
||||
CONNSTR "test-access.dsn")
|
||||
|
||||
# We have no means to test SQL Server at travis-ci.org
|
||||
soci_backend_test(
|
||||
NAME mssql
|
||||
BACKEND ODBC
|
||||
SOURCE test-odbc-mssql.cpp
|
||||
CONNSTR "test-mssql.dsn")
|
||||
endif()
|
||||
|
||||
soci_backend_test(
|
||||
NAME mysql
|
||||
BACKEND ODBC
|
||||
SOURCE test-odbc-mysql.cpp
|
||||
CONNSTR "test-mysql.dsn")
|
||||
|
||||
soci_backend_test(
|
||||
NAME postgresql
|
||||
BACKEND ODBC
|
||||
SOURCE test-odbc-postgresql.cpp
|
||||
CONNSTR "test-postgresql.dsn")
|
||||
|
||||
# TODO: DB2 backend is tested by Travis CI on dedicated VM, separate from ODBC,
|
||||
# in order to test DB2 with ODBC, it would be best to install DB2 driver only.
|
||||
if (NOT $ENV{TRAVIS})
|
||||
soci_backend_test(
|
||||
NAME db2
|
||||
BACKEND ODBC
|
||||
SOURCE test-odbc-db2.cpp
|
||||
CONNSTR "test-db2.dsn")
|
||||
endif()
|
||||
24
src/backends/odbc/test/Makefile.basic
Normal file
24
src/backends/odbc/test/Makefile.basic
Normal file
@@ -0,0 +1,24 @@
|
||||
# The following variable is specific to this backend and its correct
|
||||
# values might depend on your environment - feel free to set it accordingly.
|
||||
|
||||
ODBCINCLUDEDIR = -I/usr/include
|
||||
ODBCLIBDIR = -L/usr/lib
|
||||
ODBCLIBS = -lodbc -lodbcinst
|
||||
|
||||
# The rest of the Makefile is independent of the target environment.
|
||||
|
||||
COMPILER = g++
|
||||
CXXFLAGS = -Wall -pedantic -Wno-long-long
|
||||
INCLUDEDIRS = -I.. -I../../../core ${ODBCINCLUDEDIR}
|
||||
LIBDIRS = -L.. -L../../../core ${ODBCLIBDIR}
|
||||
LIBS = -lsoci_core -lsoci_odbc -ldl ${ODBCLIBS}
|
||||
|
||||
|
||||
test-odbc-mssql: test-odbc-mssql.cpp
|
||||
${COMPILER} -o $@ $? ${CXXFLAGS} ${INCLUDEDIRS} ${LIBDIRS} ${LIBS}
|
||||
|
||||
test-odbc-access: test-odbc-access.cpp
|
||||
${COMPILER} -o $@ $? ${CXXFLAGS} ${INCLUDEDIRS} ${LIBDIRS} ${LIBS}
|
||||
|
||||
clean :
|
||||
rm -f test-odbc-access.exe test-odbc-mssql.exe
|
||||
19
src/backends/odbc/test/makefile.msvc
Normal file
19
src/backends/odbc/test/makefile.msvc
Normal file
@@ -0,0 +1,19 @@
|
||||
ODBCINCLUDEDIR="C:\Program Files\Microsoft Platform SDK\Include"
|
||||
ODBCLIBDIR="C:\Program Files\Microsoft Platform SDK\Lib"
|
||||
|
||||
COMPILER = cl
|
||||
CXXFLAGS = /nologo /EHsc
|
||||
CXXFLAGSSO = $(CXXFLAGS)
|
||||
INCLUDEDIRS = /I.. /I..\..\..\core /I..\..\..\core\test /I$(ODBCINCLUDEDIR)
|
||||
LIBS = ..\..\..\core\soci-core.lib ..\soci-odbc.lib $(ODBCLIBDIR)\uuid.lib $(ODBCLIBDIR)\odbc32.lib
|
||||
|
||||
mssql: test-odbc-mssql.cpp
|
||||
$(COMPILER) $? $(CXXFLAGS) $(INCLUDEDIRS) $(LIBS)
|
||||
|
||||
access: test-odbc-access.cpp
|
||||
$(COMPILER) $? $(CXXFLAGS) $(INCLUDEDIRS) $(LIBS)
|
||||
|
||||
clean:
|
||||
del *.exe
|
||||
del *.obj
|
||||
|
||||
13
src/backends/odbc/test/test-access.dsn
Normal file
13
src/backends/odbc/test/test-access.dsn
Normal file
@@ -0,0 +1,13 @@
|
||||
[ODBC]
|
||||
DRIVER=Microsoft Access Driver (*.mdb)
|
||||
UID=admin
|
||||
UserCommitSync=Yes
|
||||
Threads=3
|
||||
SafeTransactions=0
|
||||
PageTimeout=5
|
||||
MaxScanRows=8
|
||||
MaxBufferSize=2048
|
||||
FIL=MS Access
|
||||
DriverId=25
|
||||
DefaultDir=.\
|
||||
DBQ=.\soci_test.mdb
|
||||
8
src/backends/odbc/test/test-mssql.dsn
Normal file
8
src/backends/odbc/test/test-mssql.dsn
Normal file
@@ -0,0 +1,8 @@
|
||||
[ODBC]
|
||||
DRIVER=SQL Native Client
|
||||
UID=David
|
||||
DATABASE=soci_test
|
||||
WSID=NANO
|
||||
APP=Microsoft Data Access Components
|
||||
Trusted_Connection=Yes
|
||||
SERVER=localhost\SQLEXPRESS
|
||||
4
src/backends/odbc/test/test-mysql.dsn
Normal file
4
src/backends/odbc/test/test-mysql.dsn
Normal file
@@ -0,0 +1,4 @@
|
||||
[ODBC]
|
||||
DRIVER=MySQL
|
||||
DATABASE=soci_test
|
||||
OPTION=0
|
||||
155
src/backends/odbc/test/test-odbc-access.cpp
Normal file
155
src/backends/odbc/test/test-odbc-access.cpp
Normal file
@@ -0,0 +1,155 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "soci.h"
|
||||
#include "soci-odbc.h"
|
||||
#include "common-tests.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
|
||||
using namespace soci;
|
||||
using namespace soci::tests;
|
||||
|
||||
std::string connectString;
|
||||
backend_factory const &backEnd = *soci::factory_odbc();
|
||||
|
||||
// DDL Creation objects for common tests
|
||||
struct table_creator_one : public table_creator_base
|
||||
{
|
||||
table_creator_one(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(id integer, val integer, c char, "
|
||||
"str varchar(20), sh integer, ul number, d float, "
|
||||
"tm timestamp, i1 integer, i2 integer, i3 integer, "
|
||||
"name varchar(20))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_two : public table_creator_base
|
||||
{
|
||||
table_creator_two(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(num_float float, num_int integer,"
|
||||
" name varchar(20), sometime datetime, chr char)";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_three : public table_creator_base
|
||||
{
|
||||
table_creator_three(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(name varchar(100) not null, "
|
||||
"phone varchar(15))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_for_get_affected_rows : table_creator_base
|
||||
{
|
||||
table_creator_for_get_affected_rows(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(val integer)";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Support for SOCI Common Tests
|
||||
//
|
||||
|
||||
class test_context : public test_context_base
|
||||
{
|
||||
public:
|
||||
|
||||
test_context(backend_factory const &backEnd, std::string const &connectString)
|
||||
: test_context_base(backEnd, connectString) {}
|
||||
|
||||
table_creator_base * table_creator_1(session& s) const
|
||||
{
|
||||
return new table_creator_one(s);
|
||||
}
|
||||
|
||||
table_creator_base * table_creator_2(session& s) const
|
||||
{
|
||||
return new table_creator_two(s);
|
||||
}
|
||||
|
||||
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_for_get_affected_rows(s);
|
||||
}
|
||||
|
||||
std::string fromDual(std::string const &sql) const
|
||||
{
|
||||
return sql;
|
||||
}
|
||||
|
||||
std::string toDate(std::string const &datdt_string) const
|
||||
{
|
||||
return "#" + datdt_string + "#";
|
||||
}
|
||||
|
||||
std::string to_date_time(std::string const &datdt_string) const
|
||||
{
|
||||
return "#" + datdt_string + "#";
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
|
||||
// instead of debug message window.
|
||||
// This hack is required to run asser()-driven tests by Buildbot.
|
||||
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||
#endif //_MSC_VER
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
connectString = argv[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
connectString = "FILEDSN=./test-access.dsn";
|
||||
}
|
||||
try
|
||||
{
|
||||
std::cout << "\nSOCI ODBC with MS Access Tests:\n\n";
|
||||
|
||||
test_context tc(backEnd, connectString);
|
||||
common_tests tests(tc);
|
||||
tests.run();
|
||||
|
||||
std::cout << "\nOK, all tests passed.\n\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (soci::odbc_soci_error const & e)
|
||||
{
|
||||
std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
|
||||
<< "Native Error Code: " << e.native_error_code() << std::endl
|
||||
<< "SOCI Message: " << e.what() << std::endl
|
||||
<< "ODBC Message: " << e.odbc_error_message() << std::endl;
|
||||
}
|
||||
catch (std::exception const & e)
|
||||
{
|
||||
std::cout << "STD::EXECEPTION " << e.what() << '\n';
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
306
src/backends/odbc/test/test-odbc-db2.cpp
Normal file
306
src/backends/odbc/test/test-odbc-db2.cpp
Normal file
@@ -0,0 +1,306 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "soci.h"
|
||||
#include "soci-odbc.h"
|
||||
#include "common-tests.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
|
||||
using namespace soci;
|
||||
using namespace soci::tests;
|
||||
|
||||
std::string connectString;
|
||||
backend_factory const &backEnd = *soci::factory_odbc();
|
||||
|
||||
// DDL Creation objects for common tests
|
||||
struct table_creator_one : public table_creator_base
|
||||
{
|
||||
table_creator_one(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "CREATE TABLE SOCI_TEST(ID INTEGER, VAL SMALLINT, C CHAR, STR VARCHAR(20), SH SMALLINT, UL NUMERIC(20), D DOUBLE, "
|
||||
"TM TIMESTAMP(9), I1 INTEGER, I2 INTEGER, I3 INTEGER, NAME VARCHAR(20))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_two : public table_creator_base
|
||||
{
|
||||
table_creator_two(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "CREATE TABLE SOCI_TEST(NUM_FLOAT DOUBLE, NUM_INT INTEGER, NAME VARCHAR(20), SOMETIME TIMESTAMP, CHR CHAR)";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_three : public table_creator_base
|
||||
{
|
||||
table_creator_three(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "CREATE TABLE SOCI_TEST(NAME VARCHAR(100) NOT NULL, PHONE VARCHAR(15))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_for_get_affected_rows : table_creator_base
|
||||
{
|
||||
table_creator_for_get_affected_rows(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "CREATE TABLE SOCI_TEST(VAL INTEGER)";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Support for SOCI Common Tests
|
||||
//
|
||||
|
||||
class test_context : public test_context_base
|
||||
{
|
||||
public:
|
||||
test_context(backend_factory const &backEnd,
|
||||
std::string const &connectString)
|
||||
: test_context_base(backEnd, connectString) {}
|
||||
|
||||
table_creator_base * table_creator_1(session& s) const
|
||||
{
|
||||
return new table_creator_one(s);
|
||||
}
|
||||
|
||||
table_creator_base * table_creator_2(session& s) const
|
||||
{
|
||||
return new table_creator_two(s);
|
||||
}
|
||||
|
||||
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_for_get_affected_rows(s);
|
||||
}
|
||||
|
||||
std::string to_date_time(std::string const &datdt_string) const
|
||||
{
|
||||
return "\'" + datdt_string + "\'";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_bigint : table_creator_base
|
||||
{
|
||||
table_creator_bigint(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "CREATE TABLE SOCI_TEST (VAL BIGINT)";
|
||||
}
|
||||
};
|
||||
|
||||
void test_odbc_db2_long_long()
|
||||
{
|
||||
const int num_recs = 100;
|
||||
session sql(backEnd, connectString);
|
||||
table_creator_bigint table(sql);
|
||||
|
||||
{
|
||||
long long n;
|
||||
statement st = (sql.prepare <<
|
||||
"INSERT INTO SOCI_TEST (VAL) VALUES (:val)", use(n));
|
||||
for (int i = 0; i < num_recs; i++)
|
||||
{
|
||||
n = 1000000000LL + i;
|
||||
st.execute();
|
||||
}
|
||||
}
|
||||
{
|
||||
long long n2;
|
||||
statement st = (sql.prepare <<
|
||||
"SELECT VAL FROM SOCI_TEST ORDER BY VAL", into(n2));
|
||||
st.execute();
|
||||
for (int i = 0; i < num_recs; i++)
|
||||
{
|
||||
st.fetch();
|
||||
assert(n2 == 1000000000LL + i);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "test odbc_db2_long_long passed" << std::endl;
|
||||
}
|
||||
|
||||
void test_odbc_db2_unsigned_long_long()
|
||||
{
|
||||
const int num_recs = 100;
|
||||
session sql(backEnd, connectString);
|
||||
table_creator_bigint table(sql);
|
||||
|
||||
{
|
||||
unsigned long long n;
|
||||
statement st = (sql.prepare <<
|
||||
"INSERT INTO SOCI_TEST (VAL) VALUES (:val)", use(n));
|
||||
for (int i = 0; i < num_recs; i++)
|
||||
{
|
||||
n = 1000000000LL + i;
|
||||
st.execute();
|
||||
}
|
||||
}
|
||||
{
|
||||
unsigned long long n2;
|
||||
statement st = (sql.prepare <<
|
||||
"SELECT VAL FROM SOCI_TEST ORDER BY VAL", into(n2));
|
||||
st.execute();
|
||||
for (int i = 0; i < num_recs; i++)
|
||||
{
|
||||
st.fetch();
|
||||
assert(n2 == 1000000000LL + i);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "test odbc_db2_unsigned_long_long passed" << std::endl;
|
||||
}
|
||||
|
||||
void test_odbc_db2_long_long_vector()
|
||||
{
|
||||
const std::size_t num_recs = 100;
|
||||
session sql(backEnd, connectString);
|
||||
table_creator_bigint table(sql);
|
||||
|
||||
{
|
||||
std::vector<long long> v(num_recs);
|
||||
for (std::size_t i = 0; i < num_recs; i++)
|
||||
{
|
||||
v[i] = 1000000000LL + i;
|
||||
}
|
||||
|
||||
sql << "INSERT INTO SOCI_TEST (VAL) VALUES (:bi)", use(v);
|
||||
}
|
||||
{
|
||||
std::size_t recs = 0;
|
||||
|
||||
std::vector<long long> v(num_recs / 2 + 1);
|
||||
statement st = (sql.prepare <<
|
||||
"SELECT VAL FROM SOCI_TEST ORDER BY VAL", into(v));
|
||||
st.execute();
|
||||
while (true)
|
||||
{
|
||||
if (!st.fetch())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
const std::size_t vsize = v.size();
|
||||
for (std::size_t i = 0; i < vsize; i++)
|
||||
{
|
||||
assert(v[i] == 1000000000LL +
|
||||
static_cast<long long>(recs));
|
||||
recs++;
|
||||
}
|
||||
}
|
||||
assert(recs == num_recs);
|
||||
}
|
||||
|
||||
std::cout << "test odbc_db2_long_long_vector passed" << std::endl;
|
||||
}
|
||||
|
||||
void test_odbc_db2_unsigned_long_long_vector()
|
||||
{
|
||||
const std::size_t num_recs = 100;
|
||||
session sql(backEnd, connectString);
|
||||
table_creator_bigint table(sql);
|
||||
|
||||
{
|
||||
std::vector<unsigned long long> v(num_recs);
|
||||
for (std::size_t i = 0; i < num_recs; i++)
|
||||
{
|
||||
v[i] = 1000000000LL + i;
|
||||
}
|
||||
|
||||
sql << "INSERT INTO SOCI_TEST (VAL) VALUES (:bi)", use(v);
|
||||
}
|
||||
{
|
||||
std::size_t recs = 0;
|
||||
|
||||
std::vector<unsigned long long> v(num_recs / 2 + 1);
|
||||
statement st = (sql.prepare <<
|
||||
"SELECT VAL FROM SOCI_TEST ORDER BY VAL", into(v));
|
||||
st.execute();
|
||||
while (true)
|
||||
{
|
||||
if (!st.fetch())
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
const std::size_t vsize = v.size();
|
||||
for (std::size_t i = 0; i < vsize; i++)
|
||||
{
|
||||
assert(v[i] == 1000000000LL +
|
||||
static_cast<unsigned long long>(recs));
|
||||
recs++;
|
||||
}
|
||||
}
|
||||
assert(recs == num_recs);
|
||||
}
|
||||
|
||||
std::cout << "test odbc_db2_unsigned_long_long_vector passed" << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
|
||||
// instead of debug message window.
|
||||
// This hack is required to run asser()-driven tests by Buildbot.
|
||||
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||
#endif //_MSC_VER
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
connectString = argv[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << std::endl <<
|
||||
"usage: test-odbc-db2 \"DSN=<db>;Uid=<user>;Pwd=<password>\"" <<
|
||||
std::endl << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
try
|
||||
{
|
||||
std::cout << "\nSOCI ODBC with DB2 Tests:\n\n";
|
||||
|
||||
test_context tc(backEnd, connectString);
|
||||
common_tests tests(tc);
|
||||
tests.run();
|
||||
|
||||
std::cout << "\nSOCI DB2 Specific Tests:\n\n";
|
||||
test_odbc_db2_long_long();
|
||||
test_odbc_db2_unsigned_long_long();
|
||||
test_odbc_db2_long_long_vector();
|
||||
test_odbc_db2_unsigned_long_long_vector();
|
||||
|
||||
std::cout << "\nOK, all tests passed.\n\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (soci::odbc_soci_error const & e)
|
||||
{
|
||||
std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
|
||||
<< "Native Error Code: " << e.native_error_code() << std::endl
|
||||
<< "SOCI Message: " << e.what() << std::endl
|
||||
<< "ODBC Message: " << e.odbc_error_message() << std::endl;
|
||||
}
|
||||
catch (std::exception const & e)
|
||||
{
|
||||
std::cout << "STD::EXECEPTION " << e.what() << '\n';
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
148
src/backends/odbc/test/test-odbc-mssql.cpp
Normal file
148
src/backends/odbc/test/test-odbc-mssql.cpp
Normal file
@@ -0,0 +1,148 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "soci.h"
|
||||
#include "soci-odbc.h"
|
||||
#include "common-tests.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
|
||||
using namespace soci;
|
||||
using namespace soci::tests;
|
||||
|
||||
std::string connectString;
|
||||
backend_factory const &backEnd = *soci::factory_odbc();
|
||||
|
||||
// DDL Creation objects for common tests
|
||||
struct table_creator_one : public table_creator_base
|
||||
{
|
||||
table_creator_one(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(id integer, val integer, c char, "
|
||||
"str varchar(20), sh smallint, ul numeric(20), d float, "
|
||||
"tm datetime, i1 integer, i2 integer, i3 integer, "
|
||||
"name varchar(20))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_two : public table_creator_base
|
||||
{
|
||||
table_creator_two(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(num_float float, num_int integer,"
|
||||
" name varchar(20), sometime datetime, chr char)";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_three : public table_creator_base
|
||||
{
|
||||
table_creator_three(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(name varchar(100) not null, "
|
||||
"phone varchar(15))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_for_get_affected_rows : table_creator_base
|
||||
{
|
||||
table_creator_for_get_affected_rows(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(val integer)";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Support for SOCI Common Tests
|
||||
//
|
||||
|
||||
class test_context : public test_context_base
|
||||
{
|
||||
public:
|
||||
test_context(backend_factory const &backEnd,
|
||||
std::string const &connectString)
|
||||
: test_context_base(backEnd, connectString) {}
|
||||
|
||||
table_creator_base* table_creator_1(session& s) const
|
||||
{
|
||||
return new table_creator_one(s);
|
||||
}
|
||||
|
||||
table_creator_base* table_creator_2(session& s) const
|
||||
{
|
||||
return new table_creator_two(s);
|
||||
}
|
||||
|
||||
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_for_get_affected_rows(s);
|
||||
}
|
||||
|
||||
std::string to_date_time(std::string const &datdt_string) const
|
||||
{
|
||||
return "convert(datetime, \'" + datdt_string + "\', 120)";
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
|
||||
// instead of debug message window.
|
||||
// This hack is required to run asser()-driven tests by Buildbot.
|
||||
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||
#endif //_MSC_VER
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
connectString = argv[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
connectString = "FILEDSN=./test-mssql.dsn";
|
||||
}
|
||||
try
|
||||
{
|
||||
std::cout << "\nSOCI ODBC with MS SQL Server Tests:\n\n";
|
||||
|
||||
test_context tc(backEnd, connectString);
|
||||
common_tests tests(tc);
|
||||
tests.run();
|
||||
|
||||
std::cout << "\nOK, all tests passed.\n\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (soci::odbc_soci_error const & e)
|
||||
{
|
||||
std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
|
||||
<< "Native Error Code: " << e.native_error_code() << std::endl
|
||||
<< "SOCI Message: " << e.what() << std::endl
|
||||
<< "ODBC Message: " << e.odbc_error_message() << std::endl;
|
||||
}
|
||||
catch (soci::soci_error const & e)
|
||||
{
|
||||
std::cout << "SOCIERROR: " << e.what() << '\n';
|
||||
}
|
||||
catch (std::exception const & e)
|
||||
{
|
||||
std::cout << "STD::EXECEPTION " << e.what() << '\n';
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
144
src/backends/odbc/test/test-odbc-mysql.cpp
Normal file
144
src/backends/odbc/test/test-odbc-mysql.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "soci.h"
|
||||
#include "soci-odbc.h"
|
||||
#include "common-tests.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
|
||||
using namespace soci;
|
||||
using namespace soci::tests;
|
||||
|
||||
std::string connectString;
|
||||
backend_factory const &backEnd = *soci::factory_odbc();
|
||||
|
||||
// DDL Creation objects for common tests
|
||||
struct table_creator_one : public table_creator_base
|
||||
{
|
||||
table_creator_one(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(id integer, val integer, c char, "
|
||||
"str varchar(20), sh int2, ul numeric(20), d float8, "
|
||||
"tm datetime, i1 integer, i2 integer, i3 integer, "
|
||||
"name varchar(20))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_two : public table_creator_base
|
||||
{
|
||||
table_creator_two(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(num_float float8, num_int integer,"
|
||||
" name varchar(20), sometime datetime, chr char)";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_three : public table_creator_base
|
||||
{
|
||||
table_creator_three(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(name varchar(100) not null, "
|
||||
"phone varchar(15))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_for_get_affected_rows : table_creator_base
|
||||
{
|
||||
table_creator_for_get_affected_rows(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(val integer)";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Support for SOCI Common Tests
|
||||
//
|
||||
|
||||
class test_context : public test_context_base
|
||||
{
|
||||
public:
|
||||
test_context(backend_factory const &backEnd,
|
||||
std::string const &connectString)
|
||||
: test_context_base(backEnd, connectString) {}
|
||||
|
||||
table_creator_base * table_creator_1(session& s) const
|
||||
{
|
||||
return new table_creator_one(s);
|
||||
}
|
||||
|
||||
table_creator_base * table_creator_2(session& s) const
|
||||
{
|
||||
return new table_creator_two(s);
|
||||
}
|
||||
|
||||
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_for_get_affected_rows(s);
|
||||
}
|
||||
|
||||
std::string to_date_time(std::string const &datdt_string) const
|
||||
{
|
||||
return "\'" + datdt_string + "\'";
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
|
||||
// instead of debug message window.
|
||||
// This hack is required to run asser()-driven tests by Buildbot.
|
||||
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||
#endif //_MSC_VER
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
connectString = argv[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
connectString = "FILEDSN=./test-mysql.dsn";
|
||||
}
|
||||
try
|
||||
{
|
||||
std::cout << "\nSOCI ODBC with MySQL Tests:\n\n";
|
||||
|
||||
test_context tc(backEnd, connectString);
|
||||
common_tests tests(tc);
|
||||
tests.run();
|
||||
|
||||
std::cout << "\nOK, all tests passed.\n\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (soci::odbc_soci_error const & e)
|
||||
{
|
||||
std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
|
||||
<< "Native Error Code: " << e.native_error_code() << std::endl
|
||||
<< "SOCI Message: " << e.what() << std::endl
|
||||
<< "ODBC Message: " << e.odbc_error_message() << std::endl;
|
||||
}
|
||||
catch (std::exception const & e)
|
||||
{
|
||||
std::cout << "STD::EXECEPTION " << e.what() << '\n';
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
146
src/backends/odbc/test/test-odbc-postgresql.cpp
Normal file
146
src/backends/odbc/test/test-odbc-postgresql.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
//
|
||||
// Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include "soci.h"
|
||||
#include "soci-odbc.h"
|
||||
#include "common-tests.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
|
||||
using namespace soci;
|
||||
using namespace soci::tests;
|
||||
|
||||
std::string connectString;
|
||||
backend_factory const &backEnd = *soci::factory_odbc();
|
||||
|
||||
// DDL Creation objects for common tests
|
||||
struct table_creator_one : public table_creator_base
|
||||
{
|
||||
table_creator_one(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(id integer, val integer, c char, "
|
||||
"str varchar(20), sh int2, ul numeric(20), d float8, "
|
||||
"tm timestamp, i1 integer, i2 integer, i3 integer, "
|
||||
"name varchar(20))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_two : public table_creator_base
|
||||
{
|
||||
table_creator_two(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(num_float float8, num_int integer,"
|
||||
" name varchar(20), sometime timestamp, chr char)";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_three : public table_creator_base
|
||||
{
|
||||
table_creator_three(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(name varchar(100) not null, "
|
||||
"phone varchar(15))";
|
||||
}
|
||||
};
|
||||
|
||||
struct table_creator_for_get_affected_rows : table_creator_base
|
||||
{
|
||||
table_creator_for_get_affected_rows(session & sql)
|
||||
: table_creator_base(sql)
|
||||
{
|
||||
sql << "create table soci_test(val integer)";
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Support for SOCI Common Tests
|
||||
//
|
||||
|
||||
class test_context : public test_context_base
|
||||
{
|
||||
public:
|
||||
test_context(backend_factory const &backEnd,
|
||||
std::string const &connectString)
|
||||
: test_context_base(backEnd, connectString) {}
|
||||
|
||||
table_creator_base * table_creator_1(session& s) const
|
||||
{
|
||||
return new table_creator_one(s);
|
||||
}
|
||||
|
||||
table_creator_base * table_creator_2(session& s) const
|
||||
{
|
||||
return new table_creator_two(s);
|
||||
}
|
||||
|
||||
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_for_get_affected_rows(s);
|
||||
}
|
||||
|
||||
std::string to_date_time(std::string const &datdt_string) const
|
||||
{
|
||||
return "timestamptz(\'" + datdt_string + "\')";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Redirect errors, unrecoverable problems, and assert() failures to STDERR,
|
||||
// instead of debug message window.
|
||||
// This hack is required to run asser()-driven tests by Buildbot.
|
||||
// NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
|
||||
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
||||
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
||||
#endif //_MSC_VER
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
connectString = argv[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
connectString = "FILEDSN=./test-postgresql.dsn";
|
||||
}
|
||||
try
|
||||
{
|
||||
std::cout << "\nSOCI ODBC with PostgreSQL Tests:\n\n";
|
||||
|
||||
test_context tc(backEnd, connectString);
|
||||
common_tests tests(tc);
|
||||
tests.run();
|
||||
|
||||
std::cout << "\nOK, all tests passed.\n\n";
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
catch (soci::odbc_soci_error const & e)
|
||||
{
|
||||
std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
|
||||
<< "Native Error Code: " << e.native_error_code() << std::endl
|
||||
<< "SOCI Message: " << e.what() << std::endl
|
||||
<< "ODBC Message: " << e.odbc_error_message() << std::endl;
|
||||
}
|
||||
catch (std::exception const & e)
|
||||
{
|
||||
std::cout << "STD::EXECEPTION " << e.what() << '\n';
|
||||
}
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
8
src/backends/odbc/test/test-postgresql.dsn
Normal file
8
src/backends/odbc/test/test-postgresql.dsn
Normal file
@@ -0,0 +1,8 @@
|
||||
[ODBC]
|
||||
Description=DSN for SOCI ODBC connection to PostgreSQL
|
||||
Driver=PostgreSQL ANSI
|
||||
Server=localhost
|
||||
Port=5432
|
||||
Database=soci_test
|
||||
UID=postgres
|
||||
PWD=
|
||||
Reference in New Issue
Block a user