added: forum
added: mount params can have arguments (in parentheses) added: mount params: withheader, withinfo, restrictcreatethread, only_root_can_remove, can_use_emacs_on(level), can_use_mkdir_on(level), added: table Item has 'subject' column now removed: column 'subject' from table Content git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@505 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
223
core/db.cpp
223
core/db.cpp
@@ -361,6 +361,7 @@ void Db::CheckAllUrlSubject()
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query, query2;
|
||||
// !! subject zostal wrzucony do tabeli item
|
||||
query << "select item.id, subject from core.item left join core.content on item.content_id = content.id where url is null or url=''";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
@@ -419,16 +420,17 @@ Error Db::AddItemIntoItem(Item & item)
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, url) values (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << ConvertTime(item.date_creation) << "', ";
|
||||
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, subject, url) values (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << ConvertTime(item.date_creation) << "', ";
|
||||
query << '\'' << ConvertTime(item.date_modification) << "', ";
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.parent_id << "', ";
|
||||
query << '\'' << item.content_id << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.parent_id << "', ";
|
||||
query << '\'' << item.content_id << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
|
||||
url_without_id = AddItemCreateUrlSubject(item);
|
||||
|
||||
@@ -468,10 +470,9 @@ Error Db::AddItemIntoContent(Item & item)
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.content (subject, content, content_type) values (";
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << item.content_type << "');";
|
||||
query << "insert into core.content (content, content_type) values (";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << item.content_type << "');";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
@@ -511,8 +512,7 @@ return result;
|
||||
|
||||
|
||||
|
||||
// !! with_subject zamienic na with_url
|
||||
Error Db::EditItemInItem(Item & item, bool with_subject)
|
||||
Error Db::EditItemInItem(Item & item, bool with_url)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error result = Error::ok;
|
||||
@@ -522,22 +522,23 @@ Error Db::EditItemInItem(Item & item, bool with_subject)
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id";
|
||||
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject";
|
||||
|
||||
if( with_subject )
|
||||
if( with_url )
|
||||
query << ", url";
|
||||
|
||||
query << ") = (";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << ConvertTime(item.date_creation) << "', ";
|
||||
query << '\'' << item.user_id << "', ";
|
||||
query << '\'' << item.group_id << "', ";
|
||||
query << '\'' << item.privileges << "', ";
|
||||
query << '\'' << ConvertTime(item.date_creation) << "', ";
|
||||
query << '\'' << ConvertTime(item.date_modification) << "', ";
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << item.parent_id << "' ";
|
||||
query << '\'' << static_cast<int>(item.type) << "', ";
|
||||
query << '\'' << item.default_item << "', ";
|
||||
query << '\'' << item.parent_id << "', ";
|
||||
query << '\'' << Escape(item.subject) << "' ";
|
||||
|
||||
if( with_subject )
|
||||
if( with_url )
|
||||
{
|
||||
url_without_id = AddItemCreateUrlSubject(item);
|
||||
|
||||
@@ -552,7 +553,7 @@ Error Db::EditItemInItem(Item & item, bool with_subject)
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
|
||||
if( with_subject && !url_without_id )
|
||||
if( with_url && !url_without_id )
|
||||
ToString(item.url, item.id);
|
||||
}
|
||||
catch(const Error & e)
|
||||
@@ -576,9 +577,8 @@ Error Db::EditItemInContent(Item & item)
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.content set (subject, content, content_type) = (";
|
||||
query << "update core.content set (content, content_type) = (";
|
||||
|
||||
query << '\'' << Escape(item.subject) << "', ";
|
||||
query << '\'' << Escape(item.content) << "', ";
|
||||
query << '\'' << item.content_type << "' ";
|
||||
|
||||
@@ -664,9 +664,8 @@ return result;
|
||||
|
||||
|
||||
// item.id must be set
|
||||
// !! with_subject zamienic na with_url
|
||||
// !! moze nazwa poprostu EditItem (nie trzeba tego ById) ? (sprawdzic czy nie koliduje z inna nazwa)
|
||||
Error Db::EditItemById(Item & item, bool with_subject)
|
||||
Error Db::EditItemById(Item & item, bool with_url)
|
||||
{
|
||||
Error result = Error::ok;
|
||||
|
||||
@@ -681,7 +680,7 @@ Error Db::EditItemById(Item & item, bool with_subject)
|
||||
result = EditItemInContent(item);
|
||||
|
||||
if( result == Error::ok )
|
||||
result = EditItemInItem(item, with_subject);
|
||||
result = EditItemInItem(item, with_url);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -691,7 +690,7 @@ return result;
|
||||
|
||||
// item.url and item.parent_id must be set
|
||||
// doesn't work with directiories
|
||||
Error Db::EditItemByUrl(Item & item, bool with_subject)
|
||||
Error Db::EditItemByUrl(Item & item, bool with_url)
|
||||
{
|
||||
Error result = EditItemGetId(item);
|
||||
|
||||
@@ -700,7 +699,7 @@ Error Db::EditItemByUrl(Item & item, bool with_subject)
|
||||
result = EditItemInContent(item);
|
||||
|
||||
if( result == Error::ok )
|
||||
result = EditItemInItem(item, with_subject);
|
||||
result = EditItemInItem(item, with_url);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -747,33 +746,48 @@ return result;
|
||||
|
||||
|
||||
|
||||
PGresult * Db::GetItemsQuery(Item & item_ref, bool asc)
|
||||
PGresult * Db::GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
|
||||
{
|
||||
std::ostringstream query;
|
||||
query << "select * from core.item left join core.content on item.content_id = content.id where type!='0' and parent_id='" << item_ref.parent_id << "'";
|
||||
query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item";
|
||||
|
||||
if( item_ref.id != -1 )
|
||||
query << " and item.id='" << item_ref.id << "'";
|
||||
if( type != Item::dir )
|
||||
{
|
||||
if( with_subject )
|
||||
query << ", subject";
|
||||
|
||||
if( with_content )
|
||||
query << ", content, content_type";
|
||||
}
|
||||
|
||||
if( !item_ref.url.empty() )
|
||||
query << " and url='" << Escape(item_ref.url) << "'";
|
||||
query << " from core.item";
|
||||
|
||||
if( type != Item::dir && with_content )
|
||||
query << " left join core.content on item.content_id = content.id";
|
||||
|
||||
query << " where parent_id='" << parent_id << "'";
|
||||
|
||||
query << " order by item.date_modification";
|
||||
if( type == Item::dir )
|
||||
query << " and type='0'";
|
||||
|
||||
if( type == Item::file )
|
||||
query << " and type='1'";
|
||||
|
||||
if( asc )
|
||||
query << " order by item.date_creation";
|
||||
|
||||
if( sort_asc )
|
||||
query << " asc";
|
||||
else
|
||||
query << " desc";
|
||||
|
||||
query << ';';
|
||||
|
||||
|
||||
return AssertQuery(query.str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Db::GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc)
|
||||
void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
|
||||
{
|
||||
item_table.clear();
|
||||
PGresult * r = 0;
|
||||
@@ -782,7 +796,7 @@ void Db::GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc)
|
||||
{
|
||||
AssertConnection();
|
||||
|
||||
r = GetItemsQuery(item_ref, asc);
|
||||
r = GetItemsQuery(parent_id, type, with_subject, with_content, sort_asc);
|
||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
|
||||
Item item;
|
||||
@@ -930,7 +944,8 @@ long Db::GetDirId(long parent_id, const std::string & url)
|
||||
|
||||
|
||||
|
||||
|
||||
// !! w tej metodzie odczytujemy tylko uprawnienia?
|
||||
// bo w tej chwili jest caly item odczytywany
|
||||
bool Db::GetPriv(Item & item, long id)
|
||||
{
|
||||
bool result = false;
|
||||
@@ -1380,7 +1395,7 @@ Error Db::GetThreadByDirId(long dir_id, Thread & thread)
|
||||
AssertConnection();
|
||||
|
||||
std::ostringstream query;
|
||||
query << "select id, dir_id, subject, closed from core.thread where thread.dir_id = " << dir_id << ";";
|
||||
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id from core.thread left join core.item on thread.last_item = item.id where thread.dir_id = '" << dir_id << "';";
|
||||
|
||||
r = AssertQuery( query.str() );
|
||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
@@ -1391,20 +1406,81 @@ Error Db::GetThreadByDirId(long dir_id, Thread & thread)
|
||||
log << log1 << "Db: there is more than one thread with dir_id: " << dir_id << logend;
|
||||
else
|
||||
if( rows == 0 )
|
||||
{
|
||||
log << log1 << "Db: there is no a thread with dir_id: " << dir_id << logend;
|
||||
throw Error(Error::no_thread);
|
||||
}
|
||||
|
||||
int cid = AssertColumn(r, "id");
|
||||
int cdir_id = AssertColumn(r, "dir_id");
|
||||
int csubject = AssertColumn(r, "subject");
|
||||
int cclosed = AssertColumn(r, "closed");
|
||||
int cid = AssertColumn(r, "id");
|
||||
int cparent_id = AssertColumn(r, "parent_id");
|
||||
int cdir_id = AssertColumn(r, "dir_id");
|
||||
int cclosed = AssertColumn(r, "closed");
|
||||
int citems = AssertColumn(r, "items");
|
||||
int clast_item = AssertColumn(r, "last_item");
|
||||
int cdate_modification = PQfnumber(r, "date_modification");
|
||||
int cuser_id = PQfnumber(r, "user_id");
|
||||
|
||||
thread.id = atol( AssertValue(r, 0, cid) );
|
||||
thread.parent_id = atol( AssertValue(r, 0, cparent_id) );
|
||||
thread.dir_id = atol( AssertValue(r, 0, cdir_id) );
|
||||
thread.closed = atol( AssertValue(r, 0, cclosed) ) == 0 ? false : true;
|
||||
thread.items = atol( AssertValue(r, 0, citems) );
|
||||
thread.last_item.id = atol( AssertValue(r, 0, clast_item) );
|
||||
thread.last_item.date_modification = ConvertTime( Db::AssertValue(r, 0, cdate_modification) );
|
||||
thread.last_item.user_id = atol( Db::AssertValue(r, 0, cuser_id) );
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
status = e;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
thread.id = atol( AssertValue(r, 0, cid) );
|
||||
thread.dir_id = atol( AssertValue(r, 0, cdir_id) );
|
||||
thread.subject = AssertValue(r, 0, csubject);
|
||||
thread.closed = atol( AssertValue(r, 0, cclosed) ) == 0 ? false : true;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error status = Error::ok;
|
||||
|
||||
try
|
||||
{
|
||||
AssertConnection();
|
||||
|
||||
std::ostringstream query;
|
||||
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id "
|
||||
"from core.thread left join core.item on thread.last_item = item.id "
|
||||
"where thread.parent_id = '" << parent_id << "' order by date_modification asc;";
|
||||
|
||||
r = AssertQuery( query.str() );
|
||||
AssertResultStatus(r, PGRES_TUPLES_OK);
|
||||
|
||||
int rows = PQntuples(r);
|
||||
Thread thread;
|
||||
|
||||
int cid = AssertColumn(r, "id");
|
||||
int cparent_id = AssertColumn(r, "parent_id");
|
||||
int cdir_id = AssertColumn(r, "dir_id");
|
||||
int cclosed = AssertColumn(r, "closed");
|
||||
int citems = AssertColumn(r, "items");
|
||||
int clast_item = AssertColumn(r, "last_item");
|
||||
int cdate_modification = PQfnumber(r, "date_modification");
|
||||
int cuser_id = PQfnumber(r, "user_id");
|
||||
|
||||
for(int i=0 ; i<rows ; ++i)
|
||||
{
|
||||
thread.id = atol( AssertValue(r, i, cid) );
|
||||
thread.parent_id = atol( AssertValue(r, i, cparent_id) );
|
||||
thread.dir_id = atol( AssertValue(r, i, cdir_id) );
|
||||
thread.closed = atol( AssertValue(r, i, cclosed) ) == 0 ? false : true;
|
||||
thread.items = atol( AssertValue(r, i, citems) );
|
||||
thread.last_item.id = atol( AssertValue(r, i, clast_item) );
|
||||
thread.last_item.date_modification = ConvertTime( Db::AssertValue(r, i, cdate_modification) );
|
||||
thread.last_item.user_id = atol( Db::AssertValue(r, i, cuser_id) );
|
||||
|
||||
thread_tab.push_back(thread);
|
||||
}
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
@@ -1420,6 +1496,7 @@ return status;
|
||||
|
||||
|
||||
|
||||
|
||||
Error Db::AddThread(Thread & thread)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
@@ -1429,10 +1506,12 @@ Error Db::AddThread(Thread & thread)
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "insert into core.thread (dir_id, subject, closed) values (";
|
||||
query << "insert into core.thread (parent_id, dir_id, closed, items, last_item) values (";
|
||||
query << '\'' << thread.parent_id << "', ";
|
||||
query << '\'' << thread.dir_id << "', ";
|
||||
query << '\'' << Escape(thread.subject) << "', ";
|
||||
query << '\'' << (thread.closed ? 1 : 0 ) << "'); ";
|
||||
query << '\'' << (thread.closed ? 1 : 0 ) << "', ";
|
||||
query << '\'' << thread.items << "', ";
|
||||
query << '\'' << thread.last_item.id << "'); ";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
@@ -1451,3 +1530,27 @@ return status;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Error Db::EditThreadAddItem(long dir_id, long item_id)
|
||||
{
|
||||
PGresult * r = 0;
|
||||
Error status = Error::ok;
|
||||
|
||||
try
|
||||
{
|
||||
AssertConnection();
|
||||
std::ostringstream query;
|
||||
query << "update core.thread set (last_item, items) = ('" << item_id << "', items+1) where dir_id='" << dir_id << "';";
|
||||
|
||||
r = AssertQuery(query.str());
|
||||
AssertResultStatus(r, PGRES_COMMAND_OK);
|
||||
}
|
||||
catch(const Error & e)
|
||||
{
|
||||
status = e;
|
||||
}
|
||||
|
||||
ClearResult(r);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
Reference in New Issue
Block a user