1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
#include <soci/soci.h>
#include <soci/empty/soci-empty.h>
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>
int main(int argc, char* argv[])
{
if (argc != 2)
{
std::cerr << "usage: " << argv[0] << " <connection-string>\n";
return EXIT_FAILURE;
}
std::string connectString{argv[1]};
try
{
soci::session sql(soci::empty, connectString);
std::cout << "Successfully connected to \"" << connectString << "\", "
<< "using \"" << sql.get_backend_name() << "\" backend.\n";
return EXIT_SUCCESS;
}
catch (const soci::soci_error& e)
{
std::cerr << "Connection to \"" << connectString << "\" failed: "
<< e.what() << "\n";
}
catch (const std::runtime_error& e)
{
std::cerr << "Unexpected standard exception occurred: "
<< e.what() << "\n";
}
catch (...)
{
std::cerr << "Unexpected unknown exception occurred.\n";
}
return EXIT_FAILURE;
}
|