Esempio n. 1
0
void dlgRole::OnVarnameSelChange(wxCommandEvent &ev)
{
	int sel = cbVarname->GuessSelection(ev);

	SetupVarEditor(sel);
}
Esempio n. 2
0
int dlgDatabase::Go(bool modal)
{
	bool createDefPriv = false;
	wxString strDefPrivsOnTables, strDefPrivsOnSeqs, strDefPrivsOnFuncs, strDefPrivsOnTypes;

	if (connection->BackendMinimumVersion(9, 2))
	{
		seclabelPage->SetConnection(connection);
		seclabelPage->SetObject(database);
		this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgDatabase::OnChange));
	}
	else
		seclabelPage->Disable();

	if (connection->BackendMinimumVersion(9, 0))
	{
		cbVarUsername->Append(wxT(""));
		// AddUsers function of dlgDefaultSecurity has already been called.
		// Hence, calling dlgProperty::AddUsers instead of that.
		dlgProperty::AddUsers(cbVarUsername);
	}
	else
		cbVarUsername->Enable(false);

	if (connection->BackendMinimumVersion(8, 0))
	{
		stPath->Hide();
		txtPath->Hide();
	}
	else
	{
		stTablespace->Hide();
		cbTablespace->Hide();
	}

	if (!connection->BackendMinimumVersion(8, 1))
	{
		txtConnLimit->Disable();
	}
	else
		txtConnLimit->SetValidator(numericValidator);

	if (!connection->BackendMinimumVersion(8, 4))
	{
		cbCollate->Disable();
		cbCType->Disable();
	}

	pgSet *set;
	if (connection->BackendMinimumVersion(7, 4))
		set = connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
		                             wxT("  FROM pg_settings WHERE context in ('user', 'superuser')"));
	else
		set = connection->ExecuteSet(wxT("SELECT name, 'string' as vartype, '' as min_val, '' as max_val FROM pg_settings"));
	if (set)
	{
		while (!set->Eof())
		{
			cbVarname->Append(set->GetVal(0));
			varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") +
			            set->GetVal(wxT("min_val")) + wxT(" ") +
			            set->GetVal(wxT("max_val")));
			set->MoveNext();
		}
		delete set;

		cbVarname->SetSelection(0);

		if (connection->BackendMinimumVersion(9, 0))
		{
			cbVarUsername->SetSelection(0);
		}
		SetupVarEditor(0);
	}

	if (database)
	{
		// edit mode

		if (!connection->BackendMinimumVersion(7, 4))
			txtName->Disable();

		if (!connection->BackendMinimumVersion(8, 0))
			cbOwner->Disable();

		readOnly = !database->GetServer()->GetCreatePrivilege();


		if (connection->BackendMinimumVersion(9, 0))
		{
			createDefPriv = true;
			strDefPrivsOnTables = database->GetDefPrivsOnTables();
			strDefPrivsOnSeqs   = database->GetDefPrivsOnSequences();
			strDefPrivsOnFuncs  = database->GetDefPrivsOnFunctions();
		}
		if (connection->BackendMinimumVersion(9, 2))
			strDefPrivsOnTypes = database->GetDefPrivsOnTypes();

		if (readOnly)
		{
			cbVarname->Disable();
			cbVarUsername->Disable();
			txtValue->Disable();
			btnAdd->Disable();
			btnRemove->Disable();
		}

		size_t i;
		wxString username;
		wxString varname;
		wxString varvalue;
		for (i = 0 ; i < database->GetVariables().GetCount() ; i += 3)
		{
			username = database->GetVariables().Item(i);
			varname = database->GetVariables().Item(i + 1);
			varvalue = database->GetVariables().Item(i + 2);

			lstVariables->AppendItem(0, username, varname, varvalue);
		}

		PrepareTablespace(cbTablespace, database->GetTablespaceOid());
		if (connection->BackendMinimumVersion(8, 4))
			cbTablespace->Enable();
		else
			cbTablespace->Disable();
		txtPath->SetValue(database->GetPath());
		txtPath->Disable();

		cbEncoding->Append(database->GetEncoding());
		cbEncoding->SetSelection(0);

		if (connection->BackendMinimumVersion(8, 1))
		{
			wxString strConnLimit;
			strConnLimit.Printf(wxT("%ld"), database->GetConnectionLimit());
			txtConnLimit->SetValue(strConnLimit);
		}

		if (connection->BackendMinimumVersion(8, 4))
		{
			cbCollate->Append(database->GetCollate());
			cbCollate->SetSelection(0);
			cbCType->Append(database->GetCType());
			cbCType->SetSelection(0);
		}

		cbTemplate->Disable();
		cbEncoding->Disable();
		cbCollate->Disable();
		cbCType->Disable();

		txtSchemaRestr->SetValue(database->GetSchemaRestriction());
	}
	else
	{
		// create mode
		if (!connection->BackendMinimumVersion(8, 2))
			txtComment->Disable();

		PrepareTablespace(cbTablespace);

		// Add the default tablespace
		cbTablespace->Insert(_("<default tablespace>"), 0, (void *)0);
		cbTablespace->SetSelection(0);

		cbTemplate->Append(wxEmptyString);
		FillCombobox(wxT("SELECT datname FROM pg_database ORDER BY datname"), cbTemplate);
		cbTemplate->SetSelection(0);

		if (connection->BackendMinimumVersion(8, 4))
		{
			FillCombobox(wxT("select DISTINCT(datctype) from pg_database UNION SELECT DISTINCT(datcollate) from pg_database"), cbCollate, cbCType);
			if (cbCollate->FindString(wxT("C")) < 0)
			{
				cbCollate->AppendString(wxT("C"));
				cbCType->AppendString(wxT("C"));
			}
			if (cbCollate->FindString(wxT("POSIX")) < 0)
			{
				cbCollate->AppendString(wxT("POSIX"));
				cbCType->AppendString(wxT("POSIX"));
			}
		}
		if (connection->BackendMinimumVersion(8, 1))
		{
			txtConnLimit->SetValue(wxT("-1"));
		}


		long encNo = 0;
		wxString encStr;
		do
		{
			encStr = connection->ExecuteScalar(
			             wxT("SELECT pg_encoding_to_char(") + NumToStr(encNo) + wxT(")"));
			if (pgConn::IsValidServerEncoding(encNo) && !encStr.IsEmpty())
				cbEncoding->Append(encStr);

			encNo++;
		}
		while (!encStr.IsEmpty());

		encStr = connection->ExecuteScalar(wxT("SELECT pg_encoding_to_char(encoding) FROM pg_database WHERE datname = 'template0'"));
		encNo = cbEncoding->FindString(encStr);

		if (encNo < 0)
		{
			encNo = cbEncoding->FindString(wxT("UNICODE"));
			if (encNo < 0)
				encNo = cbEncoding->FindString(wxT("UTF8"));
		}

		if (encNo >= 0)
			cbEncoding->SetSelection(encNo);

	}

	// Find, and disable the CONNECT ACL option if we're on pre 8.2
	if (!connection->BackendMinimumVersion(8, 2))
	{
		// Disable the checkbox
		if (!DisablePrivilege(wxT("CONNECT")))
		{
			wxLogError(_("Failed to disable the CONNECT privilege checkbox!"));
		}
	}

	return dlgDefaultSecurityProperty::Go(modal, createDefPriv, strDefPrivsOnTables, strDefPrivsOnSeqs, strDefPrivsOnFuncs, strDefPrivsOnTypes);
}
Esempio n. 3
0
int dlgRole::Go(bool modal)
{

// In wxMac, the text deletion of "calenderBox" is not raising the EVT_CALENDAR_SEL_CHANGED, EVT_DATE_CHANGED events properly.
// Hence, raising these events with wxEVT_CHILD_FOCUS events.
//
#ifdef __WXMAC__

	datValidUntil->Connect(wxEVT_CHILD_FOCUS, wxCommandEventHandler(dlgRole::OnChange), NULL, this);
	timValidUntil->Connect(wxEVT_CHILD_FOCUS, wxCommandEventHandler(dlgRole::OnChange), NULL, this);

#endif

	if (connection->BackendMinimumVersion(9, 0))
	{
		cbVarDbname->Append(wxT(""));
		AddDatabases(cbVarDbname);
	}
	else
	{
		cbVarDbname->Enable(false);
	}

	if (connection->BackendMinimumVersion(9, 2))
	{
		seclabelPage->SetConnection(connection);
		seclabelPage->SetObject(role);
		this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgRole::OnChange));
	}
	else
		seclabelPage->Disable();

	wxString roleSql =
	    wxT("SELECT rolname\n")
	    wxT("  FROM pg_roles r\n");

	varInfo.Add(wxT("role"));
	cbVarname->Append(wxT("role"));

	pgSet *set;
	set = connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
	                             wxT("  FROM pg_settings WHERE context in ('user', 'superuser')"));

	if (set)
	{
		while (!set->Eof())
		{
			cbVarname->Append(set->GetVal(0));
			varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") +
			            set->GetVal(wxT("min_val")) + wxT(" ") +
			            set->GetVal(wxT("max_val")));
			set->MoveNext();
		}
		delete set;

		cbVarname->SetSelection(0);

		if (connection->BackendMinimumVersion(9, 0))
		{
			cbVarDbname->SetSelection(0);
		}

		SetupVarEditor(0);
	}

	if (role)
	{
		wxArrayString roles = role->GetRolesIn();
		size_t i;
		for (i = 0 ; i < roles.GetCount() ; i++)
			lbRolesIn->Append(roles.Item(i));

		roleSql +=
		    wxT("  LEFT JOIN pg_auth_members ON r.oid=roleid AND member = ") + role->GetOidStr() + wxT("\n")
		    wxT(" WHERE r.oid <> ") + role->GetOidStr() + wxT("\n")
		    wxT("   AND roleid IS NULL");

		// Edit Mode
		if (role->GetServer()->GetSuperUser() || role->GetServer()->GetCreateRole())
			readOnly = false;
		else
			readOnly = true;

		chkCreateDB->SetValue(role->GetCreateDatabase());
		chkCreateRole->SetValue(role->GetCreateRole());
		chkSuperuser->SetValue(role->GetSuperuser());
		chkInherits->SetValue(role->GetInherits());
		if (!connection->BackendMinimumVersion(9, 5))
			chkUpdateCat->SetValue(role->GetUpdateCatalog());
		else
			chkUpdateCat->Disable();
		chkCanLogin->SetValue(role->GetCanLogin());
		chkReplication->SetValue(role->GetReplication());
		if (role->GetAccountExpires().IsValid() && role->GetAccountExpires().GetValue() != -1)
		{
			datValidUntil->SetValue(role->GetAccountExpires().GetDateOnly());
			timValidUntil->SetTime(role->GetAccountExpires());
		}
		else
		{
			wxDateTime empty;
			datValidUntil->SetValue(empty);
		}
		txtConnectionLimit->SetValue(NumToStr(role->GetConnectionLimit()));
		txtComment->SetValue(role->GetComment());

		size_t index;
		wxString dbname;
		wxString parameter;
		wxString value;
		for (index = 0 ; index < role->GetVariables().GetCount() ; index += 3)
		{
			dbname = role->GetVariables().Item(index);
			parameter = role->GetVariables().Item(index + 1);
			value = role->GetVariables().Item(index + 2);

			lstVariables->AppendItem(0, dbname, parameter, value);
		}

		timValidUntil->Enable(!readOnly && role->GetAccountExpires().IsValid());

		if (readOnly)
		{
			chkCanLogin->Disable();
			chkCreateDB->Disable();
			chkCreateRole->Disable();
			chkSuperuser->Disable();
			chkInherits->Disable();
			chkUpdateCat->Disable();
			chkReplication->Disable();
			datValidUntil->Disable();
			timValidUntil->Disable();
			btnAddRole->Disable();
			btnDelRole->Disable();
			cbVarname->Disable();
			cbVarDbname->Disable();
			txtValue->Disable();
			txtConnectionLimit->Disable();
			btnRemove->Disable();
			/* Its own password can be changed. */
			if (connection->GetUser() != role->GetName())
			{
				txtPasswd->Disable();
				txtRePasswd->Disable();
				btnAdd->Disable();
			}
			else
			{
				txtPasswd->Enable();
				txtRePasswd->Enable();
				btnAdd->Enable();
			}
		}
	}
	else
	{
		chkCanLogin->Disable();
		wxDateTime empty;
		datValidUntil->SetValue(empty);
		timValidUntil->Disable();
	}

	// Role comments are only appropriate in 8.2+
	if (!connection->BackendMinimumVersion(8, 2))
		txtComment->Disable();

	// Replication roles added in 9.1
	if (!connection->BackendMinimumVersion(9, 1))
	{
		chkReplication->Disable();
	}


	if (!settings->GetShowUsersForPrivileges())
	{
		if (role)
			roleSql += wxT("\n   AND NOT rolcanlogin");
		else
			roleSql += wxT("\n WHERE NOT rolcanlogin");
	}
	roleSql += wxT("\n ORDER BY rolname");

	pgSetIterator roles(connection, roleSql);

	while (roles.RowsLeft())
		lbRolesNotIn->Append(roles.GetVal(wxT("rolname")));

	return dlgProperty::Go(modal);
}
Esempio n. 4
0
int dlgRole::Go(bool modal)
{
    wxString roleSql=
        wxT("SELECT rolname\n")
        wxT("  FROM pg_roles r\n");

        varInfo.Add(wxT("role"));
        cbVarname->Append(wxT("role"));

        pgSet *set;
        set=connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
                wxT("  FROM pg_settings WHERE context in ('user', 'superuser')"));

        if (set)
        {
            while (!set->Eof())
            {
                cbVarname->Append(set->GetVal(0));
                varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") + 
                            set->GetVal(wxT("min_val")) + wxT(" ") +
                            set->GetVal(wxT("max_val")));
                set->MoveNext();
            }
            delete set;

            cbVarname->SetSelection(0);
            SetupVarEditor(0);
        }

    if (role)
    {
        wxArrayString roles=role->GetRolesIn();
        size_t i;
        for (i=0 ; i < roles.GetCount() ; i++)
            lbRolesIn->Append(roles.Item(i));

        roleSql += 
            wxT("  LEFT JOIN pg_auth_members ON r.oid=roleid AND member = ") + role->GetOidStr() + wxT("\n")
            wxT(" WHERE r.oid <> ") + role->GetOidStr() + wxT("\n")
            wxT("   AND roleid IS NULL");

        // Edit Mode
        if (role->GetServer()->GetSuperUser() || role->GetServer()->GetCreateRole()) 
			readOnly=false;
		else
			readOnly=true;

        chkCreateDB->SetValue(role->GetCreateDatabase());
        chkCreateRole->SetValue(role->GetCreateRole());
        chkSuperuser->SetValue(role->GetSuperuser());
        chkInherits->SetValue(role->GetInherits());
        chkUpdateCat->SetValue(role->GetUpdateCatalog());
        chkCanLogin->SetValue(role->GetCanLogin());
        chkReplication->SetValue(role->GetReplication());
        datValidUntil->SetValue(role->GetAccountExpires());
        timValidUntil->SetTime(role->GetAccountExpires());
        txtConnectionLimit->SetValue(NumToStr(role->GetConnectionLimit()));
        txtComment->SetValue(role->GetComment());

        size_t index;
        for (index = 0 ; index < role->GetConfigList().GetCount() ; index++)
        {
            wxString item=role->GetConfigList().Item(index);
            lstVariables->AppendItem(0, item.BeforeFirst('='), item.AfterFirst('='));
        }

        timValidUntil->Enable(!readOnly && role->GetAccountExpires().IsValid());

        if (readOnly)
        {
            chkCanLogin->Disable();
            chkCreateDB->Disable();
            chkCreateRole->Disable();
            chkSuperuser->Disable();
            chkInherits->Disable();
            chkUpdateCat->Disable();
            chkReplication->Disable();
            datValidUntil->Disable();
            timValidUntil->Disable();
            btnAddRole->Disable();
            btnDelRole->Disable();
            cbVarname->Disable();
            txtValue->Disable();
            txtConnectionLimit->Disable();
            btnRemove->Disable();
	    /* Its own password can be changed. */
	    if (connection->GetUser() != role->GetName())
	    {
		txtPasswd->Disable();
		txtRePasswd->Disable();
		btnAdd->Disable();
	    }
	    else
	    {
		txtPasswd->Enable();
		txtRePasswd->Enable();
		btnAdd->Enable();
	    }
        }
    }
    else
    {
        chkCanLogin->Disable();
        wxDateTime empty;
        datValidUntil->SetValue(empty);
        timValidUntil->Disable();
    }

    // Role comments are only appropriate in 8.2+
    if (!connection->BackendMinimumVersion(8, 2))
        txtComment->Disable();

    // Replication roles added in 9.1
    if (!connection->BackendMinimumVersion(9, 1))
	{
		chkReplication->Disable();
	}


    if (!settings->GetShowUsersForPrivileges())
    {
        if (role)
            roleSql += wxT("\n   AND NOT rolcanlogin");
        else
            roleSql += wxT("\n WHERE NOT rolcanlogin");
    }
    roleSql += wxT("\n ORDER BY rolname");

    pgSetIterator roles(connection, roleSql);

    while (roles.RowsLeft())
        lbRolesNotIn->Append(roles.GetVal(wxT("rolname")));

    return dlgProperty::Go(modal);
}
int dlgUser::Go(bool modal)
{
    pgSet *set=connection->ExecuteSet(wxT("SELECT groname FROM pg_group"));
    if (set)
    {
        while (!set->Eof())
        {
            wxString groupName=set->GetVal(wxT("groname"));
            if (user && user->GetGroupsIn().Index(groupName) >= 0)
                lbGroupsIn->Append(groupName);
            else
                lbGroupsNotIn->Append(groupName);

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

    if (connection->BackendMinimumVersion(7, 4))
        set=connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
                wxT("  FROM pg_settings WHERE context in ('user', 'superuser')"));
    else
        set=connection->ExecuteSet(wxT("SELECT name, 'string' as vartype, '' as min_val, '' as max_val FROM pg_settings"));
    if (set)
    {
        while (!set->Eof())
        {
            cbVarname->Append(set->GetVal(0));
            varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") + 
                        set->GetVal(wxT("min_val")) + wxT(" ") +
                        set->GetVal(wxT("max_val")));
            set->MoveNext();
        }
        delete set;

        cbVarname->SetSelection(0);
    }

    if (user)
    {
        // Edit Mode
        readOnly=!user->GetServer()->GetSuperUser();

        txtID->SetValue(NumToStr(user->GetUserId()));
        chkCreateDB->SetValue(user->GetCreateDatabase());
        chkCreateUser->SetValue(user->GetSuperuser());
        datValidUntil->SetValue(user->GetAccountExpires());
        timValidUntil->SetTime(user->GetAccountExpires());
        if (!connection->BackendMinimumVersion(7, 4))
            txtName->Disable();
        txtID->Disable();

        size_t index;
        for (index = 0 ; index < user->GetConfigList().GetCount() ; index++)
        {
            wxString item=user->GetConfigList().Item(index);
            lstVariables->AppendItem(0, item.BeforeFirst('='), item.AfterFirst('='));
        }

        timValidUntil->Enable(!readOnly && user->GetAccountExpires().IsValid());

        if (readOnly)
        {
            chkCreateDB->Disable();
            chkCreateUser->Disable();
            datValidUntil->Disable();
            timValidUntil->Disable();
            btnAddGroup->Disable();
            btnDelGroup->Disable();
            cbVarname->Disable();
            txtValue->Disable();
            btnRemove->Disable();
	    if (connection->GetUser() != user->GetName())
	    {
		txtPasswd->Disable();
		txtRePasswd->Disable();
		btnAdd->Disable();
	    }
	    else
	    {
		txtPasswd->Enable();
		txtRePasswd->Enable();
		btnAdd->Enable();
	    }
        }
    }
    else
    {
        wxDateTime empty;
        datValidUntil->SetValue(empty);
        txtID->SetValidator(numericValidator);
        timValidUntil->Disable();
    }

    SetupVarEditor(1);
    return dlgProperty::Go(modal);
}
Esempio n. 6
0
int dlgFunction::Go(bool modal)
{
	isBackendMinVer84 = connection->BackendMinimumVersion(8, 4);

	if (connection->BackendMinimumVersion(9, 1))
	{
		seclabelPage->SetConnection(connection);
		seclabelPage->SetObject(function);
		this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgFunction::OnChange));
	}
	else
		seclabelPage->Disable();

	if (function)
	{
		cbSchema->Enable(connection->BackendMinimumVersion(8, 1));
		rdbIn->Disable();
		rdbOut->Disable();
		rdbInOut->Disable();
		rdbVariadic->Disable();
		isProcedure = function->GetIsProcedure();
	}
	else
		cbOwner->Append(wxEmptyString);

	if (!isBackendMinVer84)
		txtArgDefVal->Disable();
	chkLeakProof->Enable(connection->BackendMinimumVersion(9, 2));

	AddGroups(cbOwner);
	AddUsers(cbOwner);

	lstArguments->AddColumn(_("Type"), 60);
	lstArguments->AddColumn(_("Mode"), 40);
	lstArguments->AddColumn(_("Name"), 60);
	lstArguments->AddColumn(_("Default Value"), 60);

	if (!connection->BackendMinimumVersion(8, 0))
		cbOwner->Disable();

	if (!connection->BackendMinimumVersion(8, 3))
		txtCost->Disable();

	txtRows->Disable();

	if (!connection->BackendMinimumVersion(8, 0))
		txtArgName->Disable();

	// Window function can not be modified
	// Disable it for editing
	if (function || !isBackendMinVer84)
		chkWindow->Disable();

	if (isProcedure)
	{
		if (function && !connection->EdbMinimumVersion(8, 2))
			txtName->Disable();
		cbOwner->Disable();
		cbLanguage->Disable();
		chkStrict->Disable();
		chkWindow->Disable();
		chkSecureDefiner->Disable();
		chkSetof->Disable();
		cbVolatility->Disable();
		cbReturntype->Disable();
		txtCost->Disable();
		txtRows->Disable();
		chkLeakProof->Disable();
	}
	else
	{
		if (!connection->BackendMinimumVersion(8, 1))
		{
			rdbIn->SetValue(true);
			rdbIn->Disable();
			rdbOut->Disable();
			rdbInOut->Disable();
		}

		if (!isBackendMinVer84)
		{
			rdbVariadic->Disable();
		}
	}

	pgSet *lang = connection->ExecuteSet(wxT("SELECT lanname FROM pg_language"));
	if (lang)
	{
		while (!lang->Eof())
		{
			wxString language = lang->GetVal(0);
			if (factory == &triggerFunctionFactory)
			{
				if (language.IsSameAs(wxT("SQL"), false) ||
				        language.IsSameAs(wxT("edbspl"), false))
				{
					lang->MoveNext();
					continue;
				}
			}
			cbLanguage->Append(language);
			lang->MoveNext();
		}
		delete lang;
	}

	if (connection->BackendMinimumVersion(8, 3))
	{
		pgSet *set;
		set = connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
		                             wxT("  FROM pg_settings WHERE context in ('user', 'superuser')"));
		if (set)
		{
			while (!set->Eof())
			{
				cbVarname->Append(set->GetVal(0));
				varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") +
				            set->GetVal(wxT("min_val")) + wxT(" ") +
				            set->GetVal(wxT("max_val")));
				set->MoveNext();
			}
			delete set;

			cbVarname->SetSelection(0);
			SetupVarEditor(0);
		}

	}
	else
	{
		btnAddVar->Disable();
		btnRemoveVar->Disable();
		cbVarname->Disable();
		txtValue->Disable();
		chkValue->Disable();
	}

	if (function)
	{
		// edit mode

		if (factory != &triggerFunctionFactory)
		{
			wxArrayString argTypes = function->GetArgTypesArray();
			wxArrayString argNames = function->GetArgNamesArray();
			wxArrayString argModes = function->GetArgModesArray();
			wxArrayString argDefs  = function->GetArgDefsArray();

			for (unsigned int i = 0; i < argTypes.Count(); i++)
			{
				if (argModes[i] != wxT("TABLE"))
				{
					if (isBackendMinVer84)
						lstArguments->AppendItem(-1, argTypes.Item(i), argModes[i], argNames[i], (argDefs.Count() > i ? argDefs[i] : wxString(wxEmptyString)));
					else
						lstArguments->AppendItem(-1, argTypes.Item(i), argModes[i], argNames[i]);
				}
			}
		}

		txtArguments->SetValue(function->GetArgListWithNames());
		cbReturntype->Append(function->GetReturnType());
		cbReturntype->SetValue(function->GetReturnType());

		cbLanguage->SetValue(function->GetLanguage());
		cbVolatility->SetValue(function->GetVolatility());

		chkSetof->SetValue(function->GetReturnAsSet());
		chkStrict->SetValue(function->GetIsStrict());
		if (connection->BackendMinimumVersion(8, 4))
			chkWindow->SetValue(function->GetIsWindow());
		chkSecureDefiner->SetValue(function->GetSecureDefiner());
		chkLeakProof->SetValue(function->GetIsLeakProof());

		if (function->GetLanguage().IsSameAs(wxT("C"), false))
		{
			txtObjectFile->SetValue(function->GetBin());
			txtLinkSymbol->SetValue(function->GetSource());
		}
		else
			txtSqlBox->SetText(function->GetSource());

		if (!connection->BackendMinimumVersion(7, 4))
			txtName->Disable();

		if (connection->BackendMinimumVersion(8, 3))
		{
			txtCost->SetValue(NumToStr(function->GetCost()));
			if (function->GetReturnAsSet())
			{
				txtRows->SetValue(NumToStr(function->GetRows()));
				txtRows->Enable();
			}
			else
				txtRows->Disable();
		}

		size_t index;
		for (index = 0 ; index < function->GetConfigList().GetCount() ; index++)
		{
			wxString item = function->GetConfigList().Item(index);
			lstVariables->AppendItem(0, item.BeforeFirst('='), item.AfterFirst('='));
		}

		cbReturntype->Disable();
		chkSetof->Disable();
		cbDatatype->Disable();
		// Editing paramter for wrapped functions is not allowed
		// It will anyway throw an error, if we try to edit the paramter list
		if ( connection->GetIsEdb() &&
		        function->GetSource().Trim(false).StartsWith( wxT( "$__EDBwrapped__$" )))
		{
			isEdbWrapped = true;
			cbDatatype->Disable();
			rdbIn->Disable();
			rdbOut->Disable();
			rdbInOut->Disable();
			rdbVariadic->Disable();
			txtArgName->Disable();
			txtArgDefVal->Disable();
			btnAdd->Disable();
			btnChange->Disable();
			btnRemove->Disable();
		}
	}
	else
	{
		wxString restrict;
		// create mode
		restrict = wxT("(typtype IN ('b', 'c', 'd', 'p') AND typname NOT IN ('any', 'trigger', 'language_handler'))");
		if (!settings->GetShowSystemObjects())
			restrict += wxT(" AND nspname NOT LIKE E'pg\\\\_toast%' AND nspname NOT LIKE E'pg\\\\_temp%'");

		DatatypeReader tr(database, restrict);
		while (tr.HasMore())
		{
			pgDatatype dt = tr.GetDatatype();

			typOids.Add(tr.GetOidStr());
			types.Add(dt.GetQuotedSchemaPrefix(database) + dt.QuotedFullName());

			cbDatatype->Append(dt.GetQuotedSchemaPrefix(database) + dt.QuotedFullName());
			if (factory != &triggerFunctionFactory)
				cbReturntype->Append(dt.GetQuotedSchemaPrefix(database) + dt.QuotedFullName());
			tr.MoveNext();
		}

		long sel;
		if (factory == &triggerFunctionFactory)
		{
			cbReturntype->Append(wxT("trigger"));
			cbReturntype->SetSelection(0);
			cbReturntype->Disable();
			lstArguments->Disable();
			cbDatatype->Disable();
			txtArgName->Disable();
			sel = cbLanguage->FindString(wxT("c"));
		}
		else if (isProcedure)
			sel = cbLanguage->FindString(wxT("edbspl"));
		else
			sel = cbLanguage->FindString(wxT("sql"));

		if (sel >= 0)
			cbLanguage->SetSelection(sel);
		txtObjectFile->SetValue(TXTOBJ_LIB);
	}

	wxNotifyEvent event;
	OnSelChangeLanguage(event);

	return dlgSecurityProperty::Go(modal);
}
Esempio n. 7
0
int dlgTablespace::Go(bool modal)
{
	if (connection->BackendMinimumVersion(9, 2))
	{
		seclabelPage->SetConnection(connection);
		seclabelPage->SetObject(tablespace);
		this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgTablespace::OnChange));
	}
	else
		seclabelPage->Disable();

	if (!tablespace)
		cbOwner->Append(wxEmptyString);
	AddGroups(cbOwner);
	AddUsers(cbOwner);

	pgSet *set;
	if (connection->BackendMinimumVersion(8, 5))
	{
		set = connection->ExecuteSet(wxT("SELECT name, vartype, min_val, max_val\n")
		                             wxT("  FROM pg_settings WHERE name IN ('seq_page_cost', 'random_page_cost')"));
		if (set)
		{
			while (!set->Eof())
			{
				cbVarname->Append(set->GetVal(0));
				varInfo.Add(set->GetVal(wxT("vartype")) + wxT(" ") +
				            set->GetVal(wxT("min_val")) + wxT(" ") +
				            set->GetVal(wxT("max_val")));
				set->MoveNext();
			}
			delete set;

			cbVarname->SetSelection(0);
			SetupVarEditor(0);
		}
	}
	else
	{
		lstVariables->Enable(false);
		btnAdd->Enable(false);
		btnRemove->Enable(false);
		cbVarname->Enable(false);
		txtValue->Enable(false);
		chkValue->Enable(false);
	}

	if (tablespace)
	{
		// Edit Mode
		txtName->SetValue(tablespace->GetIdentifier());
		txtLocation->SetValue(tablespace->GetLocation());
		txtComment->SetValue(tablespace->GetComment());

		txtLocation->Disable();

		size_t i;
		for (i = 0 ; i < tablespace->GetVariables().GetCount() ; i++)
		{
			wxString item = tablespace->GetVariables().Item(i);
			lstVariables->AppendItem(0, item.BeforeFirst('='), item.AfterFirst('='));
		}
	}
	else
	{
	}

	// Tablespace comments are only appropriate in 8.2+
	if (!connection->BackendMinimumVersion(8, 2))
		txtComment->Disable();

	return dlgSecurityProperty::Go(modal);
}