diff options
Diffstat (limited to 'libcommon/common/common.cxx')
-rw-r--r-- | libcommon/common/common.cxx | 46 |
1 files changed, 40 insertions, 6 deletions
diff --git a/libcommon/common/common.cxx b/libcommon/common/common.cxx index bffc0fc..4ad169c 100644 --- a/libcommon/common/common.cxx +++ b/libcommon/common/common.cxx @@ -11,6 +11,11 @@ #if defined(DATABASE_MYSQL) # include <odb/mysql/database.hxx> # include <odb/mysql/connection-factory.hxx> +#elif defined(DATABASE_SQLITE) +# include <odb/transaction.hxx> +# include <odb/schema-catalog.hxx> +# include <odb/sqlite/database.hxx> +# include <odb/sqlite/connection-factory.hxx> #else # error unknown database #endif @@ -18,12 +23,15 @@ #include <common/common.hxx> using namespace std; +using namespace odb::core; #if defined(DATABASE_MYSQL) -using namespace odb::mysql; +namespace mysql = odb::mysql; +#elif defined(DATABASE_SQLITE) +namespace sqlite = odb::sqlite; #endif -auto_ptr<odb::database> +auto_ptr<database> create_database (int& argc, char* argv[], size_t max_connections) { if (argc > 1 && argv[1] == string ("--help")) @@ -31,16 +39,42 @@ create_database (int& argc, char* argv[], size_t max_connections) cerr << "Usage: " << argv[0] << " [options]" << endl << "Options:" << endl; - database::print_usage (cerr); +#if defined(DATABASE_MYSQL) + mysql::database::print_usage (cerr); +#elif defined(DATABASE_SQLITE) + sqlite::database::print_usage (cerr); +#endif + exit (0); } + auto_ptr<database> db; + #if defined(DATABASE_MYSQL) - auto_ptr<connection_factory> f; + auto_ptr<mysql::connection_factory> f; if (max_connections != 0) - f.reset (new connection_pool_factory (max_connections)); + f.reset (new mysql::connection_pool_factory (max_connections)); + + db.reset (new mysql::database (argc, argv, false, 0, f)); +#elif defined(DATABASE_SQLITE) + auto_ptr<sqlite::connection_factory> f; - return auto_ptr<odb::database> (new database (argc, argv, false, 0, f)); + if (max_connections != 0) + f.reset (new sqlite::connection_pool_factory (max_connections)); + + db.reset ( + new sqlite::database ( + argc, argv, false, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, f)); + + // Create the database schema. + // + { + transaction t (db->begin ()); + schema_catalog::create_schema (*db); + t.commit (); + } #endif + + return db; } |