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

test-odbc-mysql.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 // DDL Creation objects for common tests
00032 struct table_creator_one : public table_creator_base
00033 {
00034     table_creator_one(session & sql)
00035         : table_creator_base(sql)
00036     {
00037         sql << "create table soci_test(id integer, val integer, c char, "
00038                  "str varchar(20), sh int2, ul numeric(20), d float8, "
00039                  "tm datetime, i1 integer, i2 integer, i3 integer, "
00040                  "name varchar(20))";
00041     }
00042 };
00043 
00044 struct table_creator_two : public table_creator_base
00045 {
00046     table_creator_two(session & sql)
00047         : table_creator_base(sql)
00048     {
00049         sql  << "create table soci_test(num_float float8, num_int integer,"
00050                      " name varchar(20), sometime datetime, chr char)";
00051     }
00052 };
00053 
00054 struct table_creator_three : public table_creator_base
00055 {
00056     table_creator_three(session & sql)
00057         : table_creator_base(sql)
00058     {
00059         sql << "create table soci_test(name varchar(100) not null, "
00060             "phone varchar(15))";
00061     }
00062 };
00063 
00064 //
00065 // Support for SOCI Common Tests
00066 //
00067 
00068 class test_context : public test_context_base
00069 {
00070 public:
00071     test_context(backend_factory const &backEnd,
00072                 std::string const &connectString)
00073         : test_context_base(backEnd, connectString) {}
00074 
00075     table_creator_base * table_creator_1(session& s) const
00076     {
00077         return new table_creator_one(s);
00078     }
00079 
00080     table_creator_base * table_creator_2(session& s) const
00081     {
00082         return new table_creator_two(s);
00083     }
00084 
00085     table_creator_base * table_creator_3(session& s) const
00086     {
00087         return new table_creator_three(s);
00088     }
00089 
00090     std::string to_date_time(std::string const &datdt_string) const
00091     {
00092         return "\'" + datdt_string + "\'";
00093     }
00094 
00095 };
00096 
00097 int main(int argc, char** argv)
00098 {
00099 
00100 #ifdef _MSC_VER
00101     // Redirect errors, unrecoverable problems, and assert() failures to STDERR,
00102     // instead of debug message window.
00103     // This hack is required to run asser()-driven tests by Buildbot.
00104     // NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
00105     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
00106     _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
00107 #endif //_MSC_VER
00108 
00109     if (argc == 2)
00110     {
00111         connectString = argv[1];
00112     }
00113     else
00114     {
00115         connectString = "FILEDSN=./test-mysql.dsn";
00116     }
00117     try
00118     {
00119         test_context tc(backEnd, connectString);
00120         common_tests tests(tc);
00121         tests.run();
00122     }
00123     catch (soci::odbc_soci_error const & e)
00124     {
00125         std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
00126                   << "Native Error Code: " << e.native_error_code() << std::endl
00127                   << "SOCI Message: " << e.what() << std::endl
00128                   << "ODBC Message: " << e.odbc_error_message() << std::endl;
00129     }
00130     catch (std::exception const & e)
00131     {
00132         std::cout << "STD::EXECEPTION " << e.what() << '\n';
00133     }
00134 }
 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