File: dlgRepPath.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 (154 lines) | stat: -rw-r--r-- 4,256 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// dlgRepPath.cpp - PostgreSQL Slony-I Path Property
//
//////////////////////////////////////////////////////////////////////////

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

// App headers
#include "pgAdmin3.h"

#include "slony/dlgRepPath.h"
#include "slony/slCluster.h"
#include "slony/slNode.h"
#include "slony/slPath.h"
#include "schema/pgDatatype.h"


// pointer to controls
#define cbServer      CTRL_COMBOBOX("cbServer")
#define txtConnInfo     CTRL_TEXT("txtConnInfo")
#define txtConnRetry    CTRL_TEXT("txtConnRetry")


BEGIN_EVENT_TABLE(dlgRepPath, dlgProperty)
	EVT_TEXT(XRCID("txtConnInfo"),          dlgRepPath::OnChange)
	EVT_COMBOBOX(XRCID("cbServer"),       dlgRepPath::OnChange)
END_EVENT_TABLE();

dlgProperty *slPathFactory::CreateDialog(frmMain *frame, pgObject *node, pgObject *parent)
{
	return new dlgRepPath(this, frame, (slPath *)node, (slNode *)parent);
}


dlgRepPath::dlgRepPath(pgaFactory *f, frmMain *frame, slPath *p, slNode *n)
	: dlgRepProperty(f, frame, n->GetCluster(), wxT("dlgRepPath"))
{
	path = p;
	node = n;
}


pgObject *dlgRepPath::GetObject()
{
	return path;
}


int dlgRepPath::Go(bool modal)
{

	if (path)
	{
		// edit mode
		cbServer->Append(IdAndName(path->GetSlId(), path->GetName()), (void *)path->GetSlId());
		cbServer->SetSelection(0);
		cbServer->Disable();

		txtConnInfo->SetValue(path->GetConnInfo());
		txtConnRetry->SetValue(NumToStr(path->GetConnRetry()));
	}
	else
	{
		// create mode

		txtConnRetry->SetValue(wxT("10"));

		pgSet *nodes = connection->ExecuteSet(
		                   wxT("SELECT no_id, no_comment\n")
		                   wxT("  FROM ") + cluster->GetSchemaPrefix() + wxT("sl_node\n")
		                   wxT("  LEFT JOIN ") + cluster->GetSchemaPrefix() + wxT("sl_path ON pa_client=\n") + NumToStr(node->GetSlId()) +
		                   wxT(" AND pa_server=no_id\n")
		                   wxT(" WHERE no_active AND pa_client IS NULL\n")
		                   wxT("   AND no_id <> ") + NumToStr(node->GetSlId()) + wxT("\n")
		                   wxT(" ORDER BY no_id")
		               );

		if (nodes)
		{
			while (!nodes->Eof())
			{
				cbServer->Append(IdAndName(nodes->GetLong(wxT("no_id")), nodes->GetVal(wxT("no_comment"))),
				                 (void *)nodes->GetLong(wxT("no_id")));
				nodes->MoveNext();
			}
			delete nodes;
		}
		if (cbServer->GetCount() > 0)
			cbServer->SetSelection(0);
	}

	return dlgProperty::Go(modal);
}


pgObject *dlgRepPath::CreateObject(pgCollection *collection)
{
	pgObject *obj = pathFactory.CreateObjects(collection, 0,
	                wxT(" WHERE pa_server = ") + NumToStr((OID)cbServer->wxItemContainer::GetClientData(cbServer->GetCurrentSelection())) +
	                wxT("   AND pa_client = ") + NumToStr(node->GetSlId()));

	return obj;
}




void dlgRepPath::CheckChange()
{
	if (path)
	{
		EnableOK(txtConnInfo->GetValue() != path->GetConnInfo()
		         ||   StrToLong(txtConnRetry->GetValue()) != path->GetConnRetry());
	}
	else
	{
		bool enable = true;
		CheckValid(enable, cbServer->GetCount() > 0, _("No provider node without path definition left."));
		CheckValid(enable, cbServer->GetCurrentSelection() >= 0, _("Please select provider node."));

		wxString connInfo = txtConnInfo->GetValue();
		CheckValid(enable, connInfo.Find(wxT("host=")) >= 0, _("Please provide host in connect info."));
		CheckValid(enable, connInfo.Find(wxT("dbname=")) >= 0, _("Please provide dbname in connect info."));
		CheckValid(enable, connInfo.Find(wxT("user=")) >= 0, _("Please provide user in connect info."));

		EnableOK(enable);
	}
}



wxString dlgRepPath::GetSql()
{
	wxString sql;

	int sel = cbServer->GetCurrentSelection();

	if (sel >= 0)
	{
		sql = wxT("SELECT ") + cluster->GetSchemaPrefix() + wxT("storepath(")
		      + NumToStr((OID)cbServer->wxItemContainer::GetClientData(sel)) + wxT(", ")
		      + NumToStr(node->GetSlId()) + wxT(", ")
		      + qtDbString(txtConnInfo->GetValue()) + wxT(", ")
		      + NumToStr(StrToLong(txtConnRetry->GetValue())) + wxT(");");
	}
	return sql;
}