#include "database.h" #include #include #include "query.h" namespace verbly { database::database(std::string path) { if (sqlite3_open_v2(path.c_str(), &ppdb_, SQLITE_OPEN_READONLY, NULL) != SQLITE_OK) { // We still have to free the resources allocated. In the event that // allocation failed, ppdb will be null and sqlite3_close_v2 will just // ignore it. std::string errmsg(sqlite3_errmsg(ppdb_)); sqlite3_close_v2(ppdb_); throw database_error("Could not open verbly datafile", errmsg); } } database::database(database&& other) : database() { swap(*this, other); } database& database::operator=(database&& other) { swap(*this, other); return *this; } void swap(database& first, database& second) { std::swap(first.ppdb_, second.ppdb_); } database::~database() { sqlite3_close_v2(ppdb_); } query database::notions(filter where, bool random, int limit) const { return query(*this, ppdb_, std::move(where), random, limit); } query database::words(filter where, bool random, int limit) const { return query(*this, ppdb_, std::move(where), random, limit); } query database::groups(filter where, bool random, int limit) const { return query(*this, ppdb_, std::move(where), random, limit); } query database::frames(filter where, bool random, int limit) const { return query(*this, ppdb_, std::move(where), random, limit); } query database::lemmas(filter where, bool random, int limit) const { return query(*this, ppdb_, std::move(where), random, limit); } query
database::forms(filter where, bool random, int limit) const { return query(*this, ppdb_, std::move(where), random, limit); } query database::pronunciations(filter where, bool random, int limit) const { return query(*this, ppdb_, std::move(where), random, limit); } };