From cd1deec2f13b6976fb3aac0e5e8d42a79875aef1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 27 Mar 2011 15:38:42 +0200 Subject: Build infrastructure for SQLite --- libcommon/common/common.cxx | 46 +++++++++++++++++++++++++++++++++++++++------ libcommon/common/makefile | 3 +++ 2 files changed, 43 insertions(+), 6 deletions(-) (limited to 'libcommon') 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 # include +#elif defined(DATABASE_SQLITE) +# include +# include +# include +# include #else # error unknown database #endif @@ -18,12 +23,15 @@ #include 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 +auto_ptr 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 db; + #if defined(DATABASE_MYSQL) - auto_ptr f; + auto_ptr 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 f; - return auto_ptr (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 */' >>$@ -- cgit v1.1