changed: db: table item: url_subject into url
changed: item.url_subject into item.url changed: a new table: content with: id, subject, content, content_type (those from the item table) it helps to create hard links git-svn-id: svn://ttmath.org/publicrep/cmslu/trunk@466 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
122
core/db.h
122
core/db.h
@@ -29,84 +29,64 @@
|
||||
|
||||
class Db
|
||||
{
|
||||
public:
|
||||
|
||||
Db();
|
||||
~Db();
|
||||
|
||||
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 EditItem(Item & item, bool with_subject = true);
|
||||
void CheckAllUrlSubject();
|
||||
void GetItems(std::vector<Item> & item_table, Item & item_ref);
|
||||
void GetItem(std::vector<Item> & item_table, long id);
|
||||
bool DelItem(const Item & item);
|
||||
void GetDirs(DirContainer & dir_table);
|
||||
|
||||
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
PGconn * pg_conn;
|
||||
|
||||
std::string db_database, db_user, db_pass;
|
||||
|
||||
public:
|
||||
|
||||
Db();
|
||||
~Db();
|
||||
|
||||
void Init(const std::string & database, const std::string & user, const std::string & pass);
|
||||
void Connect();
|
||||
|
||||
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);
|
||||
|
||||
bool CheckUser(std::string & login, std::string & password, long & user_id);
|
||||
|
||||
long AssertCurrval(const char * table);
|
||||
|
||||
|
||||
bool AddItemCreateUrlSubject(Item & item);
|
||||
Error AddItem(Item & item);
|
||||
Error EditItem(Item & item, bool with_subject = true);
|
||||
|
||||
void CheckAllUrlSubjectModifyItem(Item & item);
|
||||
void CheckAllUrlSubject();
|
||||
|
||||
PGresult * GetItemsQuery(Item & item_ref);
|
||||
void GetItems(std::vector<Item> & item_table, Item & item_ref);
|
||||
void GetItem(std::vector<Item> & item_table, long id);
|
||||
|
||||
bool DelItem(long id);
|
||||
|
||||
void GetDirs(DirContainer & dir_table);
|
||||
|
||||
|
||||
|
||||
struct ItemColumns
|
||||
{
|
||||
int id, subject, content, url_subject, type, parent_id, default_item;
|
||||
|
||||
void SetColumns(PGresult * r)
|
||||
{
|
||||
id = Db::AssertColumn(r, "id");
|
||||
subject = Db::AssertColumn(r, "subject");
|
||||
content = Db::AssertColumn(r, "content");
|
||||
url_subject = Db::AssertColumn(r, "url_subject");
|
||||
type = Db::AssertColumn(r, "type");
|
||||
parent_id = Db::AssertColumn(r, "parent_id");
|
||||
default_item = Db::AssertColumn(r, "default_item");
|
||||
}
|
||||
|
||||
|
||||
void SetItem(PGresult * r, long row, Item & item)
|
||||
{
|
||||
item.id = atol( Db::AssertValue(r, row, id) );
|
||||
item.subject = Db::AssertValue(r, row, subject);
|
||||
item.content = Db::AssertValue(r, row, content);
|
||||
item.url_subject = Db::AssertValue(r, row, url_subject);
|
||||
item.type = static_cast<Item::Type>( atoi( Db::AssertValue(r, row, type) ) );
|
||||
item.parent_id = atol( Db::AssertValue(r, row, parent_id) );
|
||||
item.default_item = atol( Db::AssertValue(r, row, default_item) );
|
||||
}
|
||||
void Connect();
|
||||
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_subject);
|
||||
Error EditItemInContent(Item & item);
|
||||
|
||||
void CheckAllUrlSubjectModifyItem(Item & item);
|
||||
|
||||
PGresult * GetItemsQuery(Item & item_ref);
|
||||
|
||||
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, url, type, parent_id, content_id, default_item, subject, content, content_type;
|
||||
|
||||
void SetColumns(PGresult * r);
|
||||
void SetItem(PGresult * r, long row, Item & item);
|
||||
};
|
||||
|
||||
|
||||
}; // class Db
|
||||
|
Reference in New Issue
Block a user