Esempio n. 1
0
wxString pgConn::SystemNamespaceRestriction(const wxString &nsp)
{
	if (reservedNamespaces.IsEmpty())
	{
		reservedNamespaces = wxT("'information_schema'");

		if (GetIsEdb())
			reservedNamespaces += wxT(", 'sys'");

		pgSet *set = ExecuteSet(
		                 wxT("SELECT nspname FROM pg_namespace nsp\n")
		                 wxT("  JOIN pg_proc pr ON pronamespace=nsp.oid\n")
		                 wxT(" WHERE proname IN ('slonyversion')"));
		if (set)
		{
			while (!set->Eof())
			{
				reservedNamespaces += wxT(", ") + qtDbString(set->GetVal(wxT("nspname")));
				set->MoveNext();
			}
			delete set;
		}
	}

	if (BackendMinimumVersion(8, 1))
		return wxT("(") + nsp + wxT(" NOT LIKE E'pg\\_%' AND ") + nsp + wxT(" NOT in (") + reservedNamespaces + wxT("))");
	else
		return wxT("(") + nsp + wxT(" NOT LIKE 'pg\\_%' AND ") + nsp + wxT(" NOT in (") + reservedNamespaces + wxT("))");
}
Esempio n. 2
0
void pgDatabase::UpdateDefaultSchema()
{
	searchPath = connection()->ExecuteScalar(wxT("SHOW search_path"));

	if (!searchPath.IsEmpty())
	{
		wxStringTokenizer tk(searchPath, wxT(","));
		pgSet *set = ExecuteSet(wxT("SELECT nspname, session_user=nspname AS isuser FROM pg_namespace"));
		if (set)
		{
			while (tk.HasMoreTokens())
			{
				wxString str = tk.GetNextToken();
				str.Strip(wxString::both);

				if (str.IsEmpty())
					continue;
				long row;
				for (row = 1 ; row <= set->NumRows() ; row++)
				{
					set->Locate(row);
					defaultSchema = set->GetVal(wxT("nspname"));
					if (str == defaultSchema ||
					        ((str == wxT("$user") || str == wxT("\"$user\"")) && set->GetBool(wxT("isuser"))))
					{
						delete set;
						return;
					}
				}
			}
			delete set;
		}
	}
	defaultSchema = wxEmptyString;
}
Esempio n. 3
0
// Check if, TABLE (tblname) has column with name colname
bool pgConn::TableHasColumn(wxString schemaname, wxString tblname, const wxString &colname)
{
	//
	// SELECT a.attname
	// FROM pg_catalog.pg_attribute a
	// WHERE a.attrelid = (SELECT c.oid
	//                     FROM pg_catalog.pg_class c
	//                          LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
	//                     WHERE c.relname ~ '^(TABLENAME)$' AND
	//                           pg_catalog.pg_table_is_visible(c.oid) AND
	//                           n.nspname ~ '^(SCHEMANAME)$') AND
	//       a.attnum > 0 AND NOT a.attisdropped
	// ORDER BY a.attnum
	//

	if (tblname.IsEmpty() || colname.IsEmpty())
		return false;

	if (schemaname.IsEmpty())
		schemaname = wxT("public");

	if (this && GetStatus() == PGCONN_OK)
	{
		tblname.Replace(wxT("\\"), wxT("\\\\"));
		tblname.Replace(wxT("'"), wxT("''"));
		schemaname.Replace(wxT("\\"), wxT("\\\\"));
		schemaname.Replace(wxT("'"), wxT("''"));

		wxString sql
		    = wxT("SELECT a.attname AS colname FROM pg_catalog.pg_attribute a ") \
		      wxT("WHERE a.attrelid = (SELECT c.oid FROM pg_catalog.pg_class c ") \
		      wxT("                    LEFT JOIN pg_catalog.pg_namespace n ON ") \
		      wxT("                                    n.oid = c.relnamespace ") \
		      wxT("                    WHERE c.relname ~ '^(") + tblname + wxT(")$' AND ") \
		      wxT("                          n.nspname ~ '^(") + schemaname + wxT(")$') AND ") \
		      wxT("      a.attnum > 0 AND NOT a.attisdropped ") \
		      wxT("ORDER BY a.attnum");

		pgSet *set = ExecuteSet(sql);
		if (set)
		{
			while (!set->Eof())
			{
				if (set->GetVal(wxT("colname")) == colname)
				{
					delete set;
					return true;
				}
				set->MoveNext();
			}
		}
		delete set;
	}

	return false;
}
Esempio n. 4
0
void pgTrigger::ReadColumnDetails()
{
	if (!expandedKids && GetLanguage() != wxT("edbspl"))
	{
		expandedKids = true;

		if (GetConnection()->BackendMinimumVersion(8, 5))
		{
			pgSet *res = ExecuteSet(
			                 wxT("SELECT attname\n")
			                 wxT("FROM pg_attribute,\n")
			                 wxT("(SELECT tgrelid, unnest(tgattr) FROM pg_trigger\n")
			                 wxT(" WHERE oid=") + GetOidStr() + wxT(") AS columns(tgrelid, colnum)\n")
			                 wxT("WHERE colnum=attnum AND tgrelid=attrelid"));

			// Allocate memory to store column def
			if (res->NumRows() > 0) columnList.Alloc(res->NumRows());

			long i = 1;
			columns = wxT("");
			quotedColumns = wxT("");

			while (!res->Eof())
			{
				if (i > 1)
				{
					columns += wxT(", ");
					quotedColumns += wxT(", ");
				}

				columns += res->GetVal(wxT("attname"));
				quotedColumns += qtIdent(res->GetVal(wxT("attname")));
				columnList.Add(res->GetVal(wxT("attname")));

				i++;
				res->MoveNext();
			}
		}
		else
		{
			columns = wxT("");
			quotedColumns = wxT("");
		}
	}
}
void pgSequence::UpdateValues()
{
    pgSet *sequence=ExecuteSet(
        wxT("SELECT last_value, min_value, max_value, cache_value, is_cycled, increment_by, is_called\n")
        wxT("  FROM ") + GetQuotedFullIdentifier());
    if (sequence)
    {
        lastValue = sequence->GetLongLong(wxT("last_value"));
        minValue = sequence->GetLongLong(wxT("min_value"));
        maxValue = sequence->GetLongLong(wxT("max_value"));
        cacheValue = sequence->GetLongLong(wxT("cache_value"));
        increment = sequence->GetLongLong(wxT("increment_by"));
        cycled = sequence->GetBool(wxT("is_cycled"));
        called = sequence->GetBool(wxT("is_called"));

        delete sequence;
    }
}
Esempio n. 6
0
bool pgConn::HasFeature(int featureNo, bool forceCheck)
{
	if (!features[FEATURE_INITIALIZED] || forceCheck)
	{
		features[FEATURE_INITIALIZED] = true;

		wxString sql =
		    wxT("SELECT proname, pronargs, proargtypes[0] AS arg0, proargtypes[1] AS arg1, proargtypes[2] AS arg2\n")
		    wxT("  FROM pg_proc\n")
		    wxT("  JOIN pg_namespace n ON n.oid=pronamespace\n")
		    wxT(" WHERE proname IN ('pg_tablespace_size', 'pg_file_read', 'pg_logfile_rotate',")
		    wxT(                  " 'pg_postmaster_starttime', 'pg_terminate_backend', 'pg_reload_conf',")
		    wxT(                  " 'pgstattuple', 'pgstatindex')\n")
		    wxT("   AND nspname IN ('pg_catalog', 'public')");

		pgSet *set = ExecuteSet(sql);

		if (set)
		{
			while (!set->Eof())
			{
				wxString proname = set->GetVal(wxT("proname"));
				long pronargs = set->GetLong(wxT("pronargs"));

				if (proname == wxT("pg_tablespace_size") && pronargs == 1 && set->GetLong(wxT("arg0")) == 26)
					features[FEATURE_SIZE] = true;
				else if (proname == wxT("pg_file_read") && pronargs == 3 && set->GetLong(wxT("arg0")) == 25
				         && set->GetLong(wxT("arg1")) == 20 && set->GetLong(wxT("arg2")) == 20)
					features[FEATURE_FILEREAD] = true;
				else if (proname == wxT("pg_logfile_rotate") && pronargs == 0)
					features[FEATURE_ROTATELOG] = true;
				else if (proname == wxT("pg_postmaster_starttime") && pronargs == 0)
					features[FEATURE_POSTMASTER_STARTTIME] = true;
				else if (proname == wxT("pg_terminate_backend") && pronargs == 1 && set->GetLong(wxT("arg0")) == 23)
					features[FEATURE_TERMINATE_BACKEND] = true;
				else if (proname == wxT("pg_reload_conf") && pronargs == 0)
					features[FEATURE_RELOAD_CONF] = true;
				else if (proname == wxT("pgstattuple") && pronargs == 1 && set->GetLong(wxT("arg0")) == 25)
					features[FEATURE_PGSTATTUPLE] = true;
				else if (proname == wxT("pgstatindex") && pronargs == 1 && set->GetLong(wxT("arg0")) == 25)
					features[FEATURE_PGSTATINDEX] = true;

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

		// Check for EDB function parameter default support
		wxString defCol = wxT("'proargdefaults'");

		if (EdbMinimumVersion(8, 3) && !EdbMinimumVersion(8, 4))
			defCol = wxT("'proargdefvals'");

		wxString hasFuncDefs = ExecuteScalar(wxT("SELECT count(*) FROM pg_attribute WHERE attrelid = 'pg_catalog.pg_proc'::regclass AND attname = ") + defCol);
		if (hasFuncDefs == wxT("1"))
			features[FEATURE_FUNCTION_DEFAULTS] = true;
		else
			features[FEATURE_FUNCTION_DEFAULTS] = false;
	}

	if (featureNo <= FEATURE_INITIALIZED || featureNo >= FEATURE_LAST)
		return false;
	return features[featureNo];
}
Esempio n. 7
0
bool pgConn::Initialize()
{
	// Set client encoding to Unicode/Ascii, Datestyle to ISO, and ask for notices.
	if (PQstatus(conn) == CONNECTION_OK)
	{
		connStatus = PGCONN_OK;
		PQsetNoticeProcessor(conn, pgNoticeProcessor, this);

		wxString sql = wxT("SET DateStyle=ISO;\nSET client_min_messages=notice;\n");
		if (BackendMinimumVersion(9, 0))
			sql += wxT("SET bytea_output=escape;\n");

		sql += wxT("SELECT oid, pg_encoding_to_char(encoding) AS encoding, datlastsysoid\n")
		       wxT("  FROM pg_database WHERE ");

		if (save_oid)
			sql += wxT("oid = ") + NumToStr(save_oid);
		else
		{
			// Note, can't use qtDbString here as we don't know the server version yet.
			wxString db = save_database;
			db.Replace(wxT("\\"), wxT("\\\\"));
			db.Replace(wxT("'"), wxT("''"));
			sql += wxT("datname=") + qtString(db);
		}

		pgSet *set = ExecuteSet(sql);
		if (set)
		{
			if (set->ColNumber(wxT("\"datlastsysoid\"")) >= 0)
				needColQuoting = true;

			lastSystemOID = set->GetOid(wxT("datlastsysoid"));
			dbOid = set->GetOid(wxT("oid"));
			wxString encoding = set->GetVal(wxT("encoding"));

			if (encoding != wxT("SQL_ASCII") && encoding != wxT("MULE_INTERNAL"))
			{
				encoding = wxT("UNICODE");
				conv = &wxConvUTF8;
			}
			else
				conv = &wxConvLibc;

			wxLogInfo(wxT("Setting client_encoding to '%s'"), encoding.c_str());
			if (PQsetClientEncoding(conn, encoding.ToAscii()))
			{
				wxLogError(wxT("%s"), GetLastError().c_str());
			}

			delete set;

			// Switch to the requested default role if supported by backend
			if (dbRole != wxEmptyString && BackendMinimumVersion(8, 1))
			{
				sql = wxT("SET ROLE TO ");
				sql += qtIdent(dbRole);

				pgSet *set = ExecuteSet(sql);

				if (set)
					delete set;
				else
					return false;
			}
			return true;
		}
	}
	return false;
}
Esempio n. 8
0
void pgType::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	wxString query;
	wxString collation;

	if (!expandedKids)
	{
		expandedKids = true;
		if (GetTypeClass() == TYPE_COMPOSITE)
		{
			query = wxT("SELECT attname, format_type(t.oid,NULL) AS typname, attndims, atttypmod, nsp.nspname,\n")
			        wxT("       (SELECT COUNT(1) from pg_type t2 WHERE t2.typname=t.typname) > 1 AS isdup");
			if (GetConnection()->BackendMinimumVersion(9, 1))
				query += wxT(",\n       collname, nspc.nspname as collnspname");
			query += wxT("\n  FROM pg_attribute att\n")
			         wxT("  JOIN pg_type t ON t.oid=atttypid\n")
			         wxT("  JOIN pg_namespace nsp ON t.typnamespace=nsp.oid\n")
			         wxT("  LEFT OUTER JOIN pg_type b ON t.typelem=b.oid\n");
			if (GetConnection()->BackendMinimumVersion(9, 1))
				query += wxT("  LEFT OUTER JOIN pg_collation c ON att.attcollation=c.oid\n")
				         wxT("  LEFT OUTER JOIN pg_namespace nspc ON c.collnamespace=nspc.oid\n");
			query += wxT(" WHERE att.attrelid=") + NumToStr(relOid) + wxT("\n")
			         wxT(" ORDER by attnum");
			pgSet *set = ExecuteSet(query);
			if (set)
			{
				int anzvar = 0;
				while (!set->Eof())
				{
					wxString element;
					if (anzvar++)
					{
						typesList += wxT(", ");
						quotedTypesList += wxT(",\n    ");
					}
					typesList += set->GetVal(wxT("attname")) + wxT(" ");
					typesArray.Add(set->GetVal(wxT("attname")));
					quotedTypesList += qtIdent(set->GetVal(wxT("attname"))) + wxT(" ");

					pgDatatype dt(set->GetVal(wxT("nspname")), set->GetVal(wxT("typname")),
					              set->GetBool(wxT("isdup")), set->GetLong(wxT("attndims")) > 0, set->GetLong(wxT("atttypmod")));

					wxString nspname = set->GetVal(wxT("nspname"));

					typesList += dt.GetSchemaPrefix(GetDatabase()) + dt.FullName();
					typesArray.Add(dt.GetSchemaPrefix(GetDatabase()) + dt.FullName());
					quotedTypesList += dt.GetQuotedSchemaPrefix(GetDatabase()) + dt.QuotedFullName();

					if (GetConnection()->BackendMinimumVersion(9, 1))
					{
						if (set->GetVal(wxT("collname")).IsEmpty() || (set->GetVal(wxT("collname")) == wxT("default") && set->GetVal(wxT("collnspname")) == wxT("pg_catalog")))
							collation = wxEmptyString;
						else
						{
							collation = qtIdent(set->GetVal(wxT("collnspname"))) + wxT(".") + qtIdent(set->GetVal(wxT("collname")));
							quotedTypesList += wxT(" COLLATE ") + collation;
						}
						collationsArray.Add(collation);
					}
					typesArray.Add(collation);

					set->MoveNext();
				}
				delete set;
			}
		}
		else if (GetTypeClass() == TYPE_ENUM)
		{
			query = wxT("SELECT enumlabel\n")
			        wxT("  FROM pg_enum\n")
			        wxT(" WHERE enumtypid=") + GetOidStr() + wxT("\n");
			if (GetConnection()->BackendMinimumVersion(9, 1))
				query += wxT(" ORDER by enumsortorder");
			else
				query += wxT(" ORDER by oid");
			pgSet *set = ExecuteSet(query);
			if (set)
			{
				int anzvar = 0;
				while (!set->Eof())
				{
					wxString element;
					if (anzvar++)
					{
						labelList += wxT(", ");
						quotedLabelList += wxT(",\n    ");
					}
					labelList += set->GetVal(wxT("enumlabel"));
					labelArray.Add(set->GetVal(wxT("enumlabel")));
					quotedLabelList += GetDatabase()->connection()->qtDbString(set->GetVal(wxT("enumlabel")));

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

	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Owner"), GetOwner());
		properties->AppendItem(_("Alias"), GetAlias());
		if (GetTypeClass() == TYPE_COMPOSITE)
		{
			properties->AppendItem(_("Members"), GetTypesList());
		}
		if (GetTypeClass() == TYPE_ENUM)
		{
			properties->AppendItem(_("Labels"), GetLabelList());
		}
		else
		{
			properties->AppendItem(_("Alignment"), GetAlignment());
			properties->AppendItem(_("Internal length"), GetInternalLength());
			properties->AppendItem(_("Default"), GetDefault());
			properties->AppendItem(_("Passed by Value?"), BoolToYesNo(GetPassedByValue()));
			if (!GetElement().IsEmpty())
			{
				properties->AppendItem(_("Element"), GetElement());
				properties->AppendItem(_("Delimiter"), GetDelimiter());
			}
			properties->AppendItem(_("Input function"), GetInputFunction());
			properties->AppendItem(_("Output function"), GetOutputFunction());
			if (GetConnection()->BackendMinimumVersion(7, 4))
			{
				properties->AppendItem(_("Receive function"), GetReceiveFunction());
				properties->AppendItem(_("Send function"), GetSendFunction());
			}
			if (GetConnection()->BackendMinimumVersion(8, 3))
			{
				if (GetTypmodinFunction().Length() > 0)
					properties->AppendItem(_("Typmod in function"), GetTypmodinFunction());
				if (GetTypmodoutFunction().Length() > 0)
					properties->AppendItem(_("Typmod out function"), GetTypmodoutFunction());
			}
			properties->AppendItem(_("Storage"), GetStorage());
			if (GetConnection()->BackendMinimumVersion(9, 1))
				properties->AppendItem(_("Collatable?"), BoolToYesNo(GetCollatable()));
		}
		properties->AppendYesNoItem(_("System type?"), GetSystemObject());
		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));
				}
			}
		}
	}
}
Esempio n. 9
0
void pgOperatorClass::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (!expandedKids)
	{
		expandedKids = true;

		pgSet *set;

		if (!GetConnection()->BackendMinimumVersion(8, 3))
		{
			set = ExecuteSet(
			          wxT("SELECT amopstrategy, amopreqcheck, oprname, lt.typname as lefttype, rt.typname as righttype\n")
			          wxT("  FROM pg_amop am\n")
			          wxT("  JOIN pg_operator op ON amopopr=op.oid\n")
			          wxT("  LEFT OUTER JOIN pg_type lt ON lt.oid=oprleft\n")
			          wxT("  LEFT OUTER JOIN pg_type rt ON rt.oid=oprright\n")
			          wxT(" WHERE amopclaid=") + GetOidStr() + wxT("\n")
			          wxT(" ORDER BY amopstrategy"));
		}
		else if (!GetConnection()->BackendMinimumVersion(8, 4))
		{
			set = ExecuteSet(
			          wxT("SELECT amopstrategy, amopreqcheck, oprname, lt.typname as lefttype, rt.typname as righttype\n")
			          wxT("  FROM pg_amop am\n")
			          wxT("  JOIN pg_operator op ON amopopr=op.oid\n")
			          wxT("  JOIN pg_opfamily opf ON amopfamily = opf.oid\n")
			          wxT("  JOIN pg_opclass opc ON opf.oid = opcfamily\n")
			          wxT("  LEFT OUTER JOIN pg_type lt ON lt.oid=oprleft\n")
			          wxT("  LEFT OUTER JOIN pg_type rt ON rt.oid=oprright\n")
			          wxT(" WHERE opc.oid=") + GetOidStr() + wxT("\n")
			          wxT(" AND amopmethod = opf.opfmethod\n")
			          wxT(" AND amoplefttype = op.oprleft AND amoprighttype = op.oprright\n")
			          wxT(" ORDER BY amopstrategy"));
		}
		else
		{
			set = ExecuteSet(
			          wxT("SELECT amopstrategy, oprname, lt.typname as lefttype, rt.typname as righttype\n")
			          wxT("  FROM pg_amop am\n")
			          wxT("  JOIN pg_operator op ON amopopr=op.oid\n")
			          wxT("  JOIN pg_opfamily opf ON amopfamily = opf.oid\n")
			          wxT("  JOIN pg_opclass opc ON opf.oid = opcfamily\n")
			          wxT("  LEFT OUTER JOIN pg_type lt ON lt.oid=oprleft\n")
			          wxT("  LEFT OUTER JOIN pg_type rt ON rt.oid=oprright\n")
			          wxT(" WHERE opc.oid=") + GetOidStr() + wxT("\n")
			          wxT(" AND amopmethod = opf.opfmethod\n")
			          wxT(" AND amoplefttype = op.oprleft AND amoprighttype = op.oprright\n")
			          wxT(" ORDER BY amopstrategy"));
		}

		if (set)
		{
			while (!set->Eof())
			{
				wxString str = set->GetVal(wxT("amopstrategy")) + wxT("  ") + set->GetVal(wxT("oprname"));
				wxString lt = set->GetVal(wxT("lefttype"));
				wxString rt = set->GetVal(wxT("righttype"));
				if (lt == GetInType() && (rt.IsEmpty() || rt == GetInType()))
					lt = wxEmptyString;
				if (rt == GetInType() && lt.IsEmpty())
					rt = wxEmptyString;

				if (!lt.IsEmpty() || !rt.IsEmpty())
				{
					str += wxT("(");
					if (!lt.IsEmpty())
					{
						str += lt;
						if (!rt.IsEmpty())
							str += wxT(", ");
					}
					if (!rt.IsEmpty())
						str += rt;
					str += wxT(")");
				}

				if (!GetConnection()->BackendMinimumVersion(8, 4))
				{
					if (set->GetBool(wxT("amopreqcheck")))
						str += wxT(" RECHECK");
				}

				operators.Add(str);
				set->MoveNext();
			}
			delete set;
		}

		if (!GetConnection()->BackendMinimumVersion(8, 3))
		{
			set = ExecuteSet(
			          wxT("SELECT amprocnum, amproc::oid\n")
			          wxT("  FROM pg_amproc am\n")
			          wxT(" WHERE amopclaid=") + GetOidStr() + wxT("\n")
			          wxT(" ORDER BY amprocnum"));
		}
		else
		{
			set = ExecuteSet(
			          wxT("SELECT amprocnum, amproc::oid\n")
			          wxT("  FROM pg_amproc am\n")
			          wxT("  JOIN pg_opfamily opf ON amprocfamily = opf.oid\n")
			          wxT("  JOIN pg_opclass opc ON opf.oid = opcfamily\n")
			          wxT(" WHERE opc.oid=") + GetOidStr() + wxT("\n")
			          wxT(" AND amproclefttype = opc.opcintype AND amprocrighttype = opc.opcintype\n")
			          wxT(" ORDER BY amprocnum"));
		}

		if (set)
		{
			while (!set->Eof())
			{
				wxString amproc = set->GetVal(wxT("amproc"));
				functionOids.Add(amproc);

				// We won't build a PG_FUNCTIONS collection under OperatorClass, so we create
				// temporary function items
				pgFunction *function = functionFactory.AppendFunctions(this, GetSchema(), 0, wxT(" WHERE pr.oid=") + amproc);
				if (function)
				{
					functions.Add(set->GetVal(wxT("amprocnum")) + wxT("  ") + function->GetFullName());
					quotedFunctions.Add(set->GetVal(wxT("amprocnum")) + wxT("  ")
					                    + function->GetQuotedFullIdentifier() + wxT("(") + function->GetArgSigList() + wxT(")"));
					delete function;
				}

				set->MoveNext();
			}
			delete set;
		}
	}
	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Owner"), GetOwner());
		properties->AppendYesNoItem(_("Default?"), GetOpcDefault());
		properties->AppendItem(_("For type"), GetInType());
		properties->AppendItem(_("Access method"), GetAccessMethod());
		if (GetConnection()->BackendMinimumVersion(8, 3))
			properties->AppendItem(_("Family"), GetFamily());

		if (!GetKeyType().IsEmpty())
			properties->AppendItem(_("Storage"), GetKeyType());
		unsigned int i;
		for (i = 0 ; i < operators.Count() ; i++)
			properties->AppendItem(wxT("OPERATOR"), operators.Item(i));
		for (i = 0 ; i < functions.Count() ; i++)
			properties->AppendItem(wxT("FUNCTION"), functions.Item(i));
		properties->AppendYesNoItem(_("System operator class?"), GetSystemObject());
		if (GetConnection()->BackendMinimumVersion(7, 5))
			properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
	}
}
Esempio n. 10
0
void pgForeignTable::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	wxString constraint;

	if (!expandedKids)
	{
		expandedKids = true;
		pgSet *set = ExecuteSet(
		                 wxT("SELECT attname, format_type(t.oid,NULL) AS typname, attndims, atttypmod, nspname, attnotnull,\n")
		                 wxT("       (SELECT COUNT(1) from pg_type t2 WHERE t2.typname=t.typname) > 1 AS isdup\n")
		                 wxT("  FROM pg_attribute att\n")
		                 wxT("  JOIN pg_type t ON t.oid=atttypid\n")
		                 wxT("  JOIN pg_namespace nsp ON t.typnamespace=nsp.oid\n")
		                 wxT("  LEFT OUTER JOIN pg_type b ON t.typelem=b.oid\n")
		                 wxT(" WHERE att.attrelid=") + GetOidStr() + wxT("\n")
		                 wxT(" AND attnum>0\n")
		                 wxT(" ORDER by attnum"));
		if (set)
		{
			int anzvar = 0;
			while (!set->Eof())
			{
				pgDatatype dt(set->GetVal(wxT("nspname")), set->GetVal(wxT("typname")),
				              set->GetBool(wxT("isdup")), set->GetLong(wxT("attndims")) > 0, set->GetLong(wxT("atttypmod")));
				constraint = set->GetBool(wxT("attnotnull")) ? wxT("NOT NULL") : wxT("");

				if (anzvar++)
				{
					typesList += wxT(", ");
					quotedTypesList += wxT(",\n    ");
				}

				typesList += set->GetVal(wxT("attname")) + wxT(" ")
				             + dt.GetSchemaPrefix(GetDatabase()) + dt.FullName() + wxT(" ")
				             + constraint;

				quotedTypesList += qtIdent(set->GetVal(wxT("attname"))) + wxT(" ")
				                   + dt.GetQuotedSchemaPrefix(GetDatabase()) + dt.QuotedFullName() + wxT(" ")
				                   + constraint;

				typesArray.Add(set->GetVal(wxT("attname")));
				typesArray.Add(dt.GetSchemaPrefix(GetDatabase()) + dt.FullName());
				typesArray.Add(constraint);

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

	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), GetOid());
		properties->AppendItem(_("Owner"), GetOwner());
		properties->AppendItem(_("Server"), GetForeignServer());
		properties->AppendItem(_("Columns"), GetQuotedTypesList());
		properties->AppendItem(_("Options"), GetOptionsList());
		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));
				}
			}
		}
	}
}
Esempio n. 11
0
void pgForeignKey::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane)
{
	if (!expandedKids)
	{
		expandedKids = true;

		wxStringTokenizer c1l(GetConkey(), wxT(","));
		wxStringTokenizer c2l(GetConfkey(), wxT(","));
		wxString c1, c2;

		// resolve column names
		while (c1l.HasMoreTokens())
		{
			c1 = c1l.GetNextToken();
			c2 = c2l.GetNextToken();
			pgSet *set = ExecuteSet(
			                 wxT("SELECT a1.attname as conattname, a2.attname as confattname\n")
			                 wxT("  FROM pg_attribute a1, pg_attribute a2\n")
			                 wxT(" WHERE a1.attrelid=") + GetTableOidStr() + wxT(" AND a1.attnum=") + c1 + wxT("\n")
			                 wxT("   AND a2.attrelid=") + GetRelTableOidStr() + wxT(" AND a2.attnum=") + c2);
			if (set)
			{
				if (!fkColumns.IsNull())
				{
					fkColumns += wxT(", ");
					refColumns += wxT(", ");
					quotedFkColumns += wxT(", ");
					quotedRefColumns += wxT(", ");
				}
				fkColumns += set->GetVal(0);
				refColumns += set->GetVal(1);
				quotedFkColumns += qtIdent(set->GetVal(0));
				quotedRefColumns += qtIdent(set->GetVal(1));
				delete set;
			}
		}
		wxTreeItemId item = browser->GetItemParent(GetId());
		while (item)
		{
			pgTable *table = (pgTable *)browser->GetObject(item);
			if (table->IsCreatedBy(tableFactory))
			{
				coveringIndex = table->GetCoveringIndex(browser, fkColumns);
				break;
			}
			item = browser->GetItemParent(item);
		}
	}

	if (properties)
	{
		CreateListColumns(properties);

		properties->AppendItem(_("Name"), GetName());
		properties->AppendItem(_("OID"), NumToStr(GetOid()));
		properties->AppendItem(_("Child columns"), GetFkColumns());
		properties->AppendItem(_("References"), GetReferences()
		                       + wxT("(") + GetRefColumns() + wxT(")"));

		properties->AppendItem(_("Covering index"), GetCoveringIndex());
		properties->AppendItem(_("Match type"), GetMatch());
		properties->AppendItem(_("On update"), GetOnUpdate());
		properties->AppendItem(_("On delete"), GetOnDelete());
		properties->AppendItem(_("Deferrable?"), BoolToYesNo(GetDeferrable()));
		if (GetDeferrable())
			properties->AppendItem(_("Initially?"),
			                       GetDeferred() ? wxT("DEFERRED") : wxT("IMMEDIATE"));
		if (GetDatabase()->BackendMinimumVersion(9, 1))
			properties->AppendItem(_("Valid?"), BoolToYesNo(GetValid()));
		properties->AppendItem(_("System foreign key?"), BoolToYesNo(GetSystemObject()));
		properties->AppendItem(_("Comment"), firstLineOnly(GetComment()));
	}
}