added: column 'guest_name' to 'item' table

used when user_id is -1
added: mount parameters: thread_with_info, thread_with_header
added: function rm can remove threads



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@506 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-06-07 02:40:27 +00:00
parent 1eb42446f8
commit f99c993d96
20 changed files with 283 additions and 63 deletions

View File

@@ -420,7 +420,7 @@ 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, subject, url) values (";
query << "insert into core.item (user_id, group_id, privileges, date_creation, date_modification, type, parent_id, content_id, default_item, subject, guest_name, url) values (";
query << '\'' << item.user_id << "', ";
query << '\'' << item.group_id << "', ";
query << '\'' << item.privileges << "', ";
@@ -431,6 +431,7 @@ Error Db::AddItemIntoItem(Item & item)
query << '\'' << item.content_id << "', ";
query << '\'' << item.default_item << "', ";
query << '\'' << Escape(item.subject) << "', ";
query << '\'' << Escape(item.guest_name) << "', ";
url_without_id = AddItemCreateUrlSubject(item);
@@ -522,7 +523,7 @@ Error Db::EditItemInItem(Item & item, bool with_url)
{
AssertConnection();
std::ostringstream query;
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject";
query << "update core.item set (user_id, group_id, privileges, date_creation, date_modification, type, default_item, parent_id, subject, guest_name";
if( with_url )
query << ", url";
@@ -536,7 +537,8 @@ Error Db::EditItemInItem(Item & item, bool with_url)
query << '\'' << static_cast<int>(item.type) << "', ";
query << '\'' << item.default_item << "', ";
query << '\'' << item.parent_id << "', ";
query << '\'' << Escape(item.subject) << "' ";
query << '\'' << Escape(item.subject) << "', ";
query << '\'' << Escape(item.guest_name) << "' ";
if( with_url )
{
@@ -749,7 +751,7 @@ return result;
PGresult * Db::GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
{
std::ostringstream query;
query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item";
query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item, guest_name";
if( type != Item::dir )
{
@@ -819,7 +821,7 @@ void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type typ
}
// !! ta chyba nie uzywana juz?
void Db::GetItem(std::vector<Item> & item_table, long id)
{
PGresult * r = 0;
@@ -957,7 +959,7 @@ bool result = false;
AssertConnection();
std::ostringstream query;
query << "select user_id, group_id, privileges, subject, content from core.item left join core.content on item.content_id = content.id where item.id='" << id << "';"; // !! tymczasowo odczytujemy z content i subject
query << "select user_id, group_id, privileges, subject, content, guest_name from core.item left join core.content on item.content_id = content.id where item.id='" << id << "';"; // !! tymczasowo odczytujemy z content i subject
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
@@ -993,10 +995,11 @@ Error Db::EditPrivById(Item & item, long id)
{
AssertConnection();
std::ostringstream query;
query << "update core.item set (user_id, group_id, privileges) = (";
query << "update core.item set (user_id, group_id, privileges, guest_name) = (";
query << '\'' << item.user_id << "', ";
query << '\'' << item.group_id << "', ";
query << '\'' << item.privileges << "' ";
query << '\'' << item.privileges << "', ";
query << '\'' << Escape(item.guest_name) << "' ";
query << ") where id='" << id << "';";
@@ -1449,7 +1452,7 @@ Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
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 "
query << "select thread.id, thread.parent_id, thread.dir_id, thread.closed, thread.items, thread.last_item, item.date_modification, item.user_id, item.guest_name "
"from core.thread left join core.item on thread.last_item = item.id "
"where thread.parent_id = '" << parent_id << "' order by date_modification asc;";
@@ -1467,6 +1470,9 @@ Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
int clast_item = AssertColumn(r, "last_item");
int cdate_modification = PQfnumber(r, "date_modification");
int cuser_id = PQfnumber(r, "user_id");
int cguest_name = PQfnumber(r, "guest_name");
for(int i=0 ; i<rows ; ++i)
{
@@ -1478,7 +1484,8 @@ Error Db::GetThreads(long parent_id, std::vector<Thread> & thread_tab)
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.last_item.guest_name = Db::AssertValue(r, i, cguest_name);
thread_tab.push_back(thread);
}
}
@@ -1554,3 +1561,73 @@ Error Db::EditThreadAddItem(long dir_id, long item_id)
return status;
}
Error Db::EditThreadRemoveItem(long dir_id)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query, query2;
long last_item_id = -1;
query << "select id from core.item where parent_id='" << dir_id << "' order by date_creation desc limit 1;";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
if( PQntuples(r) == 1 )
last_item_id = atol( AssertValue(r, 0, 0) );
ClearResult(r);
query2 << "update core.thread set (items, last_item) = (items-1,'" << last_item_id
<< "') where dir_id='" << dir_id << "';";
r = AssertQuery(query2.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}
Error Db::RemoveThread(long dir_id)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "delete from core.thread where dir_id='" << dir_id << "';";
const char * crows = PQcmdTuples(r);
if( crows )
log << log2 << "Db: deleted " << atol(crows) << " rows from core.thread" << logend;
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}