//Refresh GQB Tree if used
if(conn && !firstTime)
{
- wxString msg = _("Retrieving tables from database ") + wxString(conn->GetDbname());
- wxBusyInfo waiting(msg, this);
-
- // Give the UI a chance to redraw
- wxSafeYield();
- wxMilliSleep(100);
- wxSafeYield();
-
controller->getTablesBrowser()->refreshTables(conn);
controller->getView()->Refresh();
}
// Database related Stuffs.
// Create a server object and connect it.
- wxString msg= _("Retrieving tables from database ") + wxString(conn->GetDbname());
- wxBusyInfo waiting(msg, this);
-
- // Give the UI a chance to redraw
- wxSafeYield();
- wxMilliSleep(100);
- wxSafeYield();
-
controller->getTablesBrowser()->refreshTables(conn);
firstTime=false;
}
rootNode=(wxTreeItemId *)NULL;
// Create normal images list of browser
+ // Remember to update enum gqbImages in gqbBrowser.h if changing the images!!
imageList = new wxImageList(16, 16);
imageList->Add(wxIcon(database_sm_xpm));
imageList->Add(wxIcon(namespace_sm_xpm));
wxTreeItemId& gqbBrowser::createRoot(wxString &Name)
{
rootNode=this->AddRoot(Name,0,0);
- catalogsNode=this->AppendItem(rootNode, _("Catalogs"), 4, 4, NULL);
- schemasNode=this->AppendItem(rootNode, _("Schemas"), 3, 3, NULL);
+ catalogsNode=this->AppendItem(rootNode, _("Catalogs"), GQB_IMG_CATALOGS, GQB_IMG_CATALOGS, NULL);
+ schemasNode=this->AppendItem(rootNode, _("Schemas"), GQB_IMG_NAMESPACES, GQB_IMG_NAMESPACES, NULL);
return rootNode;
}
{
wxTreeItemId itemId = event.GetItem();
gqbObject *object = (gqbObject *) GetItemData(itemId);
- if(object!=NULL && (object->getType() == GQB_TABLE || object->getType() == GQB_VIEW))
+ if(object)
{
- gqbTable *item = (gqbTable *) object;
- controller->addTableToModel(item,wxPoint(10,10));
- controller->getView()->Refresh();
+ if (object->getType() == GQB_TABLE || object->getType() == GQB_VIEW)
+ {
+ gqbTable *item = (gqbTable *) object;
+ controller->addTableToModel(item,wxPoint(10,10));
+ controller->getView()->Refresh();
+ }
+ else if (GetChildrenCount(itemId) == 0 && object->getType() == GQB_SCHEMA)
+ {
+ gqbSchema *schema = (gqbSchema *)object;
+ schema->createObjects(this, schema->getOid(), itemId, GQB_IMG_TABLE, GQB_IMG_VIEW, GQB_IMG_EXTTABLE);
+ }
}
+
}
-
void gqbBrowser::refreshTables(pgConn *connection)
{
controller->emptyModel();
- this->DeleteAllItems(); // GQB-TODO: same as destructor
- wxString a = wxString(wxT("Database Name Here"));
- gqbDatabase *Data = new gqbDatabase(a, GQB_DATABASE);
- Data->createObjects(this,connection);
+ this->DeleteAllItems();
+ gqbDatabase *Data = new gqbDatabase(wxEmptyString, connection);
+ Data->createObjects(this);
this->Expand(rootNode);
}
#include "gqb/gqbTable.h"
#include "gqb/gqbArrayCollection.h"
-gqbColumn::gqbColumn(gqbObject *parent, wxString name, type_gqbObject type=GQB_COLUMN):
-gqbObject(name, type)
+gqbColumn::gqbColumn(gqbObject *parent, wxString name, pgConn *connection):
+gqbObject(name, parent, connection)
{
- this->setType(GQB_COLUMN);
- this->setName(name);
- this->setOwner(parent);
+ setType(GQB_COLUMN);
}
wxWindowID CTL_NTBKPANELS = ::wxNewId();
-gqbController::gqbController(gqbModel *_model, wxWindow *gqbParent, wxNotebook *gridParent, wxSize size=wxSize(800,1280)):
-wxObject()
+gqbController::gqbController(gqbModel *_model, wxWindow *gqbParent, wxNotebook *gridParent, wxSize size=wxSize(800,1280))
+: wxObject()
{
pparent = gqbParent;
model=_model;
while(iteratorModel->HasNext())
{
sel=(gqbQueryObject *)iteratorModel->Next();
- gqbSchema *schema = (gqbSchema *)&sel->parent->getOwner();
+ gqbSchema *schema = (gqbSchema *)sel->parent->getOwner();
if(sel->getAlias().length()>0)
{
sentence += wxT(" ") +
#include "gqb/gqbSchema.h"
#include "schema/pgSchema.h"
-gqbDatabase::gqbDatabase(wxString name, type_gqbObject type=GQB_DATABASE):
-gqbObject(name,type)
+gqbDatabase::gqbDatabase(wxString name, pgConn *connection)
+: gqbObject(name, NULL, connection)
{
- this->setType(GQB_DATABASE);
- this->setName(name);
- this->setOwner(NULL);
- conn=NULL;
+ setType(GQB_DATABASE);
}
-void gqbDatabase::createObjects(gqbBrowser *_tablesBrowser, pgConn *_conn)
+void gqbDatabase::createObjects(gqbBrowser *_tablesBrowser)
{
- wxString rootNodeString = wxString(_conn->GetDbname());
+ wxString rootNodeString = wxString(conn->GetDbname());
// Create Root Node
_tablesBrowser->createRoot(rootNodeString);
// FillBrowser
- createSchemas(_conn,_tablesBrowser,_tablesBrowser->getCatalogRootNode(),GQB_CATALOG,5);
- createSchemas(_conn,_tablesBrowser,_tablesBrowser->getTablesRootNode(),GQB_OTHER,1);
+ createSchemas(_tablesBrowser, _tablesBrowser->getCatalogRootNode(), GQB_CATALOG, GQB_IMG_CATALOG);
+ createSchemas(_tablesBrowser, _tablesBrowser->getTablesRootNode(), GQB_OTHER, GQB_IMG_NAMESPACE);
}
// Use database connection to create all objects inside tree
-void gqbDatabase::createSchemas(pgConn *conn, gqbBrowser *tablesBrowser, wxTreeItemId parentNode,typeSchema MetaType, int indexImage)
+void gqbDatabase::createSchemas(gqbBrowser *tablesBrowser, wxTreeItemId parentNode,typeSchema MetaType, int indexImage)
{
// Search Schemas and insert it
continue;
}
- int tableImage = 2, viewImage = 7;
+ int tableImage = GQB_IMG_TABLE, viewImage = GQB_IMG_VIEW;
gqbSchema *schema;
if (MetaType == GQB_CATALOG)
{
// Create Schema Object
- schema = new gqbSchema(this, name, GQB_SCHEMA);
- parent=tablesBrowser->AppendItem(parentNode, name , indexImage, indexImage, schema);
+ schema = new gqbSchema(this, name, conn, schemas->GetOid(wxT("oid")));
+ parent=tablesBrowser->AppendItem(parentNode, name, indexImage, indexImage, schema);
if(name != wxT("pg_catalog") && name != wxT("pgagent"))
{
- tableImage=5;
- viewImage=5;
+ tableImage=GQB_IMG_CATALOG_OBJ;
+ viewImage=GQB_IMG_CATALOG_OBJ;
}
}
else
{
// Create Schema Object
- schema = new gqbSchema(this, name, GQB_SCHEMA);
+ // Note that the schema will be populated when the node is expanded.
+ schema = new gqbSchema(this, name, conn, schemas->GetOid(wxT("oid")));
parent=tablesBrowser->AppendItem(parentNode, name , indexImage, indexImage, schema);
}
- schema->createObjects(tablesBrowser, conn, schemas->GetOid(wxT("oid")), parent, tableImage, viewImage, 8);
schemas->MoveNext();
}
// App headers
#include "gqb/gqbObject.h"
-gqbObject::gqbObject(wxString name, type_gqbObject type)
+gqbObject::gqbObject(wxString name, wxTreeItemData *owner, pgConn *connection, OID oid)
{
- this->Type=type;
- this->Name=name;
+ Name = name;
+ Owner = owner;
+ conn = connection;
+ Oid = oid;
}
gqbObject::~gqbObject()
{
}
-
-
-void gqbObject::setName(wxString name)
-{
- this->Name=name;
-}
-
-
-const wxString& gqbObject::getName()
-{
- return Name;
-}
-
-
-void gqbObject::setOwner(wxTreeItemData *owner)
-{
- this->Owner=owner;
-}
-
-
-const wxTreeItemData& gqbObject::getOwner()
-{
- return (*Owner);
-}
-
-
-void gqbObject::setType(type_gqbObject tname)
-{
- this->Type=tname;
-}
-
-
-const type_gqbObject gqbObject::getType()
-{
- return this->Type;
-}
#include "gqb/gqbCollection.h"
#include "gqb/gqbArrayCollection.h"
-gqbObjectCollection::gqbObjectCollection(wxString name, type_gqbObject type):
-gqbObject(name, type)
+gqbObjectCollection::gqbObjectCollection(wxString name, wxTreeItemData *owner, pgConn *connection, OID oid)
+: gqbObject(name, owner, connection, oid)
{
// Create the concrete implementation of the Collection, right now only one implementation not need parameter
implementation = new gqbArrayCollection();
// Create the collection using the concrete implementation
// use the array implementation of the collection
objectsCollection = new gqbCollection(implementation);
- this->setOwner(NULL);
}
#include "gqb/gqbObjectCollection.h"
#include "gqb/gqbViewPanels.h"
-const wxString wxEmptyStr = wxEmptyString;
-
//
// Collections of Tables inside a Query, data structured used for query storage & later generation of SQL sentence
//
-gqbQueryObjs::gqbQueryObjs():
-gqbObjectCollection(wxT(""),GQB_QUERY)
+gqbQueryObjs::gqbQueryObjs()
+: gqbObjectCollection(wxT(""), NULL, NULL)
{
- this->setOwner(NULL);
+ setType(GQB_QUERY);
}
// Because this we can not use directly the base table object
gqbQueryObject::gqbQueryObject(gqbTable *table)
-:gqbObjectCollection(table->getName(), GQB_QUERYOBJ)
+: gqbObjectCollection(table->getName(), table, table->getConnection())
{
selected=false;
- parent=table;
+ parent = table;
//GQB-TODO: Calculate a good initial position
position.x=20;
haveRegisteredJoins=false;
registeredCollection=NULL;
joinsCollection=NULL;
+ setType(GQB_QUERYOBJ);
}
//
// A Join inside a query Object like Table or view [Stored at source, registered at destination]
// I need to store the owner, destination because columns it's share between multiple joins
-gqbQueryJoin::gqbQueryJoin(gqbQueryObject *_owner, gqbQueryObject *_destination, gqbColumn *sourceCol, gqbColumn *destCol, type_Join joinKind):
-gqbObject(wxT(""),GQB_JOIN)
+gqbQueryJoin::gqbQueryJoin(gqbQueryObject *_owner, gqbQueryObject *_destination, gqbColumn *sourceCol, gqbColumn *destCol, type_Join joinKind)
+: gqbObject(wxT(""), _owner, NULL)
{
kindofJoin=joinKind;
sCol=sourceCol;
owner=_owner;
selected=false;
destination=_destination;
+ setType(GQB_JOIN);
}
}
-const wxString& gqbQueryJoin::getSourceTable()
+wxString gqbQueryJoin::getSourceTable()
{
if (!owner)
- return wxEmptyStr;
- gqbTable *s=(gqbTable*)&sCol->getOwner();
+ return wxEmptyString;
+
+ gqbTable *s=(gqbTable*)sCol->getOwner();
return s->getName();
}
-const wxString& gqbQueryJoin::getDestTable()
+wxString gqbQueryJoin::getDestTable()
{
if (!destination)
- return wxEmptyStr;
- gqbTable *d=(gqbTable*)&dCol->getOwner();
+ return wxEmptyString;
+
+ gqbTable *d=(gqbTable*)dCol->getOwner();
return d->getName();
}
-const wxString& gqbQueryJoin::getSourceCol()
+wxString gqbQueryJoin::getSourceCol()
{
if (!sCol)
- return wxEmptyStr;
+ return wxEmptyString;
+
return sCol->getName();
}
-const wxString& gqbQueryJoin::getDestCol()
+wxString gqbQueryJoin::getDestCol()
{
if (!dCol)
- return wxEmptyStr;
+ return wxEmptyString;
+
return dCol->getName();
}
QRtype
};
-gqbQueryRestriction::gqbQueryRestriction():
-gqbObject(wxT(""),GQB_RESTRICTION)
+gqbQueryRestriction::gqbQueryRestriction()
+: gqbObject(wxT(""), NULL, NULL)
{
leftPart=wxT("");
value_s=wxT("");
connector=wxT("AND");
restriction=wxT("=");
+ setType(GQB_RESTRICTION);
}
-gqbRestrictions::gqbRestrictions():
-gqbObjectCollection(wxT(""),GQB_RESTRICTION)
+gqbRestrictions::gqbRestrictions()
+: gqbObjectCollection(wxT(""), NULL, NULL)
{
- this->setOwner(NULL);
+ setType(GQB_RESTRICTION);
}
#include "gqb/gqbTable.h"
#include "gqb/gqbBrowser.h"
-gqbSchema::gqbSchema(gqbObject *parent, wxString name, type_gqbObject type=GQB_SCHEMA):
-gqbObject(name,type)
+gqbSchema::gqbSchema(gqbObject *parent, wxString name, pgConn *connection, OID oid)
+: gqbObject(name, parent, connection, oid)
{
- this->setType(GQB_SCHEMA);
- this->setName(name);
- this->setOwner(parent);
+ setType(GQB_SCHEMA);
}
// GQB-TODO: don't declare OID inside gqbBrowsear instead use the pgadmin one
-void gqbSchema::createObjects(gqbBrowser *tablesBrowser, pgConn *conn, OID oidVal, wxTreeItemId parentNode, int tableImage, int viewImage, int xTableImage)
+void gqbSchema::createObjects(gqbBrowser *tablesBrowser, OID oidVal, wxTreeItemId parentNode, int tableImage, int viewImage, int xTableImage)
{
- createTables(conn, tablesBrowser, parentNode, oidVal, tableImage, viewImage, xTableImage);
+ createTables(tablesBrowser, parentNode, oidVal, tableImage, viewImage, xTableImage);
}
-
-wxString gqbSchema::NumToStr(OID value)
-{
- wxString result;
- result.Printf(wxT("%lu"), (long)value);
- return result;
-}
-
-
-void gqbSchema::createTables(pgConn *conn, gqbBrowser *tablesBrowser, wxTreeItemId parentNode, OID oidVal, int tableImage, int viewImage, int xTableImage)
+void gqbSchema::createTables(gqbBrowser *tablesBrowser, wxTreeItemId parentNode, OID oidVal, int tableImage, int viewImage, int xTableImage)
{
wxString query;
if (relkind == wxT("r")) // Table
{
- table = new gqbTable(this, tmpname, GQB_TABLE);
+ table = new gqbTable(this, tmpname, conn, GQB_TABLE, tables->GetOid(wxT("oid")));
parent=tablesBrowser->AppendItem(parentNode, tables->GetVal(wxT("relname")) , tableImage, tableImage, table);
}
else if (relkind == wxT("v"))
{
- table = new gqbTable(this, tmpname, GQB_VIEW);
+ table = new gqbTable(this, tmpname, conn, GQB_VIEW, tables->GetOid(wxT("oid")));
parent=tablesBrowser->AppendItem(parentNode, tables->GetVal(wxT("relname")) , viewImage, viewImage, table);
}
else if (relkind == wxT("x")) // Greenplum external table
{
- table = new gqbTable(this, tmpname, GQB_TABLE);
- parent=tablesBrowser->AppendItem(parentNode, tables->GetVal(wxT("relname")) , xTableImage, xTableImage, table);
+ table = new gqbTable(this, tmpname, conn, GQB_TABLE, tables->GetOid(wxT("oid")));
+ parent=tablesBrowser->AppendItem(parentNode, tables->GetVal(wxT("relname")), xTableImage, xTableImage, table);
}
// Create columns inside this table.
#include "gqb/gqbColumn.h"
#include "gqb/gqbArrayCollection.h"
-gqbTable::gqbTable(gqbObject *parent, wxString name, type_gqbObject type=GQB_TABLE):
-gqbObjectCollection(name,type)
+gqbTable::gqbTable(gqbObject *parent, wxString name, pgConn *connection, type_gqbObject type, OID oid)
+: gqbObjectCollection(name, parent, connection, oid)
{
- this->setType(type);
- this->setName(name);
- this->setOwner(parent);
+ setType(type);
}
createColumns(_conn, _tablesBrowser, parentNode, oidVal);
}
-
-wxString gqbTable::NumToStr(OID value)
-{
- wxString result;
- result.Printf(wxT("%lu"), (long)value);
- return result;
-}
-
-
void gqbTable::createColumns(pgConn *conn, gqbBrowser *tablesBrowser, wxTreeItemId parentNode, OID oidVal)
{
{
//Disable, Column SHOULDN'T be added to tree only use for debug purposes tablesBrowser->AppendItem(parentNode, columns->GetVal(wxT("attname")) , -1, -1);
wxString tmpname = wxString(columns->GetVal(wxT("attname")));
- gqbColumn *column = new gqbColumn(this,tmpname,GQB_COLUMN);
+ gqbColumn *column = new gqbColumn(this, tmpname, conn);
this->addColumn(column);
columns->MoveNext();
}
#ifndef GQBBROWSER_H
#define GQBBROWSER_H
-// typedef unsigned long OID;
+enum gqbImages
+{
+ GQB_IMG_DATABASE = 0,
+ GQB_IMG_NAMESPACE = 1,
+ GQB_IMG_TABLE = 2,
+ GQB_IMG_NAMESPACES = 3,
+ GQB_IMG_CATALOGS = 4,
+ GQB_IMG_CATALOG = 5,
+ GQB_IMG_CATALOG_OBJ = 6,
+ GQB_IMG_VIEW = 7,
+ GQB_IMG_EXTTABLE = 8
+};
class gqbController;
class gqbColumn : public gqbObject
{
public:
- gqbColumn(gqbObject *parent, wxString name, type_gqbObject type);
+ gqbColumn(gqbObject *parent, wxString name, pgConn *connection);
};
#endif
class gqbDatabase : public gqbObject
{
public:
- gqbDatabase(wxString name, type_gqbObject type);
- void createObjects(gqbBrowser *_tablesBrowser, pgConn *_conn);
+ gqbDatabase(wxString name, pgConn *connection);
+ void createObjects(gqbBrowser *_tablesBrowser);
private:
- pgConn *conn;
enum typeSchema
{
GQB_CATALOG,
GQB_OTHER
};
- void createSchemas(pgConn *conn, gqbBrowser *tablesBrowser, wxTreeItemId parentNode,typeSchema MetaType, int indexImage);
+ void createSchemas(gqbBrowser *tablesBrowser, wxTreeItemId parentNode,typeSchema MetaType, int indexImage);
};
#endif
class gqbObject : public wxTreeItemData
{
public:
- gqbObject(wxString name, type_gqbObject type);
+ gqbObject(wxString name, wxTreeItemData *owner, pgConn *connection, OID oid = 0);
virtual ~gqbObject();
- void setName(wxString name);
- const wxString& getName();
- void setOwner(wxTreeItemData *owner);
- const wxTreeItemData& getOwner();
- void setType(type_gqbObject name);
- const type_gqbObject getType();
+ const wxString& getName() { return Name; }
+ wxTreeItemData *getOwner() { return Owner; }
+ const type_gqbObject getType() { return Type; }
+ void setType(const type_gqbObject type) { Type = type; }
+ pgConn *getConnection() { return conn; }
+ OID getOid() { return Oid; }
+
+protected:
+ pgConn *conn;
private:
wxString Name;
wxTreeItemData *Owner;
type_gqbObject Type;
+ OID Oid;
};
#endif
class gqbObjectCollection : public gqbObject
{
public:
- gqbObjectCollection(wxString name, type_gqbObject type);
+ gqbObjectCollection(wxString name, wxTreeItemData *owner, pgConn *connection, OID oid = 0);
virtual ~gqbObjectCollection();
protected:
gqbQueryObject* getDestQTable();
gqbColumn* getDCol();
gqbColumn* getSCol();
- const wxString& getSourceTable();
- const wxString& getDestTable();
- const wxString& getSourceCol();
- const wxString& getDestCol();
+ wxString getSourceTable();
+ wxString getDestTable();
+ wxString getSourceCol();
+ wxString getDestCol();
void setSourceAnchor(wxPoint pt);
void setDestAnchor(wxPoint pt);
wxPoint& getSourceAnchor();
class gqbSchema : public gqbObject
{
public:
- gqbSchema(gqbObject *parent, wxString name, type_gqbObject type);
- void createObjects(gqbBrowser *tablesBrowser, pgConn *conn, OID oidVal, wxTreeItemId parentNode, int tableImage, int viewImage, int xTableImage);
+ gqbSchema(gqbObject *parent, wxString name, pgConn *connection, OID oid);
+ void createObjects(gqbBrowser *tablesBrowser, OID oidVal, wxTreeItemId parentNode, int tableImage, int viewImage, int xTableImage);
private:
- pgConn *conn;
- wxString NumToStr(OID value);
- void createTables(pgConn *conn, gqbBrowser *tablesBrowser, wxTreeItemId parentNode, OID oidVal, int tableImage, int viewImage, int xTableImage);
+ void createTables(gqbBrowser *tablesBrowser, wxTreeItemId parentNode, OID oidVal, int tableImage, int viewImage, int xTableImage);
};
#endif
class gqbTable : public gqbObjectCollection
{
public:
- gqbTable(gqbObject *parent, wxString name, type_gqbObject type);
+ gqbTable(gqbObject *parent, wxString name, pgConn *connection, type_gqbObject type, OID oid);
void createObjects(gqbBrowser *_tablesBrowser, pgConn *_conn, OID oidVal, wxTreeItemId parentNode);
gqbIteratorBase* createColumnsIterator();
int countCols();
int indexColumn(gqbColumn *col);
private:
- wxString NumToStr(OID value);
void addColumn(gqbColumn *column); // Used only as synonym for gqbObjectCollection addObject
void createColumns(pgConn *conn, gqbBrowser *tablesBrowser, wxTreeItemId parentNode, OID oidVal);