SOCI Logo Get SOCI at SourceForge.net. Fast, secure and Free Open Source software downloads

test-odbc-postgresql.cpp

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, David Courtney
00003 // Distributed under the Boost Software License, Version 1.0.
00004 // (See accompanying file LICENSE_1_0.txt or copy at
00005 // http://www.boost.org/LICENSE_1_0.txt)
00006 //
00007 
00008 //
00009 #if defined(SOCI_HEADERS_BURIED)
00010 #       include <soci/core/soci.h>
00011 #       include <soci/backends/odbc/soci-odbc.h>
00012 #       include <soci/core/test/common-tests.h>
00013 #else
00014 #       include <soci.h>
00015 #       include <soci-odbc.h>
00016 #       include <test/common-tests.h>
00017 #endif
00018 //
00019 #include <iostream>
00020 #include <string>
00021 #include <cassert>
00022 #include <ctime>
00023 #include <cmath>
00024 
00025 using namespace soci;
00026 using namespace soci::tests;
00027 
00028 std::string connectString;
00029 backend_factory const &backEnd = odbc;
00030 
00031 
00032 // DDL Creation objects for common tests
00033 struct table_creator_one : public table_creator_base
00034 {
00035     table_creator_one(session & sql)
00036         : table_creator_base(sql)
00037     {
00038         sql << "create table soci_test(id integer, val integer, c char, "
00039                  "str varchar(20), sh int2, ul numeric(20), d float8, "
00040                  "tm timestamp, i1 integer, i2 integer, i3 integer, "
00041                  "name varchar(20))";
00042     }
00043 };
00044 
00045 struct table_creator_two : public table_creator_base
00046 {
00047     table_creator_two(session & sql)
00048         : table_creator_base(sql)
00049     {
00050         sql  << "create table soci_test(num_float float8, num_int integer,"
00051                      " name varchar(20), sometime timestamp, chr char)";
00052     }
00053 };
00054 
00055 struct table_creator_three : public table_creator_base
00056 {
00057     table_creator_three(session & sql)
00058         : table_creator_base(sql)
00059     {
00060         sql << "create table soci_test(name varchar(100) not null, "
00061             "phone varchar(15))";
00062     }
00063 };
00064 
00065 //
00066 // Support for SOCI Common Tests
00067 //
00068 
00069 class test_context : public test_context_base
00070 {
00071 public:
00072     test_context(backend_factory const &backEnd,
00073                 std::string const &connectString)
00074         : test_context_base(backEnd, connectString) {}
00075 
00076     table_creator_base * table_creator_1(session& s) const
00077     {
00078         return new table_creator_one(s);
00079     }
00080 
00081     table_creator_base * table_creator_2(session& s) const
00082     {
00083         return new table_creator_two(s);
00084     }
00085 
00086     table_creator_base * table_creator_3(session& s) const
00087     {
00088         return new table_creator_three(s);
00089     }
00090 
00091     std::string to_date_time(std::string const &datdt_string) const
00092     {
00093         return "timestamptz(\'" + datdt_string + "\')";
00094     }
00095 
00096 };
00097 
00098 int main(int argc, char** argv)
00099 {
00100 
00101 #ifdef _MSC_VER
00102     // Redirect errors, unrecoverable problems, and assert() failures to STDERR,
00103     // instead of debug message window.
00104     // This hack is required to run asser()-driven tests by Buildbot.
00105     // NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
00106     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
00107     _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
00108 #endif //_MSC_VER
00109 
00110     if (argc == 2)
00111     {
00112         connectString = argv[1];
00113     }
00114     else
00115     {
00116         connectString = "FILEDSN=./test-postgresql.dsn";
00117     }
00118     try
00119     {
00120         test_context tc(backEnd, connectString);
00121         common_tests tests(tc);
00122         tests.run();
00123     }
00124     catch (soci::odbc_soci_error const & e)
00125     {
00126         std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
00127                   << "Native Error Code: " << e.native_error_code() << std::endl
00128                   << "SOCI Message: " << e.what() << std::endl
00129                   << "ODBC Message: " << e.odbc_error_message() << std::endl;
00130     }
00131     catch (std::exception const & e)
00132     {
00133         std::cout << "STD::EXECEPTION " << e.what() << '\n';
00134     }
00135 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
SourceForge Logo

Generated on Sun Oct 3 2010 17:42:16 for EXTRAS-SOCI by Doxygen 1.7.1