123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
- //
- // Permission to use, copy, modify, and/or distribute this software for any
- // purpose with or without fee is hereby granted, provided that the above
- // copyright notice and this permission notice appear in all copies.
- //
- // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- #ifndef __DATASRC_SQLITE3_CONNECTION_H
- #define __DATASRC_SQLITE3_CONNECTION_H
- #include <datasrc/database.h>
- #include <exceptions/exceptions.h>
- #include <cc/data.h>
- #include <boost/enable_shared_from_this.hpp>
- #include <string>
- namespace isc {
- namespace dns {
- class RRClass;
- }
- namespace datasrc {
- /**
- * \brief Low-level database error
- *
- * This exception is thrown when the SQLite library complains about something.
- * It might mean corrupt database file, invalid request or that something is
- * rotten in the library.
- */
- class SQLite3Error : public Exception {
- public:
- SQLite3Error(const char* file, size_t line, const char* what) :
- isc::Exception(file, line, what) {}
- };
- struct SQLite3Parameters;
- /**
- * \brief Concrete implementation of DatabaseConnection for SQLite3 databases
- *
- * This opens one database file with our schema and serves data from there.
- * According to the design, it doesn't interpret the data in any way, it just
- * provides unified access to the DB.
- */
- class SQLite3Connection : public DatabaseConnection,
- public boost::enable_shared_from_this<SQLite3Connection> {
- public:
- /**
- * \brief Constructor
- *
- * This opens the database and becomes ready to serve data from there.
- *
- * This might throw SQLite3Error if the given database file doesn't work
- * (it is broken, doesn't exist and can't be created, etc). It might throw
- * DataSourceError if the provided config is invalid (it is missing the
- * database_file element).
- *
- * \param config The part of config describing which database file should
- * be used.
- * \param rrclass Which class of data it should serve (while the database
- * can contain multiple classes of data, single connection can provide
- * only one class).
- * \todo Should we pass the database filename instead of the config? It
- * might be cleaner if this class doesn't know anything about configs.
- */
- SQLite3Connection(const isc::data::ConstElementPtr& config,
- const isc::dns::RRClass& rrclass);
- /**
- * \brief Destructor
- *
- * Closes the database.
- */
- ~ SQLite3Connection();
- /**
- * \brief Look up a zone
- *
- * This implements the getZone from DatabaseConnection and looks up a zone
- * in the data. It looks for a zone with the exact given origin and class
- * passed to the constructor.
- *
- * It may throw SQLite3Error if something about the database is broken.
- *
- * \param name The name of zone to look up
- * \return The pair contains if the lookup was successful in the first
- * element and the zone id in the second if it was.
- */
- virtual std::pair<bool, int> getZone(const isc::dns::Name& name) const;
- virtual IteratorContextPtr getIteratorContext(const isc::dns::Name&,
- int id) const;
- private:
- /// \brief Private database data
- SQLite3Parameters* dbparameters_;
- /// \brief The class for which the queries are done
- const std::string class_;
- /// \brief Opens the database
- void open(const std::string& filename);
- /// \brief Closes the database
- void close();
- class Context;
- friend class Context;
- };
- }
- }
- #endif
|