Page: add id field

This commit is contained in:
2018-11-04 19:31:58 +01:00
parent b6cdf9a088
commit 099f6533f8
4 changed files with 11 additions and 8 deletions

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 = ?";
@ -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)
{