/
test-odbc-mysql.cpp
144 lines (126 loc) · 3.85 KB
/
test-odbc-mysql.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
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;
}