Ejemplo n.º 1
0
wxString pgDatabase::GetQuotedSchemaPrefix(const wxString &name) const
{
	wxString str = GetSchemaPrefix(name);
	if (!str.IsEmpty())
		return qtIdent(str.Left(str.Length() - 1)) + wxT(".");
	return str;
}
Ejemplo n.º 2
0
void pgCast::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Source type"), GetSchemaPrefix(GetSourceNamespace()) + GetSourceType());
		properties->AppendItem(_("Target type"), GetSchemaPrefix(GetTargetNamespace()) + GetTargetType());
		if (GetCastFunction().IsNull())
			properties->AppendItem(_("Function"), _("(binary compatible)"));
		else
			properties->AppendItem(_("Function"), GetCastFunction() + wxT("(") + GetSourceType() + wxT(")"));
		properties->AppendItem(_("Context"), GetCastContext());
		properties->AppendYesNoItem(_("System cast?"), GetSystemObject());
		if (GetConnection()->BackendMinimumVersion(7, 5))
			properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
	}
}
void pgConversion::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
    if (properties)
    {
        CreateListColumns(properties);

        properties->AppendItem(_("Name"), GetName());
        properties->AppendItem(_("OID"), GetOid());
        properties->AppendItem(_("Owner"), GetOwner());
        properties->AppendItem(_("From"), GetForEncoding());
        properties->AppendItem(_("To"), GetToEncoding());
        properties->AppendItem(_("Function"), GetSchemaPrefix(GetProcNamespace()) + GetProc());
        properties->AppendItem(_("Default?"), GetDefaultConversion());
        properties->AppendItem(_("System conversion?"), GetSystemObject());
        if (GetConnection()->BackendMinimumVersion(7, 5))
            properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
    }
}
Ejemplo n.º 4
0
bool slCluster::DropObject(wxFrame *frame, ctlTree *browser, bool cascaded)
{
	return GetDatabase()->ExecuteVoid(
	           wxT("SELECT ") + GetSchemaPrefix() + wxT("uninstallnode();\n")
	           wxT("DROP SCHEMA ") + qtIdent(wxT("_") + GetName()) + wxT(" CASCADE;"));
}
Ejemplo n.º 5
0
void slCluster::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (!expandedKids)
	{
		expandedKids = true;

		browser->RemoveDummyChild(this);
		pgSet *set;

		set = GetDatabase()->ExecuteSet(
		          wxT("SELECT no_id, no_comment, ") + GetSchemaPrefix() + wxT("slonyversion() AS version\n")
		          wxT("  FROM ") + GetSchemaPrefix() + wxT("sl_local_node_id\n")
		          wxT("  JOIN ") + GetSchemaPrefix() + wxT("sl_node ON no_id = last_value"));
		if (set)
		{
			iSetClusterVersion(set->GetVal(wxT("version")));
			iSetLocalNodeID(set->GetLong(wxT("no_id")));
			iSetLocalNodeName(set->GetVal(wxT("no_comment")).BeforeFirst('\n'));
			delete set;
		}

		adminNodeID = settings->Read(wxT("Replication/") + GetName() + wxT("/AdminNode"), -1L);

		wxString sql =  wxT("SELECT no_id, no_comment\n")
		                wxT("  FROM ") + GetSchemaPrefix() + wxT("sl_node\n");

		if (adminNodeID == -1L)
		{
			sql +=  wxT("  JOIN ") + GetSchemaPrefix() + wxT("sl_path ON no_id = pa_client\n")
			        wxT(" WHERE pa_server = ") + NumToStr(localNodeID) +
			        wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%host=") + GetServer()->GetName() + wxT("%")) +
			        wxT("   AND pa_conninfo LIKE ") + qtDbString(wxT("%dbname=") + GetDatabase()->GetName() + wxT("%"));
		}
		else
			sql += wxT(" WHERE no_id = ") + NumToStr(adminNodeID);


		set = GetDatabase()->ExecuteSet(sql);
		if (set)
		{
			if (!set->Eof())
			{
				adminNodeID = set->GetLong(wxT("no_id"));
				adminNodeName = set->GetVal(wxT("no_comment"));
				settings->WriteLong(wxT("Replication/") + GetName() + wxT("/AdminNode"), adminNodeID);
			}
			delete set;
		}

		wxLogInfo(wxT("Adding child object to cluster %s"), GetIdentifier().c_str());

		browser->AppendCollection(this, nodeFactory);
		browser->AppendCollection(this, setFactory);
	}


	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("Local node ID"), GetLocalNodeID());
		properties->AppendItem(_("Local node"), GetLocalNodeName());

		if (GetAdminNodeID() == -1L)
			properties->AppendItem(_("Admin node"), _("<none>"));
		else
		{
			properties->AppendItem(_("Admin node ID"), GetAdminNodeID());
			properties->AppendItem(_("Admin node"), GetAdminNodeName());
		}

		long slonPid = GetSlonPid();
		if (slonPid)
			properties->AppendItem(wxT("Slon PID"), slonPid);
		else
			properties->AppendItem(wxT("Slon PID"), _("unknown"));

		properties->AppendItem(_("Version"), GetClusterVersion());
		properties->AppendItem(_("Owner"), GetOwner());
		properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
	}
}
Ejemplo n.º 6
0
pgConn *slCluster::GetNodeConn(frmMain *form, long nodeId, bool create)
{
	size_t i;

	if (nodeId == GetLocalNodeID())
		return GetDatabase()->GetConnection();

	for (i = 0 ; i < remoteConns.GetCount() ; i++)
	{
		if (remoteConns[i].nodeID == nodeId)
			return remoteConns[i].conn;
	}

	if (create && adminNodeID >= 0)
	{
		wxString connstr = GetDatabase()->ExecuteScalar(
		                       wxT("SELECT pa_conninfo FROM ") + GetSchemaPrefix() + wxT("sl_path\n")
		                       wxT(" WHERE pa_server = ") + NumToStr(nodeId) +
		                       wxT("   AND pa_client = ") + NumToStr(adminNodeID));

		if (!connstr.IsEmpty())
		{
			// check for server registration
			wxTreeItemId servers = GetId();
			pgObject *obj = this;
			while (obj && obj != form->GetServerCollection())
			{
				servers = form->GetBrowser()->GetItemParent(servers);
				if (servers)
					obj = form->GetBrowser()->GetObject(servers);
			}

			wxCookieType cookie;

			wxStringTokenizer strtok(connstr, wxT(" "), wxTOKEN_RET_EMPTY);

			wxString lastToken;
			wxArrayString tokens;
			wxString str;

			while (strtok.HasMoreTokens())
			{
				str = strtok.GetNextToken();
				if (str.Find('=') < 0)
				{
					if (!lastToken.IsEmpty())
						lastToken += wxT(" ");
					lastToken += str;
				}
				else
				{
					if (!lastToken.IsEmpty())
						tokens.Add(lastToken);
					lastToken = str;
				}
			}
			if (!lastToken.IsEmpty())
				tokens.Add(lastToken);

			size_t i;

			wxString host, dbname;
			int port = 5432;
			for (i = 0 ; i < tokens.GetCount() ; i++)
			{
				str = tokens[i].BeforeFirst('=');
				if (str == wxT("host"))
					host = tokens[i].AfterFirst('=');
				else if (str == wxT("dbname"))
					dbname = tokens[i].AfterFirst('=');
				else if (str == wxT("port"))
					port = StrToLong(tokens[i].AfterFirst('='));
			}

			if (host.IsEmpty() || dbname.IsEmpty())
				return NULL;

			wxTreeItemId serverItem = form->GetBrowser()->GetFirstChild(servers, cookie);
			while (serverItem)
			{
				pgServer *server = (pgServer *)form->GetBrowser()->GetObject(serverItem);
				if (server && server->IsCreatedBy(serverFactory))
				{
					if (server->GetName() == host && server->GetPort() == port)
					{
						if (!server->GetConnected())
						{
							server->Connect(form, server->GetStorePwd());
							if (!server->GetConnected())
							{
								wxLogError(server->GetLastError());
								return NULL;
							}
						}
						pgConn *conn = server->CreateConn(dbname);

						if (conn)
							remoteConns.Add(new RemoteConn(nodeId, connstr, conn));

						return conn;
					}
				}
				serverItem = form->GetBrowser()->GetNextChild(servers, cookie);
			}

		}
	}
	return NULL;
}