aboutsummaryrefslogtreecommitdiff
path: root/libcommon/common/common.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'libcommon/common/common.cxx')
-rw-r--r--libcommon/common/common.cxx58
1 files changed, 34 insertions, 24 deletions
diff --git a/libcommon/common/common.cxx b/libcommon/common/common.cxx
index 4d2d5f0..ed8be69 100644
--- a/libcommon/common/common.cxx
+++ b/libcommon/common/common.cxx
@@ -24,34 +24,44 @@ using namespace odb;
auto_ptr<database>
create_database (int argc, char* argv[], size_t max_connections)
{
+ try
+ {
#ifdef DB_ID_MYSQL
- cli::argv_file_scanner scan (argc, argv, "--options-file");
- cli::mysql_options ops (scan);
+ cli::argv_file_scanner scan (argc, argv, "--options-file");
+ cli::mysql_options ops (scan);
+
+ if (ops.help ())
+ {
+ cerr << "Usage: " << argv[0] << " [options]" << endl
+ << "Options:" << endl;
+ cli::mysql_options::print_usage (cerr);
+ exit (0);
+ }
+
+ auto_ptr<mysql::connection_factory> f;
- if (ops.help ())
+ if (max_connections != 0)
+ f.reset (new mysql::connection_pool_factory (max_connections));
+
+ return auto_ptr<database> (
+ new mysql::database (
+ ops.user (),
+ ops.password_specified () ? &ops.password () : 0,
+ ops.database (),
+ ops.host (),
+ ops.port (),
+ ops.socket_specified () ? &ops.socket () : 0,
+ 0,
+ f));
+#else
+ return auto_ptr<database> (0);
+#endif
+ }
+ catch (const cli::exception& e)
{
- cerr << "Usage: " << argv[0] << " [options]" << endl
- << "Options:" << endl;
- cli::mysql_options::print_usage (cerr);
- exit (0);
+ cerr << e.what () << endl;
+ exit (1);
}
- auto_ptr<mysql::connection_factory> f;
-
- if (max_connections != 0)
- f.reset (new mysql::connection_pool_factory (max_connections));
-
- return auto_ptr<database> (
- new mysql::database (
- ops.user (),
- ops.password_specified () ? &ops.password () : 0,
- ops.database (),
- ops.host (),
- ops.port (),
- ops.socket_specified () ? &ops.socket () : 0,
- 0,
- f));
-#else
return auto_ptr<database> (0);
-#endif
}