added: parameter 'l' to 'ls' function

added: Db::ItemQuery struct for querying items
changed: some refactoring (renamed some config variables)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@589 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2010-02-22 22:52:09 +00:00
parent 16e51cd4e5
commit 3702efc5be
29 changed files with 396 additions and 195 deletions

View File

@@ -421,7 +421,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, static_auth, default_item, subject, guest_name, url) values (";
"parent_id, content_id, auth, default_item, subject, guest_name, url) values (";
query << '\'' << item.user_id << "', ";
query << '\'' << item.group_id << "', ";
query << '\'' << item.privileges << "', ";
@@ -430,7 +430,7 @@ Error Db::AddItemIntoItem(Item & item)
query << '\'' << static_cast<int>(item.type) << "', ";
query << '\'' << item.parent_id << "', ";
query << '\'' << item.content_id << "', ";
query << '\'' << static_cast<int>(item.static_auth) << "', ";
query << '\'' << static_cast<int>(item.auth) << "', ";
query << '\'' << item.default_item << "', ";
query << '\'' << Escape(item.subject) << "', ";
query << '\'' << Escape(item.guest_name) << "', ";
@@ -527,7 +527,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, guest_name, static_auth";
"default_item, parent_id, subject, guest_name, auth";
if( with_url )
query << ", url";
@@ -543,7 +543,7 @@ Error Db::EditItemInItem(Item & item, bool with_url)
query << '\'' << item.parent_id << "', ";
query << '\'' << Escape(item.subject) << "', ";
query << '\'' << Escape(item.guest_name) << "', ";
query << '\'' << static_cast<int>(item.static_auth) << "' ";
query << '\'' << static_cast<int>(item.auth) << "' ";
if( with_url )
{
@@ -752,49 +752,56 @@ return result;
PGresult * Db::GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
PGresult * Db::GetItemsQuery(const ItemQuery & iq)
{
std::ostringstream query;
query << "select item.id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, "
"content_id, default_item, guest_name, static_auth";
query << "select item.id";
if( type != Item::dir )
{
if( with_subject )
query << ", subject";
if( with_content )
query << ", content, content_type";
}
if( iq.sel_parent_id ) query << " ,parent_id";
if( iq.sel_user_id ) query << " ,user_id";
if( iq.sel_group_id ) query << " ,group_id";
if( iq.sel_guest_name) query << " ,guest_name";
if( iq.sel_privileges ) query << " ,privileges";
if( iq.sel_date ) query << " ,date_creation, date_modification";
if( iq.sel_subject ) query << " ,subject";
if( iq.sel_content ) query << " ,content, content_type, content_id";
if( iq.sel_url ) query << " ,url";
if( iq.sel_type ) query << " ,type";
if( iq.sel_default_item ) query << " ,default_item";
if( iq.sel_auth ) query << " ,auth";
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 << "'";
if( iq.sel_content ) query << " left join core.content on item.content_id = content.id";
if( iq.where_id || iq.where_parent_id || iq.where_type || iq.where_auth )
{
query << " where ";
const char * add_and = " and ";
const char * if_and = "";
if( iq.where_id ) { query << if_and << "id='" << iq.id << "'" ; if_and = add_and; }
if( iq.where_parent_id ) { query << if_and << "parent_id='" << iq.parent_id << "'" ; if_and = add_and; }
if( iq.where_type ) { query << if_and << "type='" << static_cast<int>(iq.type) << "'" ; if_and = add_and; }
if( iq.where_auth ) { query << if_and << "auth='" << static_cast<int>(iq.auth) << "'" ; if_and = add_and; }
}
if( type == Item::dir )
query << " and type='0'";
if( type == Item::file )
query << " and type='1'";
query << " order by item.date_creation";
if( sort_asc )
query << " asc";
if( iq.sort_asc )
query << " asc;";
else
query << " desc";
query << " desc;";
query << ';';
return AssertQuery(query.str());
}
void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc)
void Db::GetItems(std::vector<Item> & item_table, const ItemQuery & item_query)
{
item_table.clear();
PGresult * r = 0;
@@ -805,7 +812,7 @@ void Db::GetItems(std::vector<Item> & item_table, long parent_id, Item::Type typ
{
AssertConnection();
r = GetItemsQuery(parent_id, type, with_subject, with_content, sort_asc);
r = GetItemsQuery(item_query);
AssertResultStatus(r, PGRES_TUPLES_OK);
Item item;