File: gqbTable.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (102 lines) | stat: -rw-r--r-- 2,383 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// gqbTable.cpp - Table object for GQB
//
//////////////////////////////////////////////////////////////////////////

// App headers
#include "pgAdmin3.h"

// wxWindows headers
#include <wx/wx.h>

// App headers
#include "gqb/gqbObject.h"
#include "gqb/gqbTable.h"
#include "gqb/gqbColumn.h"
#include "gqb/gqbArrayCollection.h"

gqbTable::gqbTable(gqbObject *parent, wxString name, pgConn *connection, type_gqbObject type, OID oid)
	: gqbObjectCollection(name, parent, connection, oid)
{
	setType(type);
}


gqbIteratorBase *gqbTable::createColumnsIterator()
{
	return createIterator();
}


void gqbTable::addColumn(gqbColumn *column)
{
	this->addObject(column);
}


void gqbTable::createObjects(gqbBrowser *_tablesBrowser,  pgConn *_conn, OID oidVal,  wxTreeItemId parentNode)
{
	createColumns(_conn, _tablesBrowser, parentNode, oidVal);
}

void gqbTable::createColumns(pgConn *conn, gqbBrowser *tablesBrowser, wxTreeItemId parentNode,  OID oidVal)
{

	wxString systemRestriction;
	if (!settings->GetShowSystemObjects())
		systemRestriction = wxT("\n   AND attnum > 0");

	wxString sql =
	    wxT("SELECT attname FROM pg_attribute att\n")
	    wxT(" WHERE attrelid = ")
	    + NumToStr(oidVal)
	    + systemRestriction + wxT("\n")
	    wxT("   AND attisdropped IS FALSE\n")
	    wxT(" ORDER BY attnum");

	pgSet *columns = conn->ExecuteSet(sql);
	if (columns)
	{
		while (!columns->Eof())
		{
			if (tablesBrowser)
			{
				//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, conn);
				this->addColumn(column);
				columns->MoveNext();
			}
			else
				break;
		}

		delete columns;
	}
}


//work as a synonym for function
int gqbTable::countCols()
{
	return this->countObjects();
}


//work as a synonym for function & return correct type
gqbColumn *gqbTable::getColumnAtIndex(int index)
{
	return (gqbColumn *)this->getObjectAtIndex(index);
}


int gqbTable::indexColumn(gqbColumn *col)
{
	return this->indexObject(col);
}