test-odbc-access.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 integer, ul number, d float, "
31  "tm timestamp, 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 float, 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 
73 test_context(backend_factory const &backEnd, 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 fromDual(std::string const &sql) const
97  {
98  return sql;
99  }
100 
101  std::string toDate(std::string const &datdt_string) const
102  {
103  return "#" + datdt_string + "#";
104  }
105 
106  std::string to_date_time(std::string const &datdt_string) const
107  {
108  return "#" + datdt_string + "#";
109  }
110 };
111 
112 int main(int argc, char** argv)
113 {
114 
115 #ifdef _MSC_VER
116  // Redirect errors, unrecoverable problems, and assert() failures to STDERR,
117  // instead of debug message window.
118  // This hack is required to run asser()-driven tests by Buildbot.
119  // NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
120  _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
121  _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
122 #endif //_MSC_VER
123 
124  if (argc == 2)
125  {
126  connectString = argv[1];
127  }
128  else
129  {
130  connectString = "FILEDSN=./test-access.dsn";
131  }
132  try
133  {
134  std::cout << "\nSOCI ODBC with MS Access Tests:\n\n";
135 
136  test_context tc(backEnd, connectString);
137  common_tests tests(tc);
138  tests.run();
139 
140  std::cout << "\nOK, all tests passed.\n\n";
141  return EXIT_SUCCESS;
142  }
143  catch (soci::odbc_soci_error const & e)
144  {
145  std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
146  << "Native Error Code: " << e.native_error_code() << std::endl
147  << "SOCI Message: " << e.what() << std::endl
148  << "ODBC Message: " << e.odbc_error_message() << std::endl;
149  }
150  catch (std::exception const & e)
151  {
152  std::cout << "STD::EXECEPTION " << e.what() << '\n';
153  }
154  return EXIT_FAILURE;
155 }
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
std::string connectString
std::string toDate(std::string const &datdt_string) const
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)
std::string fromDual(std::string const &sql) const
SOCI_ODBC_DECL backend_factory const * factory_odbc()
backend_factory const & backEnd
table_creator_three(session &sql)
int main(int argc, char **argv)


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