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