Example #1
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()));
	}
}
Example #2
0
void User::Say( const wxString& message ) const
{
  GetServer().SayPrivate( m_nick, message );
}
Example #3
0
void User::DoAction( const wxString& message ) const
{
  GetServer().DoActionPrivate( m_nick, message );
}
Example #4
0
void User::SendMyUserStatus() const
{
  GetServer().SendMyUserStatus();
}
Example #5
0
bool pgDatabase::CanDebugPlpgsql()
{
	wxString preload_option;

	// Result cache - 0 = not tested, 1 = false, 2 = true.
	if (canDebugPlpgsql == 1)
		return false;
	else if (canDebugPlpgsql == 2)
		return true;

	// "show shared_preload_libraries" does not work for other than
	// the super users.
	if (GetServer()->GetSuperUser())
	{
		// Parameter's name depends of the backend's version
		if (server->GetConnection()->BackendMinimumVersion(8, 2))
		{
			preload_option = wxT("shared_preload_libraries");
		}
		else
		{
			preload_option = wxT("preload_libraries");
		}

		// Check the appropriate plugin is loaded
		if (!ExecuteScalar(wxT("SHOW ") + preload_option).Contains(wxT("plugin_debugger")))
		{
			canDebugPlpgsql = 1;
			return false;
		}
	}

	if (ExecuteScalar(wxT("SELECT count(*) FROM pg_proc WHERE proname = 'pldbg_get_target_info';")) == wxT("0"))
	{
		canDebugPlpgsql = 1;
		return false;
	}

	// If this is EDBAS81, the debuggers will be built into the PLs
	// so we don't need to check any further.
	if (server->GetConnection()->EdbMinimumVersion(8, 1))
	{
		canDebugPlpgsql = 2;
		return true;
	}

	// On EDBAS82 and PostgreSQL, we need to check to make sure that
	// the debugger library is also available.
	if (ExecuteScalar(wxT("SELECT count(*) FROM pg_proc WHERE proname = 'plpgsql_oid_debug';")) == wxT("0"))
	{
		canDebugPlpgsql = 1;
		return false;
	}
	else
	{
		canDebugPlpgsql = 2;
		return true;
	}

	return true;
}
Example #6
0
void pgDatabase::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (Connect() == PGCONN_OK)
	{
		// Set the icon if required
		UpdateIcon(browser);

		// Add child nodes if necessary
		if (browser->GetChildrenCount(GetId(), false) == 0)
		{
			wxLogInfo(wxT("Adding child object to database %s"), GetIdentifier().c_str());

			if (settings->GetDisplayOption(_("Catalogs")))
				browser->AppendCollection(this, catalogFactory);
			if (settings->GetDisplayOption(_("Casts")))
				browser->AppendCollection(this, castFactory);
			if (settings->GetDisplayOption(_("Extensions")) && GetConnection()->BackendMinimumVersion(9, 1))
				browser->AppendCollection(this, extensionFactory);
			if (settings->GetDisplayOption(_("Foreign Data Wrappers")) && GetConnection()->BackendMinimumVersion(8, 4))
				browser->AppendCollection(this, foreignDataWrapperFactory);
			if (settings->GetDisplayOption(_("Languages")))
				browser->AppendCollection(this, languageFactory);
			if (settings->GetDisplayOption(_("Synonyms")) && connection()->EdbMinimumVersion(8, 0))
				if (!GetConnection()->BackendMinimumVersion(8, 4))
					browser->AppendCollection(this, synonymFactory);
			if (settings->GetDisplayOption(_("Schemas")))
				browser->AppendCollection(this, schemaFactory);
			if (settings->GetDisplayOption(_("Slony-I Clusters")))
				browser->AppendCollection(this, slClusterFactory);

			wxString missingFKsql = wxT("SELECT COUNT(*) FROM\n")
			                        wxT("   (SELECT tgargs from pg_trigger tr\n")
			                        wxT("      LEFT JOIN pg_depend dep ON dep.objid=tr.oid AND deptype = 'i'\n")
			                        wxT("      LEFT JOIN pg_constraint co ON refobjid = co.oid AND contype = 'f'\n")
			                        wxT("     WHERE \n");
			if (connection()->BackendMinimumVersion(9, 0))
				missingFKsql += wxT("tgisinternal\n");
			else
				missingFKsql += wxT("tgisconstraint\n");

			missingFKsql += wxT("     AND co.oid IS NULL\n")
			                wxT("     GROUP BY tgargs\n")
			                wxT("    HAVING count(1) = 3) AS foo");
			missingFKs = StrToLong(connection()->ExecuteScalar(missingFKsql));
		}
	}

	GetServer()->iSetLastDatabase(GetName());

	if (properties)
	{
		// Setup listview
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), NumToStr(GetOid()));
		properties->AppendItem(_("Owner"), GetOwner());
		properties->AppendItem(_("ACL"), GetAcl());
		if (!GetPath().IsEmpty())
			properties->AppendItem(_("Path"), GetPath());

		// We may not actually be connected...
		if (GetConnection() && GetConnection()->BackendMinimumVersion(8, 0))
		{
			properties->AppendItem(_("Tablespace"), GetTablespace());
			properties->AppendItem(_("Default tablespace"), GetDefaultTablespace());
		}
		properties->AppendItem(_("Encoding"), GetEncoding());

		if (GetConnection() && GetConnection()->BackendMinimumVersion(8, 4))
		{
			properties->AppendItem(_("Collation"), GetCollate());
			properties->AppendItem(_("Character type"), GetCType());
		}

		properties->AppendItem(_("Default schema"), defaultSchema);

		properties->AppendItem(_("Default table ACL"), m_defPrivsOnTables);
		properties->AppendItem(_("Default sequence ACL"), m_defPrivsOnSeqs);
		properties->AppendItem(_("Default function ACL"), m_defPrivsOnFuncs);

		size_t i;
		wxString username;
		wxString varname;
		wxString varvalue;
		for (i = 0 ; i < variables.GetCount() ; i++)
		{
			wxStringTokenizer tkz(variables.Item(i), wxT("="));
			while (tkz.HasMoreTokens())
			{
				username = tkz.GetNextToken();
				varname = tkz.GetNextToken();
				varvalue = tkz.GetNextToken();
			}

			if (username.Length() == 0)
			{
				properties->AppendItem(varname, varvalue);
			}
			else
			{
				// should we add the parameters for the username?
				// I don't think so
				// but if we want this, how will we display that?
			}
		}
		properties->AppendYesNoItem(_("Allow connections?"), GetAllowConnections());
		properties->AppendYesNoItem(_("Connected?"), GetConnected());
		if (GetConnection() && GetConnection()->BackendMinimumVersion(8, 1))
		{
			wxString strConnLimit;
			strConnLimit.Printf(wxT("%ld"), GetConnectionLimit());
			properties->AppendItem(_("Connection limit"), strConnLimit);
		}
		properties->AppendYesNoItem(_("System database?"), GetSystemObject());
		if (GetMissingFKs())
			properties->AppendItem(_("Old style FKs"), GetMissingFKs());
		if (!GetSchemaRestriction().IsEmpty())
			properties->AppendItem(_("Schema restriction"), GetSchemaRestriction());
		properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));

		if (!GetLabels().IsEmpty())
		{
			wxArrayString seclabels = GetProviderLabelArray();
			if (seclabels.GetCount() > 0)
			{
				for (unsigned int index = 0 ; index < seclabels.GetCount() - 1 ; index += 2)
				{
					properties->AppendItem(seclabels.Item(index), seclabels.Item(index + 1));
				}
			}
		}
	}
	if (form && GetCanHint() && !hintShown)
	{
		ShowHint(form, false);
	}
}
Example #7
0
wxString pgDatabase::GetSql(ctlTree *browser)
{
	if (sql.IsEmpty())
	{
		// If we can't connect to this database, use the maintenance DB
		pgConn *myConn = GetConnection();
		if (!myConn)
			myConn = GetServer()->GetConnection();

		sql = wxT("-- Database: ") + GetQuotedFullIdentifier() + wxT("\n\n")
		      + wxT("-- DROP DATABASE ") + GetQuotedIdentifier() + wxT(";")
		      + wxT("\n\nCREATE DATABASE ") + GetQuotedIdentifier()
		      + wxT("\n  WITH OWNER = ") + qtIdent(GetOwner())
		      + wxT("\n       ENCODING = ") + qtDbString(GetEncoding());
		if (!GetTablespace().IsEmpty())
			sql += wxT("\n       TABLESPACE = ") + qtIdent(GetTablespace());
		if (myConn && myConn->BackendMinimumVersion(8, 4))
		{
			sql += wxT("\n       LC_COLLATE = ") + qtDbString(GetCollate());
			sql += wxT("\n       LC_CTYPE = ") + qtDbString(GetCType());
		}
		if (myConn && myConn->BackendMinimumVersion(8, 1))
		{
			sql += wxT("\n       CONNECTION LIMIT = ");
			sql << GetConnectionLimit();
		}
		sql += wxT(";\n");

		size_t i;
		wxString username;
		wxString varname;
		wxString varvalue;
		for (i = 0 ; i < variables.GetCount() ; i++)
		{
			wxStringTokenizer tkz(variables.Item(i), wxT("="));
			while (tkz.HasMoreTokens())
			{
				username = tkz.GetNextToken();
				varname = tkz.GetNextToken();
				varvalue = tkz.GetNextToken();
			}

			if (username.Length() == 0)
			{
				sql += wxT("ALTER DATABASE ") + GetQuotedFullIdentifier();
			}
			else
			{
				sql += wxT("ALTER ROLE ") + username + wxT(" IN DATABASE ") + GetQuotedFullIdentifier();
			}
			if (varname != wxT("search_path") && varname != wxT("temp_tablespaces"))
				sql += wxT(" SET ") + varname + wxT("='") + varvalue + wxT("';\n");
			else
				sql += wxT(" SET ") + varname + wxT("=") + varvalue + wxT(";\n");
		}

		if (myConn)
		{
			if (!myConn->BackendMinimumVersion(8, 2))
				sql += GetGrant(wxT("CT"));
			else
				sql += GetGrant(wxT("CTc"));
		}

		sql += wxT("\n") + pgDatabase::GetDefaultPrivileges('r', m_defPrivsOnTables, wxT(""));
		sql += pgDatabase::GetDefaultPrivileges('S', m_defPrivsOnSeqs, wxT(""));
		sql += pgDatabase::GetDefaultPrivileges('f', m_defPrivsOnFuncs, wxT(""));

		sql += GetCommentSql();

		if (myConn->BackendMinimumVersion(9, 2))
			sql += GetSeqLabelsSql();
	}
	return sql;
}
Example #8
0
void pgDatabaseCollection::ShowStatistics(frmMain *form, ctlListView *statistics)
{
	wxLogInfo(wxT("Displaying statistics for databases on ") + GetServer()->GetIdentifier());

	bool hasSize = GetConnection()->HasFeature(FEATURE_SIZE);

	wxString restr;
	if (!GetServer()->GetDbRestriction().IsEmpty())
	{
		if (restr.IsEmpty())
			restr = wxT(" WHERE db.datname IN (");
		else
			restr = wxT("   AND db.datname IN (");

		restr += GetServer()->GetDbRestriction() + wxT(")\n");
	}

	wxString sql = wxT("SELECT db.datid, db.datname, numbackends, xact_commit, xact_rollback, blks_read, blks_hit");

	if (GetConnection()->BackendMinimumVersion(8, 3))
		sql += wxT(", tup_returned, tup_fetched, tup_inserted, tup_updated, tup_deleted");
	if (GetConnection()->BackendMinimumVersion(9, 1))
		sql += wxT(", stats_reset, slave.confl_tablespace, slave.confl_lock, slave.confl_snapshot, slave.confl_bufferpin, slave.confl_deadlock");
	if (hasSize)
		sql += wxT(", pg_size_pretty(pg_database_size(db.datid)) as size");

	sql += wxT("\n  FROM pg_stat_database db\n");
	if (GetConnection()->BackendMinimumVersion(9, 1))
		sql += wxT("  JOIN pg_stat_database_conflicts slave ON db.datid=slave.datid\n");
	sql += restr + wxT(" ORDER BY db.datname");

	// Add the statistics view columns
	statistics->ClearAll();
	statistics->AddColumn(_("Database"), 60);
	statistics->AddColumn(_("Backends"), 50);
	if (hasSize)
		statistics->AddColumn(_("Size"), 60);
	statistics->AddColumn(_("Xact Committed"), 60);
	statistics->AddColumn(_("Xact Rolled Back"), 60);
	statistics->AddColumn(_("Blocks Read"), 60);
	statistics->AddColumn(_("Blocks Hit"), 60);
	if (GetConnection()->BackendMinimumVersion(8, 3))
	{
		statistics->AddColumn(_("Tuples Returned"), 60);
		statistics->AddColumn(_("Tuples Fetched"), 60);
		statistics->AddColumn(_("Tuples Inserted"), 60);
		statistics->AddColumn(_("Tuples Updated"), 60);
		statistics->AddColumn(_("Tuples Deleted"), 60);
	}
	if (GetConnection()->BackendMinimumVersion(9, 1))
	{
		statistics->AddColumn(_("Last statistics reset"), 60);
		statistics->AddColumn(_("Tablespace conflicts"), 60);
		statistics->AddColumn(_("Lock conflicts"), 60);
		statistics->AddColumn(_("Snapshot conflicts"), 60);
		statistics->AddColumn(_("Bufferpin conflicts"), 60);
		statistics->AddColumn(_("Deadlock conflicts"), 60);
	}

	bool sysobj;
	pgSet *stats = GetServer()->ExecuteSet(sql);
	if (stats)
	{
		while (!stats->Eof())
		{
			if (stats->GetVal(wxT("datname")) == wxT("template0"))
				sysobj = true;
			else
				sysobj = stats->GetOid(wxT("datid")) <= GetServer()->GetLastSystemOID();

			if (settings->GetShowSystemObjects() || !sysobj)
			{
				statistics->InsertItem(statistics->GetItemCount(), stats->GetVal(wxT("datname")), PGICON_STATISTICS);
				statistics->SetItem(statistics->GetItemCount() - 1, 1, stats->GetVal(wxT("numbackends")));
				if (hasSize)
					statistics->SetItem(statistics->GetItemCount() - 1, 2, stats->GetVal(wxT("size")));
				statistics->SetItem(statistics->GetItemCount() - 1, 2 + (hasSize ? 1 : 0), stats->GetVal(wxT("xact_commit")));
				statistics->SetItem(statistics->GetItemCount() - 1, 3 + (hasSize ? 1 : 0), stats->GetVal(wxT("xact_rollback")));
				statistics->SetItem(statistics->GetItemCount() - 1, 4 + (hasSize ? 1 : 0), stats->GetVal(wxT("blks_read")));
				statistics->SetItem(statistics->GetItemCount() - 1, 5 + (hasSize ? 1 : 0), stats->GetVal(wxT("blks_hit")));
				if (GetConnection()->BackendMinimumVersion(8, 3))
				{
					statistics->SetItem(statistics->GetItemCount() - 1, 6 + (hasSize ? 1 : 0), stats->GetVal(wxT("tup_returned")));
					statistics->SetItem(statistics->GetItemCount() - 1, 7 + (hasSize ? 1 : 0), stats->GetVal(wxT("tup_fetched")));
					statistics->SetItem(statistics->GetItemCount() - 1, 8 + (hasSize ? 1 : 0), stats->GetVal(wxT("tup_inserted")));
					statistics->SetItem(statistics->GetItemCount() - 1, 9 + (hasSize ? 1 : 0), stats->GetVal(wxT("tup_updated")));
					statistics->SetItem(statistics->GetItemCount() - 1, 10 + (hasSize ? 1 : 0), stats->GetVal(wxT("tup_deleted")));
				}
				if (GetConnection()->BackendMinimumVersion(9, 1))
				{
					statistics->SetItem(statistics->GetItemCount() - 1, 11 + (hasSize ? 1 : 0), stats->GetVal(wxT("stats_reset")));
					statistics->SetItem(statistics->GetItemCount() - 1, 12 + (hasSize ? 1 : 0), stats->GetVal(wxT("confl_tablespace")));
					statistics->SetItem(statistics->GetItemCount() - 1, 13 + (hasSize ? 1 : 0), stats->GetVal(wxT("confl_lock")));
					statistics->SetItem(statistics->GetItemCount() - 1, 14 + (hasSize ? 1 : 0), stats->GetVal(wxT("confl_snapshot")));
					statistics->SetItem(statistics->GetItemCount() - 1, 15 + (hasSize ? 1 : 0), stats->GetVal(wxT("confl_bufferpin")));
					statistics->SetItem(statistics->GetItemCount() - 1, 16 + (hasSize ? 1 : 0), stats->GetVal(wxT("confl_deadlock")));
				}
			}
			stats->MoveNext();
		}

		delete stats;
	}
}