Warning, file /sdk/codevis/thirdparty/soci/examples/connect/connect.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 // 0002 // Copyright (C) 2021 Vadim Zeitlin 0003 // Distributed under the Boost Software License, Version 1.0. 0004 // (See accompanying file LICENSE_1_0.txt or copy at 0005 // http://www.boost.org/LICENSE_1_0.txt) 0006 // 0007 // 0008 0009 // This is the simplest possible example of using SOCI: just connect to the 0010 // database using the provided command line argument. 0011 0012 #include <soci/soci.h> 0013 0014 #include <cstdlib> 0015 #include <iostream> 0016 0017 int main(int argc, char* argv[]) 0018 { 0019 if (argc != 2) 0020 { 0021 std::cerr << "usage: " << argv[0] << " <connection-string>\n"; 0022 return EXIT_FAILURE; 0023 } 0024 0025 char const* const connectString = argv[1]; 0026 0027 try 0028 { 0029 soci::session sql(connectString); 0030 0031 std::cout << "Successfully connected to \"" << connectString << "\", " 0032 << "using \"" << sql.get_backend_name() << "\" backend.\n"; 0033 0034 return EXIT_SUCCESS; 0035 } 0036 catch (soci::soci_error const& e) 0037 { 0038 std::cerr << "Connection to \"" << connectString << "\" failed: " 0039 << e.what() << "\n"; 0040 } 0041 catch (std::runtime_error const& e) 0042 { 0043 std::cerr << "Unexpected standard exception occurred: " 0044 << e.what() << "\n"; 0045 } 0046 catch (...) 0047 { 0048 std::cerr << "Unexpected unknown exception occurred.\n"; 0049 } 0050 0051 return EXIT_FAILURE; 0052 }