aboutsummaryrefslogtreecommitdiff
path: root/libcommon/common.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2010-06-04 16:57:53 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2010-06-04 16:57:53 +0200
commitca42db0da0d12b1dcdee1cc82dbbd171131cb628 (patch)
tree166fb9b3d51f686688da9ff86c5a51f3cc36a477 /libcommon/common.cxx
parentbdb7fa4620c9950b16e8292c22424bbf15a25613 (diff)
Initial set of tests
Diffstat (limited to 'libcommon/common.cxx')
-rw-r--r--libcommon/common.cxx45
1 files changed, 45 insertions, 0 deletions
diff --git a/libcommon/common.cxx b/libcommon/common.cxx
new file mode 100644
index 0000000..bfc3482
--- /dev/null
+++ b/libcommon/common.cxx
@@ -0,0 +1,45 @@
+// file : libcommon/common.cxx
+// author : Boris Kolpackov <boris@codesynthesis.com>
+// copyright : Copyright (c) 2005-2010 Code Synthesis Tools CC
+// license : GNU GPL v2; see accompanying LICENSE file
+
+#include <cstdlib> // std::exit
+#include <iostream>
+
+#ifdef DB_ID_MYSQL
+# include <odb/mysql/database.hxx>
+#endif
+
+#include "common.hxx"
+#include "options.hxx"
+
+using namespace std;
+using namespace odb;
+
+auto_ptr<database>
+create_database (int argc, char* argv[])
+{
+#ifdef DB_ID_MYSQL
+ 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);
+ }
+
+ return auto_ptr<database> (
+ new mysql::database (
+ ops.user (),
+ ops.passwd_specified () ? &ops.passwd () : 0,
+ ops.db_name (),
+ ops.host (),
+ ops.port (),
+ ops.socket_specified () ? &ops.socket () : 0));
+#else
+ return auto_ptr<database> (0);
+#endif
+}