Example #1
0
int dlgRepSetMerge::Go(bool modal)
{
	txtID->SetValue(IdAndName(set->GetSlId(), set->GetName()));
	txtID->Disable();

	wxString sql =
	    wxT("SELECT set_id, set_comment\n")
	    wxT("  FROM ") + cluster->GetSchemaPrefix() + wxT("sl_set\n")
	    wxT("  LEFT JOIN ") + cluster->GetSchemaPrefix() + wxT("sl_subscribe ON set_id=sub_set\n")
	    wxT(" WHERE set_origin = ") + NumToStr(cluster->GetLocalNodeID()) +
	    wxT("   AND set_id <> ") + NumToStr(set->GetSlId());

	if (set->GetSubscriptionCount() > 0)
		sql += wxT("\n")
		       wxT(" GROUP BY set_id, set_comment\n")
		       wxT("HAVING COUNT(sub_set) > 0");
	else
		sql += wxT("\n")
		       wxT("   AND sub_set IS NULL");

	pgSet *sets = connection->ExecuteSet(sql);

	if (sets)
	{
		while (!sets->Eof())
		{
			long id = sets->GetLong(wxT("set_id"));
			cbTargetID->Append(IdAndName(id, sets->GetVal(wxT("set_comment"))), (void *)id);
			sets->MoveNext();
		}
		delete sets;
	}

	return dlgProperty::Go(modal);
}
int dlgRepSubscription::Go(bool modal)
{
	txtOrigin->SetValue(NumToStr(set->GetOriginId()));
	if (subscription)
	{
		// edit mode
		chkForward->SetValue(subscription->GetForward());
		txtReceiver->SetValue(IdAndName(subscription->GetReceiverId(), subscription->GetReceiverNode()));
	}
	else
	{
		// create mode
		txtReceiver->SetValue(IdAndName(cluster->GetLocalNodeID(), cluster->GetLocalNodeName()));

		if (cluster->ClusterMinimumVersion(1, 1))
		{
			// This is very ugly: starting with Slony-I 1.1, this must be called on the provider,
			// not on the receiver.
			stProvider->SetLabel(_("Receiver"));
			stReceiver->SetLabel(_("Provider"));
		}
	}

	if (set->GetOriginId() == cluster->GetLocalNodeID() && subscription)
	{
		chkForward->SetValue(subscription->GetForward());
		cbProvider->Append(IdAndName(subscription->GetProviderId(), subscription->GetProviderNode()));
		cbProvider->SetSelection(0);
		cbProvider->Disable();
		chkForward->Disable();
		EnableOK(false);
	}
	else
	{
		pgSet *sets = connection->ExecuteSet(
		                  wxT("SELECT no_id, no_comment\n")
		                  wxT("  FROM ") + cluster->GetSchemaPrefix() + wxT("sl_node\n")
		                  wxT(" WHERE no_active AND no_id <> ") + NumToStr(cluster->GetLocalNodeID()));

		if (sets)
		{
			while (!sets->Eof())
			{
				cbProvider->Append(IdAndName(sets->GetLong(wxT("no_id")), sets->GetVal(wxT("no_comment"))),
				                   (void *)sets->GetLong(wxT("no_id")));

				if (subscription && sets->GetLong(wxT("no_id")) == subscription->GetProviderId())
					cbProvider->SetSelection(cbProvider->GetCount() - 1);
				sets->MoveNext();
			}
			delete sets;
		}
	}
	if (!subscription && cbProvider->GetCount())
	{
		cbProvider->SetSelection(0);
		EnableOK(true);
	}
	return dlgProperty::Go(modal);
}
Example #3
0
int dlgRepListen::Go(bool modal)
{
	txtReceiver->SetValue(IdAndName(node->GetSlId(), node->GetName()));
	txtReceiver->Disable();

	if (listen)
	{
		// edit mode
		cbOrigin->Append(IdAndName(listen->GetSlId(), listen->GetName()));
		cbOrigin->SetSelection(0);
		cbProvider->Append(IdAndName(listen->GetProviderId(), listen->GetProviderName()));
		cbProvider->SetSelection(0);
		cbOrigin->Disable();
		cbProvider->Disable();
	}
	else
	{
		// create mode

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

		if (nodes)
		{
			while (!nodes->Eof())
			{
				long id = nodes->GetLong(wxT("no_id"));
				wxString name = IdAndName(id, nodes->GetVal(wxT("no_comment")));

				cbOrigin->Append(name, (void *)id);

				if (nodes->GetLong(wxT("pa_server")) > 0)
					cbProvider->Append(name, (void *)id);

				nodes->MoveNext();
			}
			delete nodes;
		}
	}

	return dlgProperty::Go(modal);
}
Example #4
0
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);
}
Example #5
0
void dlgRepCluster::OnChangeCluster(wxCommandEvent &ev)
{
	clusterBackup = wxEmptyString;
	remoteVersion = wxEmptyString;

	cbAdminNode->Clear();
	cbAdminNode->Append(_("<none>"), (void *) - 1);

	int sel = cbClusterName->GetCurrentSelection();
	if (remoteConn && sel >= 0)
	{
		wxString schemaPrefix = qtIdent(wxT("_") + cbClusterName->GetValue()) + wxT(".");
		long adminNodeID = settings->Read(wxT("Replication/") + cbClusterName->GetValue() + wxT("/AdminNode"), -1L);

		remoteVersion = remoteConn->ExecuteScalar(wxT("SELECT ") + schemaPrefix + wxT("slonyVersion();"));

		wxString sql =
		    wxT("SELECT no_id, no_comment\n")
		    wxT("  FROM ") + schemaPrefix + wxT("sl_node\n")
		    wxT("  JOIN ") + schemaPrefix + wxT("sl_path ON no_id = pa_client\n")
		    wxT(" WHERE pa_server = (SELECT last_value FROM ") + schemaPrefix + wxT("sl_local_node_id)\n")
		    wxT("   AND pa_conninfo ILIKE ") + qtDbString(wxT("%host=") + remoteServer->GetName() + wxT("%")) + wxT("\n")
		    wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%dbname=") + cbDatabase->GetValue() + wxT("%")) + wxT("\n");

		if (remoteServer->GetPort() != 5432)
			sql += wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%port=") + NumToStr((long)remoteServer->GetPort()) + wxT("%"));

		pgSet *set = remoteConn->ExecuteSet(sql);
		if (set)
		{
			if (!set->Eof())
			{
				long id = set->GetLong(wxT("no_id"));
				cbAdminNode->Append(IdAndName(id, set->GetVal(wxT("no_comment"))), (void *)id);
				if (adminNodeID == id)
					cbAdminNode->SetSelection(cbAdminNode->GetCount() - 1);
			}
		}


		usedNodes.Clear();
		set = remoteConn->ExecuteSet(
		          wxT("SELECT no_id FROM ") + schemaPrefix + wxT("sl_node"));

		if (set)
		{
			while (!set->Eof())
			{
				usedNodes.Add(set->GetLong(wxT("no_id")));
				set->MoveNext();
			}
			delete set;
		}
	}
	OnChange(ev);
}
Example #6
0
int dlgRepSet::Go(bool modal)
{
	txtID->SetValidator(numericValidator);

	if (set)
	{
		// edit mode
		txtID->SetValue(NumToStr(set->GetSlId()));
		txtID->Disable();
		txtOrigin->SetValue(IdAndName(set->GetOriginId(), set->GetOriginNode()));
		txtComment->Disable();
	}
	else
	{
		// create mode
		txtOrigin->SetValue(IdAndName(cluster->GetLocalNodeID(), cluster->GetLocalNodeName()));
		EnableOK(true);
	}

	txtOrigin->Disable();

	return dlgProperty::Go(modal);
}
Example #7
0
int dlgRepSetMove::Go(bool modal)
{
	txtID->SetValue(IdAndName(set->GetSlId(), set->GetName()));
	txtID->Disable();

	pgSet *nodes = connection->ExecuteSet(
	                   wxT("SELECT no_id, no_comment\n")
	                   wxT("  FROM ") + cluster->GetSchemaPrefix() + wxT("sl_node\n")
	                   wxT("  JOIN ") + cluster->GetSchemaPrefix() + wxT("sl_subscribe ON sub_receiver=no_id\n")
	                   wxT(" WHERE sub_set = ") + NumToStr(set->GetSlId()));

	if (nodes)
	{
		while (!nodes->Eof())
		{
			long id = nodes->GetLong(wxT("no_id"));
			cbTargetNode->Append(IdAndName(id, nodes->GetVal(wxT("no_comment"))), (void *)id);
			nodes->MoveNext();
		}
		delete nodes;
	}
	return dlgProperty::Go(modal);
}
Example #8
0
int dlgRepCluster::Go(bool modal)
{
	chkJoinCluster->SetValue(false);

	if (cluster)
	{
		// edit mode
		txtClusterName->SetValue(cluster->GetName());
		txtNodeID->SetValue(NumToStr(cluster->GetLocalNodeID()));
		txtClusterName->Disable();
		txtNodeID->Disable();
		txtNodeName->SetValue(cluster->GetLocalNodeName());
		txtNodeName->Disable();
		chkJoinCluster->Disable();

		txtAdminNodeID->Hide();
		txtAdminNodeName->Hide();

		wxString sql =
		    wxT("SELECT no_id, no_comment\n")
		    wxT("  FROM ") + cluster->GetSchemaPrefix() + wxT("sl_node\n")
		    wxT("  JOIN ") + cluster->GetSchemaPrefix() + wxT("sl_path ON no_id = pa_client\n")
		    wxT(" WHERE pa_server = ") + NumToStr(cluster->GetLocalNodeID()) +
		    wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%host=") + cluster->GetServer()->GetName() + wxT("%")) +
		    wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%dbname=") + cluster->GetDatabase()->GetName() + wxT("%"));

		if (cluster->GetServer()->GetPort() != 5432)
			sql += wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%port=") + NumToStr((long)cluster->GetServer()->GetPort()) + wxT("%"));

		sql += wxT(" ORDER BY no_id");

		pgSet *set = connection->ExecuteSet(sql);
		if (set)
		{
			while (!set->Eof())
			{
				long id = set->GetLong(wxT("no_id"));
				cbAdminNode->Append(IdAndName(id, set->GetVal(wxT("no_comment"))), (void *)id);
				if (id == cluster->GetAdminNodeID())
					cbAdminNode->SetSelection(cbAdminNode->GetCount() - 1);

				set->MoveNext();
			}
			delete set;
		}
		if (!cbAdminNode->GetCount())
		{
			cbAdminNode->Append(_("<none>"), (void *) - 1);
			cbAdminNode->SetSelection(0);
		}

		cbServer->Append(cluster->GetServer()->GetName());
		cbServer->SetSelection(0);
		cbDatabase->Append(cluster->GetDatabase()->GetName());
		cbDatabase->SetSelection(0);
		cbClusterName->Append(cluster->GetName());
		cbClusterName->SetSelection(0);
	}
	else
	{
		// create mode
		cbAdminNode->Hide();

		wxString scriptVersion = wxEmptyString;
		wxString xxidVersion = wxEmptyString;

		txtNodeID->SetValidator(numericValidator);
		txtAdminNodeID->SetValidator(numericValidator);
		txtClusterName->Hide();

		//We need to find the exact Slony Version.
		//NOTE: We are not supporting Slony versions less than 1.2.0

		wxString tempScript;
		AddScript(tempScript, wxT("slony1_funcs.sql"));

		if (tempScript.Contains(wxT("@MODULEVERSION@")) && slonyVersion.IsEmpty())
		{
			this->database->ExecuteVoid(wxT("CREATE OR REPLACE FUNCTION pgadmin_slony_version() returns text as '$libdir/slony1_funcs', '_Slony_I_getModuleVersion' LANGUAGE C"));
			slonyVersion = this->database->ExecuteScalar(wxT("SELECT pgadmin_slony_version();"));
			this->database->ExecuteVoid(wxT("DROP FUNCTION pgadmin_slony_version()"));

			if (slonyVersion.IsEmpty())
			{
				wxLogError(_("Couldn't test for the Slony version. Assuming 1.2.0"));
				slonyVersion = wxT("1.2.0");
			}
		}

		//Here we are finding the exact slony scripts version, which is based on Slony Version and PG Version.
		// For Slony 1.2.0 to 1.2.17 and 2.0.0 if PG 7.3 script version is v73
		// For Slony 1.2.0 to 1.2.17 and 2.0.0 if PG 7.4 script version is v74
		// For Slony 1.2.0 to 1.2.6 if PG 8.0+ script version is v80
		// For Slony 1.2.7 to 1.2.17 and 2.0.0 if PG 8.0 script version is v80
		// For Slony 1.2.7 to 1.2.17 and 2.0.0 if PG 8.1+ script version is v81
		// For Slony 2.0.1 and 2.0.2 if PG 8.3+ script version is v83. (These version onwards do not support PG Version less than 8.3)
		// For Slony 2.0.3 if PG 8.3 script version is v83.
		// For Slony 2.0.3 if PG 8.4+ script version is v84.

		//Since both 1.2 and 2.0 series is increasing, the following code needs to be updated with each Slony or PG update.


		if (!tempScript.IsEmpty())
		{
			//Set the slony_base and slony_funcs script version.
			if (SlonyMaximumVersion(wxT("1.2"), 6))
			{
				if (connection->BackendMinimumVersion(8, 0))
					scriptVersion = wxT("v80");
				else
				{
					if (connection->BackendMinimumVersion(7, 4))
						scriptVersion = wxT("v74");
					else
						scriptVersion = wxT("v73");
				}
			}
			else
			{
				if (SlonyMaximumVersion(wxT("1.2"), 17) || SlonyMaximumVersion(wxT("2.0"), 0))
				{
					if (connection->BackendMinimumVersion(8, 1))
						scriptVersion = wxT("v81");
					else
					{
						if (connection->BackendMinimumVersion(8, 0))
							scriptVersion = wxT("v80");
						else
						{
							if (connection->BackendMinimumVersion(7, 4))
								scriptVersion = wxT("v74");
							else
								scriptVersion = wxT("v73");
						}
					}
				}
				else
				{
					if (SlonyMaximumVersion(wxT("2.0"), 2))
						scriptVersion = wxT("v83");
					else
					{
						if (SlonyMaximumVersion(wxT("2.0"), 3))
						{
							if (connection->BackendMinimumVersion(8, 4))
								scriptVersion = wxT("v84");
						}
						else
							scriptVersion = wxT("v83");
					}
				}

			}

			//Set the correct xxid version if applicable
			// For Slony 1.2.0 to 1.2.17 and 2.0.0 if PG 7.3 xxid version is v73
			// For Slony 1.2.1 to 1.2.17 and 2.0.0 if PG 7.4+ xxid version is v74
			// For Slony 1.2.0 if PG 8.0 xxid version is v80
			// For Slony 2.0.1+ and PG8.4+ xxid is obsolete.

			if (SlonyMaximumVersion(wxT("1.2"), 0))
			{
				if (connection->BackendMinimumVersion(8, 0))
					xxidVersion = wxT("v80");
				else
				{
					if (connection->BackendMinimumVersion(7, 4))
						xxidVersion = wxT("v74");
					else
						xxidVersion = wxT("v73");
				}
			}
			else
			{
				if (SlonyMaximumVersion(wxT("1.2"), 17) || SlonyMaximumVersion(wxT("2.0"), 0))
				{
					if (!connection->BackendMinimumVersion(8, 4))
					{
						if (connection->BackendMinimumVersion(7, 4))
							xxidVersion = wxT("v74");
						else
							xxidVersion = wxT("v73");
					}
				}
			}


			wxString slonyBaseVersionFilename = wxT("slony1_base.") + scriptVersion + wxT(".sql");
			wxString slonyFuncsVersionFilename = wxT("slony1_funcs.") + scriptVersion + wxT(".sql");

			wxString xxidVersionFilename;

			if (!xxidVersion.IsEmpty())
				xxidVersionFilename = wxT("xxid.") + xxidVersion + wxT(".sql");

			if (((!xxidVersion.IsEmpty() && !AddScript(createScript, xxidVersionFilename)) ||
			        !AddScript(createScript, wxT("slony1_base.sql")) ||
			        !AddScript(createScript, slonyBaseVersionFilename) ||
			        !AddScript(createScript, wxT("slony1_funcs.sql")) ||
			        !AddScript(createScript, slonyFuncsVersionFilename)))
				createScript = wxEmptyString;

		}

		// Populate the server combo box
		ctlTree *browser = mainForm->GetBrowser();
		wxTreeItemIdValue foldercookie, servercookie;
		wxTreeItemId folderitem, serveritem;
		pgObject *object;
		pgServer *server;
		int sel = -1;

		folderitem = browser->GetFirstChild(browser->GetRootItem(), foldercookie);
		while (folderitem)
		{
			if (browser->ItemHasChildren(folderitem))
			{
				serveritem = browser->GetFirstChild(folderitem, servercookie);
				while (serveritem)
				{
					object = browser->GetObject(serveritem);
					if (object->IsCreatedBy(serverFactory))
					{
						server = (pgServer *)object;
						if (server == database->GetServer())
							sel = cbServer->GetCount();
						cbServer->Append(browser->GetItemText(server->GetId()), (void *)server);
					}
					serveritem = browser->GetNextChild(folderitem, servercookie);
				}
			}
			folderitem = browser->GetNextChild(browser->GetRootItem(), foldercookie);
		}

		if (sel >= 0)
			cbServer->SetSelection(sel);
	}

	wxCommandEvent ev;
	OnChangeJoin(ev);

	return dlgRepClusterBase::Go(modal);
}