Page: add id field

Bu işleme şunda yer alıyor:
Albert S. 2018-11-04 19:31:58 +01:00
ebeveyn b6cdf9a088
işleme 099f6533f8
4 değiştirilmiş dosya ile 11 ekleme ve 8 silme

Dosyayı Görüntüle

@ -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;

Dosyayı Görüntüle

@ -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 = ?";
@ -88,8 +89,9 @@ 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)
{

Dosyayı Görüntüle

@ -13,11 +13,11 @@ class PageDaoSqlite : public PageDao, protected SqliteDao
{
}
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;

1
page.h
Dosyayı Görüntüle

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