// file : odb/sqlite/database.cxx // copyright : Copyright (c) 2009-2012 Code Synthesis Tools CC // license : GNU GPL v2; see accompanying LICENSE file #include #include #include #include #include #include #include using namespace std; namespace odb { namespace sqlite { using odb::details::transfer_ptr; database:: ~database () { } database:: database (const string& name, int flags, bool foreign_keys, transfer_ptr factory) : name_ (name), flags_ (flags), foreign_keys_ (foreign_keys), factory_ (factory.transfer ()) { if (factory_.get () == 0) factory_.reset (new connection_pool_factory ()); factory_->database (*this); } database:: database (int& argc, char* argv[], bool erase, int flags, bool foreign_keys, transfer_ptr factory) : flags_ (flags), foreign_keys_ (foreign_keys), factory_ (factory.transfer ()) { using namespace details; try { cli::argv_file_scanner scan (argc, argv, "--options-file", erase); options ops (scan, cli::unknown_mode::skip, cli::unknown_mode::skip); name_ = ops.database (); if (ops.create ()) flags_ |= SQLITE_OPEN_CREATE; if (ops.read_only ()) flags_ = (flags_ & ~SQLITE_OPEN_READWRITE) | SQLITE_OPEN_READONLY; } catch (const cli::exception& e) { ostringstream ostr; ostr << e; throw cli_exception (ostr.str ()); } if (factory_.get () == 0) factory_.reset (new connection_pool_factory ()); factory_->database (*this); } void database:: print_usage (std::ostream& os) { details::options::print_usage (os); } transaction_impl* database:: begin () { return new transaction_impl (*this, transaction_impl::deferred); } transaction_impl* database:: begin_immediate () { return new transaction_impl (*this, transaction_impl::immediate); } transaction_impl* database:: begin_exclusive () { return new transaction_impl (*this, transaction_impl::exclusive); } odb::connection* database:: connection_ () { connection_ptr c (factory_->connect ()); return c.release (); } } }