1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// gqbSchema.cpp - Schema object for GQB
//
//////////////////////////////////////////////////////////////////////////
// App headers
#include "pgAdmin3.h"
// wxWindows headers
#include <wx/wx.h>
// App headers
#include "gqb/gqbSchema.h"
#include "gqb/gqbObject.h"
#include "gqb/gqbTable.h"
#include "gqb/gqbBrowser.h"
gqbSchema::gqbSchema(gqbObject *parent, wxString name, pgConn *connection, OID oid)
: gqbObject(name, parent, connection, oid)
{
setType(GQB_SCHEMA);
}
// GQB-TODO: don't declare OID inside gqbBrowsear instead use the pgadmin one
void gqbSchema::createObjects(gqbBrowser *tablesBrowser, OID oidVal, wxTreeItemId parentNode, int tableImage, int viewImage, int xTableImage)
{
createTables(tablesBrowser, parentNode, oidVal, tableImage, viewImage, xTableImage);
}
void gqbSchema::createTables(gqbBrowser *tablesBrowser, wxTreeItemId parentNode, OID oidVal, int tableImage, int viewImage, int xTableImage)
{
wxString query;
// Get the child objects.
query = wxT("SELECT oid, relname, relkind\n")
wxT(" FROM pg_class\n")
wxT(" WHERE relkind IN ('r','v','x','m') AND relnamespace = ") + NumToStr(oidVal) + wxT(";");
pgSet *tables = conn->ExecuteSet(query);
wxTreeItemId parent;
if (tables)
{
while (!tables->Eof())
{
gqbTable *table = 0;
wxString tmpname = tables->GetVal(wxT("relname"));
wxString relkind = tables->GetVal(wxT("relkind"));
if (relkind == wxT("r")) // 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") || relkind == wxT("m"))
{
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, conn, GQB_TABLE, tables->GetOid(wxT("oid")));
parent = tablesBrowser->AppendItem(parentNode, tables->GetVal(wxT("relname")), xTableImage, xTableImage, table);
}
// Create columns inside this table.
if (table)
table->createObjects(tablesBrowser, conn, tables->GetOid(wxT("oid")), parent);
tables->MoveNext();
}
delete tables;
}
tablesBrowser->SortChildren(parentNode);
}
|