Page: add id field

This commit is contained in:
Albert S. 2018-11-04 19:31:58 +01:00
parent c93893a56e
commit 667776e3d7
4 changed files with 9 additions and 8 deletions

View File

@ -11,9 +11,9 @@ class PageDao
public:
PageDao();
virtual bool exists(std::string page) const = 0;
virtual bool exists(int id) const = 0;
virtual bool exists(unsigned int id) const = 0;
virtual std::optional<Page> find(std::string name) = 0;
virtual std::optional<Page> find(int id) = 0;
virtual std::optional<Page> find(unsigned int id) = 0;
virtual std::vector<std::string> getPageList(QueryOption option) = 0;
virtual std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) = 0;
virtual void deletePage(std::string page) = 0;

View File

@ -26,7 +26,7 @@ SOFTWARE.
/* TODO: copied from C version mostly, review whether access to table other than page is ok */
bool PageDaoSqlite::exists(int id) const
bool PageDaoSqlite::exists(unsigned int id) const
{
auto binder = *db << "SELECT 1 from page WHERE id = ?" << id ;
return execBool(binder);
@ -44,9 +44,10 @@ std::optional<Page> PageDaoSqlite::find(std::string name)
return find(pageid);
}
std::optional<Page> PageDaoSqlite::find(int id)
std::optional<Page> PageDaoSqlite::find(unsigned int id)
{
Page result;
result.pageid = id;
try
{
auto ps = *db << "SELECT name, lastrevision, visible FROM page WHERE id = ?";
@ -91,7 +92,7 @@ void PageDaoSqlite::save(const Page &page)
{
try
{
*db << "INSERT INTO page (name, lastrevision, visible) VALUES(?, ?, ?)" << page.name << page.current_revision << page.listed;
*db << "INSERT OR REPLACE INTO page (id, name, lastrevision, visible) VALUES((SELECT id FROM page WHERE name = ? OR id = ?), ?, ?, ?)" << page.name << page.pageid << page.name << page.current_revision << page.listed;
}
catch(sqlite::sqlite_exception &e)
{

View File

@ -11,11 +11,11 @@ class PageDaoSqlite : public PageDao, protected SqliteDao
public:
PageDaoSqlite() { }
void deletePage(std::string page) override;
bool exists(int id) const override;
bool exists(unsigned int id) const override;
bool exists(std::string name) const override;
void save(const Page &page) override;
std::optional<Page> find(std::string name) override;
std::optional<Page> find(int id) override;
std::optional<Page> find(unsigned int id) override;
std::vector<std::string> getPageList(QueryOption option) override;
std::vector<std::string> fetchCategories(std::string pagename, QueryOption option) override;
using SqliteDao::SqliteDao;

2
page.h
View File

@ -9,7 +9,7 @@ public:
std::string name;
bool listed;
unsigned int current_revision;
unsigned int pageid;
};
#endif // PAGE_H