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

test-odbc-access.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 integer, ul number, d float, "
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 float, num_int integer,"
00051                      " name varchar(20), sometime datetime, 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     
00073 test_context(backend_factory const &backEnd, 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 fromDual(std::string const &sql) const
00092     {
00093         return sql;
00094     }
00095 
00096     std::string toDate(std::string const &datdt_string) const
00097     {
00098         return "#" + datdt_string + "#";
00099     }
00100 
00101     std::string to_date_time(std::string const &datdt_string) const
00102     {
00103         return "#" + datdt_string + "#";
00104     }
00105 };
00106 
00107 int main(int argc, char** argv)
00108 {
00109 
00110 #ifdef _MSC_VER
00111     // Redirect errors, unrecoverable problems, and assert() failures to STDERR,
00112     // instead of debug message window.
00113     // This hack is required to run asser()-driven tests by Buildbot.
00114     // NOTE: Comment this 2 lines for debugging with Visual C++ debugger to catch assertions inside.
00115     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
00116     _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
00117 #endif //_MSC_VER
00118 
00119     if (argc == 2)
00120     {
00121         connectString = argv[1];
00122     }
00123     else
00124     {
00125         connectString = "FILEDSN=./test-access.dsn";
00126     }
00127     try
00128     {
00129         test_context tc(backEnd, connectString);
00130         common_tests tests(tc);
00131         tests.run();
00132     }
00133     catch (soci::odbc_soci_error const & e)
00134     {
00135         std::cout << "ODBC Error Code: " << e.odbc_error_code() << std::endl
00136                   << "Native Error Code: " << e.native_error_code() << std::endl
00137                   << "SOCI Message: " << e.what() << std::endl
00138                   << "ODBC Message: " << e.odbc_error_message() << std::endl;
00139     }
00140     catch (std::exception const & e)
00141     {
00142         std::cout << "STD::EXECEPTION " << e.what() << '\n';
00143     }
00144 }
 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