148 lines
3.8 KiB
C++
Executable File
148 lines
3.8 KiB
C++
Executable File
/*
|
|
* This file is a part of CMSLU -- Content Management System like Unix
|
|
* and is not publicly distributed
|
|
*
|
|
* Copyright (c) 2008-2009, Tomasz Sowa
|
|
* All rights reserved.
|
|
*
|
|
*/
|
|
|
|
#ifndef headerfilecmslucoredb
|
|
#define headerfilecmslucoredb
|
|
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
#include <map>
|
|
#include <sstream>
|
|
#include <libpq-fe.h>
|
|
#include <cstdio>
|
|
#include <ctime>
|
|
#include <cstring>
|
|
|
|
#include "item.h"
|
|
#include "user.h"
|
|
#include "group.h"
|
|
#include "thread.h"
|
|
#include "error.h"
|
|
#include "dircontainer.h"
|
|
#include "ugcontainer.h"
|
|
|
|
|
|
|
|
class Db
|
|
{
|
|
public:
|
|
|
|
Db(bool close_at_end_ = true);
|
|
~Db();
|
|
|
|
// !! przerobic tak aby GetItem zwracalo wszystkie pozycja
|
|
// !! GetFile tylko dla plikow
|
|
// !! GetDir tylko dla katalogow
|
|
// !! GetFile i GetDir beda uzywac GetItem
|
|
|
|
void Init(const std::string & database, const std::string & user, const std::string & pass);
|
|
bool CheckUser(std::string & login, std::string & password, long & user_id);
|
|
Error AddItem(Item & item);
|
|
Error EditItemById(Item & item, bool with_url = true);
|
|
Error EditItemByUrl(Item & item, bool with_url = true);
|
|
void CheckAllUrlSubject();
|
|
|
|
void GetItems(std::vector<Item> & item_table, long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc);
|
|
|
|
void GetItem(std::vector<Item> & item_table, long id);
|
|
|
|
|
|
bool GetPriv(Item & item, long id);
|
|
Error EditPrivById(Item & item, long id);
|
|
|
|
Error DelDirById(long id);
|
|
|
|
bool DelItem(const Item & item);
|
|
void GetDirs(DirContainer & dir_table);
|
|
void GetUsers(UGContainer<User> & user_table);
|
|
void GetGroups(UGContainer<Group> & group_table);
|
|
|
|
// !! nowy interfejs
|
|
long Size(long parent_id, Item::Type type = Item::none);
|
|
|
|
Error GetItem(long parent_id, const std::string & url, Item & item);
|
|
Error EditDefaultItem(long id, long new_default_item);
|
|
|
|
long GetItemId(long parent_id, const std::string & url, Item::Type type);
|
|
long GetFileId(long parent_id, const std::string & url);
|
|
long GetDirId(long parent_id, const std::string & url);
|
|
|
|
static tm ConvertTime(const char * str);
|
|
static const char * ConvertTime(const tm & t);
|
|
|
|
PGconn * GetPGconn();
|
|
|
|
virtual void Connect();
|
|
|
|
|
|
Error AddThread(Thread & thread);
|
|
Error GetThreadByDirId(long dir_id, Thread & thread);
|
|
Error GetThreads(long parent_id, std::vector<Thread> & thread_tab);
|
|
Error EditThreadAddItem(long dir_id, long item_id);
|
|
Error EditThreadRemoveItem(long dir_id);
|
|
Error RemoveThread(long dir_id);
|
|
|
|
protected:
|
|
|
|
PGconn * pg_conn;
|
|
std::string db_database, db_user, db_pass;
|
|
bool close_at_end;
|
|
|
|
void SetDbParameters();
|
|
|
|
void Close();
|
|
|
|
void AssertConnection();
|
|
std::string Escape(const std::string & s);
|
|
std::string Escape(const char * s);
|
|
PGresult * AssertQuery(const std::string & q);
|
|
void AssertResultStatus(PGresult * r, ExecStatusType t);
|
|
static int AssertColumn(PGresult * r, const char * column_name);
|
|
static const char * AssertValue(PGresult * r, int row, int col);
|
|
void ClearResult(PGresult * r);
|
|
long AssertCurrval(const char * table);
|
|
bool AddItemCreateUrlSubject(Item & item);
|
|
|
|
Error AddItemIntoContent(Item & item);
|
|
Error AddItemIntoItem(Item & item);
|
|
|
|
Error EditItemInItem(Item & item, bool with_url);
|
|
Error EditItemInContent(Item & item);
|
|
Error EditItemGetId(Item & item);
|
|
Error EditItemGetContentId(Item & item);
|
|
|
|
void CheckAllUrlSubjectModifyItem(Item & item);
|
|
|
|
PGresult * GetItemsQuery(long parent_id, Item::Type type, bool with_subject, bool with_content, bool sort_asc);
|
|
|
|
bool DelItemDelItem(const Item & item);
|
|
void DelItemDelContent(const Item & item);
|
|
Error DelItemCountContents(const Item & item, long & contents);
|
|
|
|
|
|
struct ItemColumns
|
|
{
|
|
int id, user_id, group_id, privileges, date_creation, date_modification, url, type, parent_id, content_id, default_item, subject, content, content_type, guest_name;
|
|
|
|
|
|
void SetColumns(PGresult * r);
|
|
void SetItem(PGresult * r, long row, Item & item);
|
|
};
|
|
|
|
|
|
}; // class Db
|
|
|
|
|
|
extern Db db;
|
|
|
|
|
|
#endif
|
|
|