added: mount points have parameters now

added: to the database: table 'thread'



git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@499 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2009-04-20 23:49:28 +00:00
parent e94ccc86f8
commit f46677dfc0
24 changed files with 787 additions and 366 deletions

View File

@@ -745,7 +745,7 @@ return result;
PGresult * Db::GetItemsQuery(Item & item_ref)
PGresult * Db::GetItemsQuery(Item & item_ref, bool 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 << "'";
@@ -756,14 +756,22 @@ PGresult * Db::GetItemsQuery(Item & item_ref)
if( !item_ref.url.empty() )
query << " and url='" << Escape(item_ref.url) << "'";
query << " order by item.date_modification";
if( asc )
query << " asc";
else
query << " desc";
query << ';';
return AssertQuery(query.str());
}
void Db::GetItems(std::vector<Item> & item_table, Item & item_ref)
void Db::GetItems(std::vector<Item> & item_table, Item & item_ref, bool asc)
{
item_table.clear();
PGresult * r = 0;
@@ -772,7 +780,7 @@ void Db::GetItems(std::vector<Item> & item_table, Item & item_ref)
{
AssertConnection();
r = GetItemsQuery(item_ref);
r = GetItemsQuery(item_ref, asc);
AssertResultStatus(r, PGRES_TUPLES_OK);
Item item;
@@ -1358,3 +1366,86 @@ return buffer;
Error Db::GetThreadByDirId(long dir_id, Thread & thread)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "select id, dir_id, subject, closed from core.thread where thread.dir_id = " << dir_id << ";";
r = AssertQuery( query.str() );
AssertResultStatus(r, PGRES_TUPLES_OK);
int rows = PQntuples(r);
if( rows > 1 )
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");
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;
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}
Error Db::AddThread(Thread & thread)
{
PGresult * r = 0;
Error status = Error::ok;
try
{
AssertConnection();
std::ostringstream query;
query << "insert into core.thread (dir_id, subject, closed) values (";
query << '\'' << thread.dir_id << "', ";
query << '\'' << Escape(thread.subject) << "', ";
query << '\'' << (thread.closed ? 1 : 0 ) << "'); ";
r = AssertQuery(query.str());
AssertResultStatus(r, PGRES_COMMAND_OK);
thread.id = AssertCurrval("core.thread_id_seq");
}
catch(const Error & e)
{
status = e;
}
ClearResult(r);
return status;
}