As posted earlier, 2 more listings, header for class and derived class. DBItem.h
#define DB_ERROR 1
#define DB_EXCEPTION 2
class DBItem;
typedef pair<string, string> ssPair;
typedef vector<DBItem*> DBIList;
struct DataStructure
{
map<string, _variant_t> mAttr;
map<string, BOOL> mAttrLoaded;
map<string, BOOL> mAttrModified;
map<string, string> mAttrFields;// field, attr name;
map<string, string> mLinks;// attr, link class
map<string, ssPair> mDeps; // depends
string sIdField;
string sTableName;
string sTittleAttr;
string sTreeLink;
};
class DBItem
{
public:
DBItem(int nId, _ConnectionPtr pConnectionGeneral = NULL);
virtual ~DBItem();
_variant_t GetAttr(string sAttr);
string GetName();
DBItem *GetObject(string sAttr);
DBIList *GetInstances();
virtual string GetClass();
protected:
DBItem *GetInstance(string sClassName, unsigned long nId);
DataStructure ds;
private:
_ConnectionPtr pConnDB;
_RecordsetPtr pRstDB;
int nIid;
stack<string> mMessages;
BOOL bNoLogging;
BOOL Load();
void FormLoadQuery(char **szQuery);
void FormGetIDsQuery(char **szQuery);
BOOL ExecuteQuery(string sQuery);
void AddMessage(int nMsgType, string sMessage);
string ToString(int nConvertable);
string ToString(long nConvertable);
};
DB_Obj1.cpp
#include "stdafx.h"
#include "DB_Obj1.h"
DB_Obj1::DB_Obj1(int nId, _ConnectionPtr pConnectionGeneral) : DBItem(nId, pConnectionGeneral)
{
_variant_t vtNull;
vtNull.vt = VT_NULL;
// Init attributes as NULL (the variant way)
ds.mAttr["Id"] = vtNull;
ds.mAttr["Name"] = vtNull;
ds.mAttr["State"] = vtNull;
// Set Table Field <=> Attribute correspondence
ds.mAttrFields["IdObj"] = "Id";
ds.mAttrFields["ObjName"] = "Name";
ds.mAttrFields["CurrentState"] = "State";
// Init attributes as not load and not modified
// TODO: Implement uses for this :D
ds.mAttrLoaded["Id"] =
ds.mAttrLoaded["Name"] =
ds.mAttrLoaded["State"] =
ds.mAttrModified["Id"] =
ds.mAttrModified["Name"] =
ds.mAttrModified["State"] = FALSE;
// Set internal links to other Item Types, as in attributes that represent another object, via an ID
ds.mLinks["State"] = "DB_StateObj";
// Set dependencies. What other object types link to me basicly. Should support dependency types
// and enforcing them on deletes, inserts
ds.mDeps["someone_depends_on_me_somehow"] = make_pair((string)"