winix/plugins/thread/tdb.h

87 lines
1.9 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfile_winix_plugins_thread_tdb
#define headerfile_winix_plugins_thread_tdb
#include <vector>
#include "thread.h"
#include "db/dbbase.h"
#include "core/error.h"
namespace Thread
{
class TDb : public DbBase
{
public:
/*
high level interface
*/
Error AddThread(const Thread & thread);
Error GetThread(long file_id, Thread & thread);
Error GetThreads(const std::vector<long> & file_id_tab, std::vector<Thread> & thread_tab);
Error RemoveThread(long file_id);
Error AddAnswer(long file_id, long answer_id);
Error GetAnswers(long file_id, std::vector<long> & answer_id_tab);
Error RemoveAnswer(long answer_id);
/*
low level interface
*/
// looking for the last answer in a thread (in 'thread_files' table)
// this is not the value from 'thread' table
long FindLastAnswer(long file_id);
// returning all threads id (file_id) (from 'thread' table)
void GetAllThreadsId(std::vector<long> & file_id);
// removing only the answer in 'thread_files' table without updating 'thread' table
Error RemoveAnswerOnly(long answer_id);
// returning how many answers there are
// calculating from 'thread_files' table
// this is not the value from 'thread' table
long CalcAnswers(long file_id);
// recalculating last_item, replies in 'thread' table on a given thread
Error RecalcThread(long file_id);
private:
DbTextStream query;
std::wstring list_id;
int cfile_id, creplies, cclosed, clast_item, cdate_modification, cuser_id, cguest;
Thread thread_temp;
std::vector<long> file_id_tab;
void SetThreadColumns(PGresult * r);
void SetThread(PGresult * r, int col, Thread & thread);
Error RemoveAnswerRecalcLast(long file_id);
Error RemoveAnswerRecalcLast(const std::vector<long> & file_id_tab);
};
} // namespace
#endif