aboutsummaryrefslogtreecommitdiff
path: root/libcommon/common
diff options
context:
space:
mode:
Diffstat (limited to 'libcommon/common')
-rw-r--r--libcommon/common/common.cxx46
-rw-r--r--libcommon/common/makefile3
2 files changed, 43 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;
}
diff --git a/libcommon/common/makefile b/libcommon/common/makefile
index 1d78786..ae7d2ce 100644
--- a/libcommon/common/makefile
+++ b/libcommon/common/makefile
@@ -52,6 +52,9 @@ $(out_base)/config.h: $(dcf_root)/configuration-dynamic.make
ifeq ($(db_id),mysql)
@echo '#define DATABASE_MYSQL 1' >>$@
endif
+ifeq ($(db_id),sqlite)
+ @echo '#define DATABASE_SQLITE 1' >>$@
+endif
@echo '#define HAVE_TR1_MEMORY 1' >>$@
@echo '' >>$@
@echo '#endif /* LIBCOMMON_COMMON_CONFIG_H */' >>$@