Exemplo n.º 1
0
int dlgCast::Go(bool modal)
{

	if (!connection->BackendMinimumVersion(7, 5))
		txtComment->Disable();

	if (cast)
	{
		// edit mode
		cbSourceType->Append(cast->GetSourceType());
		cbSourceType->SetSelection(0);
		cbSourceType->Disable();

		cbTargetType->Append(wxEmptyString);
		cbTargetType->Append(cast->GetTargetType());
		cbTargetType->SetSelection(1);
		cbTargetType->Disable();

		AddType(wxT(" "), cast->GetSourceTypeOid());
		AddType(wxT(" "), cast->GetTargetTypeOid());

		cbFunction->Append(cast->GetCastFunction());
		cbFunction->SetSelection(0);

		cbFunction->Disable();
		chkImplicit->Disable();
	}
	else
	{
		// create mode
		FillDatatype(cbSourceType, cbTargetType, false);
	}

	return dlgProperty::Go(modal);
}
Exemplo n.º 2
0
int dlgDomain::Go(bool modal)
{
	if (connection->BackendMinimumVersion(9, 1))
	{
		seclabelPage->SetConnection(connection);
		seclabelPage->SetObject(domain);
		this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgDomain::OnChange));
	}
	else
		seclabelPage->Disable();

	if (domain)
	{
		// edit mode
		cbSchema->Enable(connection->BackendMinimumVersion(8, 1));
		cbDatatype->Append(domain->GetBasetype());
		AddType(wxT(" "), 0, domain->GetBasetype());
		cbDatatype->SetSelection(0);
		if (domain->GetLength() >= 0)
		{
			txtLength->SetValue(NumToStr(domain->GetLength()));
			if (domain->GetPrecision() >= 0)
				txtPrecision->SetValue(NumToStr(domain->GetPrecision()));
		}
		chkNotNull->SetValue(domain->GetNotNull());
		txtDefault->SetValue(domain->GetDefault());
		txtCheck->SetValue(domain->GetCheck());

		cbDatatype->Disable();

		cbCollation->SetValue(domain->GetQuotedCollation());
		cbCollation->Disable();

		if (!connection->BackendMinimumVersion(7, 4))
		{
			cbOwner->Disable();
			txtDefault->Disable();
			chkNotNull->Disable();
		}

		if (connection->BackendMinimumVersion(9, 2))
			chkDontValidate->SetValue(!domain->GetValid());
	}
	else
	{
		// create mode
		if (!connection->BackendMinimumVersion(7, 4))
			txtCheck->Disable();
		FillDatatype(cbDatatype, false);

		cbCollation->Enable(connection->BackendMinimumVersion(9, 1));
		if (connection->BackendMinimumVersion(9, 1))
		{
			// fill collation combobox
			cbCollation->Append(wxEmptyString);
			pgSet *set = connection->ExecuteSet(
			                 wxT("SELECT nspname, collname\n")
			                 wxT("  FROM pg_collation c, pg_namespace n\n")
			                 wxT("  WHERE c.collnamespace=n.oid\n")
			                 wxT("  ORDER BY nspname, collname"));
			if (set)
			{
				while (!set->Eof())
				{
					wxString name = qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname")));
					cbCollation->Append(name);
					set->MoveNext();
				}
				delete set;
			}
			cbCollation->SetSelection(0);
		}
	}

	if (connection->BackendMinimumVersion(9, 2))
		chkDontValidate->Enable(!domain || (domain && !domain->GetValid()));
	else
		chkDontValidate->Enable(false);

	return dlgProperty::Go(modal);
}
Exemplo n.º 3
0
int dlgDomain::Go(bool modal)
{
	if (connection->BackendMinimumVersion(9, 1))
	{
		seclabelPage->SetConnection(connection);
		seclabelPage->SetObject(domain);
		this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgDomain::OnChange));
	}
	else
		seclabelPage->Disable();

	if (domain)
	{
		// edit mode
		cbSchema->Enable(connection->BackendMinimumVersion(8, 1));
		cbDatatype->Append(domain->GetBasetype());
		AddType(wxT(" "), 0, domain->GetBasetype());
		cbDatatype->SetSelection(0);
		if (domain->GetLength() >= 0)
		{
			txtLength->SetValue(NumToStr(domain->GetLength()));
			if (domain->GetPrecision() >= 0)
				txtPrecision->SetValue(NumToStr(domain->GetPrecision()));
		}
		chkNotNull->SetValue(domain->GetNotNull());
		txtDefault->SetValue(domain->GetDefault());

		wxCookieType cookie;
		pgObject *data = 0;
		wxTreeItemId item = mainForm->GetBrowser()->GetFirstChild(domain->GetId(), cookie);
		while (item)
		{
			data = mainForm->GetBrowser()->GetObject(item);
			pgaFactory *factory = data->GetFactory();
			if (factory == checkFactory.GetCollectionFactory())
				constraintsItem = item;
			else if (data->GetMetaType() == PGM_CONSTRAINT)
				constraintsItem = item;

			if (constraintsItem)
				break;

			item = mainForm->GetBrowser()->GetNextChild(domain->GetId(), cookie);
		}

		if (constraintsItem)
		{
			pgCollection *coll = (pgCollection *)mainForm->GetBrowser()->GetObject(constraintsItem);
			// make sure all constraints are appended
			coll->ShowTreeDetail(mainForm->GetBrowser());
			// this is the constraints collection
			item = mainForm->GetBrowser()->GetFirstChild(constraintsItem, cookie);

			// add constraints
			while (item)
			{
				data = mainForm->GetBrowser()->GetObject(item);
				switch (data->GetMetaType())
				{
					case PGM_CHECK:
					{
						pgCheck *obj = (pgCheck *)data;

						lstConstraints->AppendItem(data->GetIconId(), obj->GetName(), obj->GetDefinition());
						constraintsDefinition.Add(obj->GetDefinition());
						previousConstraints.Add(obj->GetQuotedIdentifier()
						                        + wxT(" ") + obj->GetTypeName().Upper() + wxT(" ") + obj->GetDefinition());
						break;
					}
				}

				item = mainForm->GetBrowser()->GetNextChild(constraintsItem, cookie);
			}
		}

		cbDatatype->Disable();

		cbCollation->SetValue(domain->GetQuotedCollation());
		cbCollation->Disable();

		if (!connection->BackendMinimumVersion(7, 4))
		{
			cbOwner->Disable();
			txtDefault->Disable();
			chkNotNull->Disable();
		}
	}
	else
	{
		// create mode
		FillDatatype(cbDatatype, false);

		cbCollation->Enable(connection->BackendMinimumVersion(9, 1));
		if (connection->BackendMinimumVersion(9, 1))
		{
			// fill collation combobox
			cbCollation->Append(wxEmptyString);
			pgSet *set = connection->ExecuteSet(
			                 wxT("SELECT nspname, collname\n")
			                 wxT("  FROM pg_collation c, pg_namespace n\n")
			                 wxT("  WHERE c.collnamespace=n.oid\n")
			                 wxT("  ORDER BY nspname, collname"));
			if (set)
			{
				while (!set->Eof())
				{
					wxString name = qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname")));
					cbCollation->Append(name);
					set->MoveNext();
				}
				delete set;
			}
			cbCollation->SetSelection(0);
		}
	}

	cbConstrType->Clear();
	cbConstrType->Append(_("Check"));
	cbConstrType->SetSelection(0);
	btnRemoveConstr->Disable();

	return dlgProperty::Go(modal);
}
Exemplo n.º 4
0
int dlgOperator::Go(bool modal)
{
	if (oper)
	{
		// edit mode
		cbSchema->Enable(connection->BackendMinimumVersion(9, 1));

		cbLeftType->Append(oper->GetLeftType());
		cbLeftType->SetSelection(0);

		cbRightType->Append(oper->GetRightType());
		cbRightType->SetSelection(0);

		cbProcedure->Append(oper->GetOperatorFunction());
		cbProcedure->SetSelection(0);

		AddType(wxT(" "), oper->GetLeftTypeOid());
		AddType(wxT(" "), oper->GetRightTypeOid());

		cbRestrict->Append(oper->GetRestrictFunction());
		cbRestrict->SetSelection(0);

		cbJoin->Append(oper->GetJoinFunction());
		cbJoin->SetSelection(0);

		cbCommutator->Append(oper->GetCommutator());
		cbCommutator->SetSelection(0);

		cbNegator->Append(oper->GetNegator());
		cbNegator->SetSelection(0);

		if (!connection->BackendMinimumVersion(8, 3))
		{
			cbLeftSort->Append(oper->GetLeftSortOperator());
			cbLeftSort->SetSelection(0);

			cbRightSort->Append(oper->GetRightSortOperator());
			cbRightSort->SetSelection(0);

			cbLess->Append(oper->GetLessOperator());
			cbLess->SetSelection(0);

			cbGreater->Append(oper->GetGreaterOperator());
			cbGreater->SetSelection(0);
		}

		chkCanHash->SetValue(oper->GetHashJoins());
		chkCanMerge->SetValue(oper->GetMergeJoins());


		txtName->Disable();
		cbProcedure->Disable();
		cbLeftType->Disable();
		cbRightType->Disable();
		if (!connection->BackendMinimumVersion(8, 0))
			cbOwner->Disable();
	}
	else
	{
		// create mode
		wxArrayString incl;
		incl.Add(wxT("+"));
		incl.Add(wxT("-"));
		incl.Add(wxT("*"));
		incl.Add(wxT("/"));
		incl.Add(wxT("<"));
		incl.Add(wxT(">"));
		incl.Add(wxT("="));
		incl.Add(wxT("~"));
		incl.Add(wxT("!"));
		incl.Add(wxT("@"));
		incl.Add(wxT("#"));
		incl.Add(wxT("%"));
		incl.Add(wxT("^"));
		incl.Add(wxT("&"));
		incl.Add(wxT("|"));
		incl.Add(wxT("`"));
		incl.Add(wxT("?"));
		incl.Add(wxT("$"));

		wxTextValidator validator(wxFILTER_INCLUDE_CHAR_LIST);
		validator.SetIncludes(incl);
		txtName->SetValidator(validator);

		AddType(wxT(" "), 0);
		cbLeftType->Append(wxT(" "));
		cbRightType->Append(wxT(" "));
		FillDatatype(cbLeftType, cbRightType, false);
	}

	return dlgProperty::Go(modal);
}
Exemplo n.º 5
0
int dlgColumn::Go(bool modal)
{
	if (connection->BackendMinimumVersion(8, 4))
	{
		securityPage->SetConnection(connection);

		if (securityPage->cbGroups)
		{
			// Fetch Groups Information
			for ( unsigned int index = 0; index < groups.Count();)
				securityPage->cbGroups->Append(wxT("group ") + groups[index++]);

			// Fetch Users Information
			if (settings->GetShowUsersForPrivileges())
			{
				securityPage->stGroup->SetLabel(_("Group/User"));
				dlgProperty::AddUsers(securityPage->cbGroups);
				Layout();
			}
		}
		securityPage->lbPrivileges->GetParent()->Layout();
	}

	if (connection->BackendMinimumVersion(8, 5))
	{
		cbVarname->Append(wxT("n_distinct"));
		cbVarname->Append(wxT("n_distinct_inherited"));
		cbVarname->SetSelection(0);
	}
	else
	{
		lstVariables->Enable(false);
		btnAdd->Enable(false);
		btnRemove->Enable(false);
		cbVarname->Enable(false);
		txtValue->Enable(false);
	}

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

	cbStorage->Enable(true);

	if (connection->BackendMinimumVersion(9, 1))
	{
		// fill collation combobox
		cbCollation->Append(wxEmptyString);
		pgSet *set = connection->ExecuteSet(
		                 wxT("SELECT nspname, collname\n")
		                 wxT("  FROM pg_collation c, pg_namespace n\n")
		                 wxT("  WHERE c.collnamespace=n.oid\n")
		                 wxT("  ORDER BY nspname, collname"));
		if (set)
		{
			while (!set->Eof())
			{
				wxString name = qtIdent(set->GetVal(wxT("nspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname")));
				cbCollation->Append(name);
				set->MoveNext();
			}
			delete set;
		}
		cbCollation->SetSelection(0);
	}
	else
		cbCollation->Disable();

	if (column)
	{
		// edit mode
		if (column->GetLength() > 0)
			txtLength->SetValue(NumToStr(column->GetLength()));
		if (column->GetPrecision() >= 0)
			txtPrecision->SetValue(NumToStr(column->GetPrecision()));
		txtDefault->SetValue(column->GetDefault());
		chkNotNull->SetValue(column->GetNotNull());
		txtAttstattarget->SetValue(NumToStr(column->GetAttstattarget()));

		wxString fullType = column->GetRawTypename();
		if (column->GetIsArray())
			fullType += wxT("[]");
		cbDatatype->Append(fullType);
		AddType(wxT("?"), column->GetAttTypId(), fullType);

		if (!column->IsReferenced())
		{
			wxString typeSql =
			    wxT("SELECT tt.oid, format_type(tt.oid,NULL) AS typname\n")
			    wxT("  FROM pg_cast\n")
			    wxT("  JOIN pg_type tt ON tt.oid=casttarget\n")
			    wxT(" WHERE castsource=") + NumToStr(column->GetAttTypId()) + wxT("\n");

			if (connection->BackendMinimumVersion(8, 0))
				typeSql += wxT("   AND castcontext IN ('i', 'a')");
			else
				typeSql += wxT("   AND castfunc=0");

			pgSetIterator set(connection, typeSql);

			while (set.RowsLeft())
			{
				if (set.GetVal(wxT("typname")) != column->GetRawTypename())
				{
					cbDatatype->Append(set.GetVal(wxT("typname")));
					AddType(wxT("?"), set.GetOid(wxT("oid")), set.GetVal(wxT("typname")));
				}
			}
		}
		if (cbDatatype->GetCount() <= 1)
			cbDatatype->Disable();

		cbDatatype->SetSelection(0);
		wxNotifyEvent ev;
		OnSelChangeTyp(ev);

		previousDefinition = GetDefinition();
		if (column->GetColNumber() < 0)  // Disable controls not valid for system columns
		{
			txtName->Disable();
			txtDefault->Disable();
			chkNotNull->Disable();
			txtLength->Disable();
			cbDatatype->Disable();
			txtAttstattarget->Disable();
			cbStorage->Disable();
			cbCollation->Disable();
		}
		else if (column->GetTable()->GetMetaType() == PGM_VIEW) // Disable controls not valid for view columns
		{
			txtName->Disable();
			chkNotNull->Disable();
			txtLength->Disable();
			cbDatatype->Disable();
			txtAttstattarget->Disable();
			cbStorage->Disable();
			cbCollation->Disable();
		}
		else if (column->GetTable()->GetMetaType() == GP_EXTTABLE) // Disable controls not valid for external table columns
		{
			txtName->Disable();
			chkNotNull->Disable();
			txtLength->Disable();
			cbDatatype->Disable();
			txtAttstattarget->Disable();
			txtDefault->Disable();
			cbStorage->Disable();
			cbCollation->Disable();
		}
		else if (table->GetOfTypeOid() > 0)
		{
			txtName->Disable();
			chkNotNull->Enable();
			txtLength->Disable();
			cbDatatype->Disable();
			txtAttstattarget->Enable();
			txtDefault->Enable();
			cbStorage->Enable();
			cbCollation->Disable();
		}

		cbStorage->SetValue(column->GetStorage());
		cbCollation->SetValue(column->GetCollation());

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

	}
	else
	{
		// create mode
		FillDatatype(cbDatatype, true, true);

		if (!table)
		{
			cbClusterSet->Disable();
			cbClusterSet = 0;
		}

		txtAttstattarget->Disable();
		cbStorage->Disable();
	}

	if (changedColumn)
		ApplyChangesToDlg();

	return dlgTypeProperty::Go(modal);
}
Exemplo n.º 6
0
int dlgForeignTable::Go(bool modal)
{
	seclabelPage->SetConnection(connection);
	seclabelPage->SetObject(foreigntable);
	this->Connect(EVT_SECLABELPANEL_CHANGE, wxCommandEventHandler(dlgForeignTable::OnChange));

	// Fill owner combobox
	if (!foreigntable)
		cbOwner->Append(wxT(""));
	AddGroups();
	AddUsers(cbOwner);

	// Fill datatype combobox
	FillDatatype(cbDatatype);

	// Initialize options listview and buttons
	lstOptions->AddColumn(_("Option"), 80);
	lstOptions->AddColumn(_("Value"), 40);
	txtOption->SetValue(wxT(""));
	txtValue->SetValue(wxT(""));
	btnAdd->Disable();
	btnRemove->Disable();

	if (foreigntable)
	{
		// Edit Mode
		cbForeignServer->SetValue(foreigntable->GetForeignServer());
		cbForeignServer->Disable();

		txtMembername->Enable(true);
		btnAddMember->Enable(true);
		btnChangeMember->Enable(false);
		btnRemoveMember->Enable(false);

		wxArrayString elements = foreigntable->GetTypesArray();
		wxString fullType, typeName, typeLength, typePrecision;
		size_t pos;
		size_t i;
		for (i = 0 ; i < elements.GetCount() ; i += 3)
		{
			lstMembers->AppendItem(0, elements.Item(i), elements.Item(i + 1), elements.Item(i + 2));

			fullType = elements.Item(i + 1);
			typeName = fullType;
			typeLength = wxEmptyString;
			typePrecision = wxEmptyString;

			if (fullType.Find(wxT("(")) > 0)
			{
				// there is at least a length
				typeName = fullType.BeforeFirst('(');
				if (fullType.Find(wxT(",")) > 0)
				{
					// there is also a precision
					typeLength = fullType.AfterFirst('(').BeforeFirst(',');
					typePrecision = fullType.AfterFirst(',').BeforeFirst(')');
				}
				else
					typeLength = fullType.AfterFirst('(').BeforeFirst(')');
			}

			for (pos = 0; pos < cbDatatype->GetCount() - 1; pos++)
			{
				if (cbDatatype->GetString(pos) == typeName)
				{
					memberTypes.Add(GetTypeInfo(pos));
					break;
				}
			}
			memberLengths.Add(typeLength);
			memberPrecisions.Add(typePrecision);
			memberNotNulls.Add(elements.Item(i + 2));
		}

		cbDatatype->Enable();
		txtLength->Enable();

		wxArrayString options = foreigntable->GetOptionsArray();
		wxString optionname, optionvalue;
		for (unsigned int index = 0; index < options.Count(); index += 2)
		{
			optionname = options.Item(index);
			optionvalue = options.Item(index + 1);
			lstOptions->AppendItem(optionname, optionvalue);
		}
	}
	else
	{
		// Create mode
		cbOwner->Append(wxEmptyString);
		cbOwner->Disable();

		pgSet *set = connection->ExecuteSet(
		                 wxT("SELECT srvname\n")
		                 wxT("  FROM pg_foreign_server\n")
		                 wxT("  ORDER BY srvname"));
		if (set)
		{
			while (!set->Eof())
			{
				wxString srvname = set->GetVal(wxT("srvname"));
				cbForeignServer->Append(srvname);
				set->MoveNext();
			}
			delete set;
		}
		cbForeignServer->SetSelection(0);
	}

	txtLength->SetValidator(numericValidator);

	return dlgTypeProperty::Go(modal);
}