test-odbc-mysql.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #include "soci.h"
9 #include "soci-odbc.h"
10 #include "common-tests.h"
11 #include <iostream>
12 #include <string>
13 #include <cassert>
14 #include <ctime>
15 #include <cmath>
16 
17 using namespace soci;
18 using namespace soci::tests;
19 
20 std::string connectString;
22 
23 // DDL Creation objects for common tests
25 {
27  : table_creator_base(sql)
28  {
29  sql << "create table soci_test(id integer, val integer, c char, "
30  "str varchar(20), sh int2, ul numeric(20), d float8, "
31  "tm datetime, i1 integer, i2 integer, i3 integer, "
32  "name varchar(20))";
33  }
34 };
35 
37 {
39  : table_creator_base(sql)
40  {
41  sql << "create table soci_test(num_float float8, num_int integer,"
42  " name varchar(20), sometime datetime, chr char)";
43  }
44 };
45 
47 {
49  : table_creator_base(sql)
50  {
51  sql << "create table soci_test(name varchar(100) not null, "
52  "phone varchar(15))";
53  }
54 };
55 
57 {
59  : table_creator_base(sql)
60  {
61  sql << "create table soci_test(val integer)";
62  }
63 };
64 
65 //
66 // Support for SOCI Common Tests
67 //
68 
69 class test_context : public test_context_base
70 {
71 public:
72  test_context(backend_factory const &backEnd,
73  std::string const &connectString)
74  : test_context_base(backEnd, connectString) {}
75 
77  {
78  return new table_creator_one(s);
79  }
80 
82  {
83  return new table_creator_two(s);
84  }
85 
87  {
88  return new table_creator_three(s);
89  }
90 
92  {
94  }
95 
96  std::string to_date_time(std::string const &datdt_string) const
97  {
98  return "\'" + datdt_string + "\'";
99  }
100 };
101 
102 int main(int argc, char** argv)
103 {
104 #ifdef _MSC_VER
105  // Redirect errors, unrecoverable problems, and assert() failures to STDERR,
106  // instead of debug message window.
107  // This hack is required to run asser()-driven tests by Buildbot.
108  // NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
109  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
110  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
111 #endif //_MSC_VER
112 
113  if (argc == 2)
114  {
115  connectString = argv[1];
116  }
117  else
118  {
119  connectString = "FILEDSN=./test-mysql.dsn";
120  }
121  try
122  {
123  std::cout << "\nSOCI ODBC with MySQL Tests:\n\n";
124 
125  test_context tc(backEnd, connectString);
126  common_tests tests(tc);
127  tests.run();
128 
129  std::cout << "\nOK, all tests passed.\n\n";
130  return EXIT_SUCCESS;
131  }
132  catch (soci::odbc_soci_error const & e)
133  {
134  std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
135  << "Native Error Code: " << e.native_error_code() << std::endl
136  << "SOCI Message: " << e.what() << std::endl
137  << "ODBC Message: " << e.odbc_error_message() << std::endl;
138  }
139  catch (std::exception const & e)
140  {
141  std::cout << "STD::EXECEPTION " << e.what() << '\n';
142  }
143  return EXIT_FAILURE;
144 }
std::string connectString
SQLCHAR const * odbc_error_message() const
Definition: soci-odbc.h:341
test_context(backend_factory const &backEnd, std::string const &connectString)
table_creator_base * table_creator_2(session &s) const
void run(bool dbSupportsTransactions=true)
Definition: common-tests.h:293
backend_factory const & backEnd
int main(int argc, char **argv)
table_creator_one(session &sql)
table_creator_base * table_creator_4(session &s) const
SQLINTEGER native_error_code() const
Definition: soci-odbc.h:337
table_creator_base * table_creator_1(session &s) const
table_creator_base * table_creator_3(session &s) const
SQLCHAR const * odbc_error_code() const
Definition: soci-odbc.h:333
std::string to_date_time(std::string const &datdt_string) const
table_creator_two(session &sql)
SOCI_ODBC_DECL backend_factory const * factory_odbc()
table_creator_three(session &sql)


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41