src/bin/pg_dump/pg_dump.c
static void
collectSecLabels(Archive *fout)
{
	PGresult   *res;
	PQExpBuffer query;
	int			i_label;
	int			i_provider;
	int			i_classoid;
	int			i_objoid;
	int			i_objsubid;
	int			ntups;
	int			i;
	DumpableObject *dobj;

	query = createPQExpBuffer();

	appendPQExpBufferStr(query,
						 "SELECT label, provider, classoid, objoid, objsubid "
						 "FROM pg_catalog.pg_seclabel "
						 "ORDER BY classoid, objoid, objsubid");

	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);

	/* Construct lookup table containing OIDs in numeric form */
	i_label = PQfnumber(res, "label");
	i_provider = PQfnumber(res, "provider");
	i_classoid = PQfnumber(res, "classoid");
	i_objoid = PQfnumber(res, "objoid");
	i_objsubid = PQfnumber(res, "objsubid");

	ntups = PQntuples(res);

	seclabels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
	nseclabels = 0;
	dobj = NULL;

	for (i = 0; i < ntups; i++)
	{
		CatalogId	objId;
		int			subid;

		objId.tableoid = atooid(PQgetvalue(res, i, i_classoid));
		objId.oid = atooid(PQgetvalue(res, i, i_objoid));
		subid = atoi(PQgetvalue(res, i, i_objsubid));

		/* We needn't remember labels that don't match any dumpable object */
		if (dobj == NULL ||
			dobj->catId.tableoid != objId.tableoid ||
			dobj->catId.oid != objId.oid)
			dobj = findObjectByCatalogId(objId);
		if (dobj == NULL)
			continue;

		/*
		 * Labels on columns of composite types are linked to the type's
		 * pg_class entry, but we need to set the DUMP_COMPONENT_SECLABEL flag
		 * in the type's own DumpableObject.
		 */
		if (subid != 0 && dobj->objType == DO_TABLE &&
			((TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
		{
			TypeInfo   *cTypeInfo;

			cTypeInfo = findTypeByOid(((TableInfo *) dobj)->reltype);
			if (cTypeInfo)
				cTypeInfo->dobj.components |= DUMP_COMPONENT_SECLABEL;
		}
		else
			dobj->components |= DUMP_COMPONENT_SECLABEL;

		seclabels[nseclabels].label = pg_strdup(PQgetvalue(res, i, i_label));
		seclabels[nseclabels].provider = pg_strdup(PQgetvalue(res, i, i_provider));
		seclabels[nseclabels].classoid = objId.tableoid;
		seclabels[nseclabels].objoid = objId.oid;
		seclabels[nseclabels].objsubid = subid;
		nseclabels++;
	}

	PQclear(res);
	destroyPQExpBuffer(query);
}
/*
 * collectSecLabels
 *
 * Construct a table of all security labels available for database objects;
 * also set the has-seclabel component flag for each relevant object.
 *
 * The table is sorted by classoid/objid/objsubid for speed in lookup.
 */
collectSecLabels
Construct a table of all security labels available for database objects;
also set the has-seclabel component flag for each relevant object.

The table is sorted by classoid/objid/objsubid for speed in lookup.
collectSecLabels Construct a table of all security labels available for database objects ; also set the has - seclabel component flag for each relevant object . The table is sorted by classoid / objid / objsubid for speed in lookup .
static void
collectSecLabels(Archive *fout)
{
	PGresult   *res;
	PQExpBuffer query;
	int			i_label;
	int			i_provider;
	int			i_classoid;
	int			i_objoid;
	int			i_objsubid;
	int			ntups;
	int			i;
	DumpableObject *dobj;
	query = createPQExpBuffer();
	appendPQExpBufferStr(query,
						 "SELECT label, provider, classoid, objoid, objsubid "
						 "FROM pg_catalog.pg_seclabel "
						 "ORDER BY classoid, objoid, objsubid");
	res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
	i_label = PQfnumber(res, "label");
	i_provider = PQfnumber(res, "provider");
	i_classoid = PQfnumber(res, "classoid");
	i_objoid = PQfnumber(res, "objoid");
	i_objsubid = PQfnumber(res, "objsubid");
	ntups = PQntuples(res);
	seclabels = (SecLabelItem *) pg_malloc(ntups * sizeof(SecLabelItem));
	nseclabels = 0;
	dobj = NULL;
	for (i = 0; i < ntups; i++)
	{
		CatalogId	objId;
		int			subid;
		objId.tableoid = atooid(PQgetvalue(res, i, i_classoid));
		objId.oid = atooid(PQgetvalue(res, i, i_objoid));
		subid = atoi(PQgetvalue(res, i, i_objsubid));
		if (dobj == NULL ||
			dobj->catId.tableoid != objId.tableoid ||
			dobj->catId.oid != objId.oid)
			dobj = findObjectByCatalogId(objId);
		if (dobj == NULL)
			continue;
		if (subid != 0 && dobj->objType == DO_TABLE &&
			((TableInfo *) dobj)->relkind == RELKIND_COMPOSITE_TYPE)
		{
			TypeInfo   *cTypeInfo;
			cTypeInfo = findTypeByOid(((TableInfo *) dobj)->reltype);
			if (cTypeInfo)
				cTypeInfo->dobj.components |= DUMP_COMPONENT_SECLABEL;
		}
		else
			dobj->components |= DUMP_COMPONENT_SECLABEL;
		seclabels[nseclabels].label = pg_strdup(PQgetvalue(res, i, i_label));
		seclabels[nseclabels].provider = pg_strdup(PQgetvalue(res, i, i_provider));
		seclabels[nseclabels].classoid = objId.tableoid;
		seclabels[nseclabels].objoid = objId.oid;
		seclabels[nseclabels].objsubid = subid;
		nseclabels++;
	}
	PQclear(res);
	destroyPQExpBuffer(query);
}
static void collectSecLabels ( Archive * fout ) { PGresult * res ; PQExpBuffer query ; int i_label ; int i_provider ; int i_classoid ; int i_objoid ; int i_objsubid ; int ntups ; int i ; DumpableObject * dobj ; query = createPQExpBuffer ( ) ; appendPQExpBufferStr ( query , " " " " " " ) ; res = ExecuteSqlQuery ( fout , query -> data , PGRES_TUPLES_OK ) ; i_label = PQfnumber ( res , " " ) ; i_provider = PQfnumber ( res , " " ) ; i_classoid = PQfnumber ( res , " " ) ; i_objoid = PQfnumber ( res , " " ) ; i_objsubid = PQfnumber ( res , " " ) ; ntups = PQntuples ( res ) ; seclabels = ( SecLabelItem * ) pg_malloc ( ntups * sizeof ( SecLabelItem ) ) ; nseclabels = 0 ; dobj = NULL ; for ( i = 0 ; i < ntups ; i ++ ) { CatalogId objId ; int subid ; objId . tableoid = atooid ( PQgetvalue ( res , i , i_classoid ) ) ; objId . oid = atooid ( PQgetvalue ( res , i , i_objoid ) ) ; subid = atoi ( PQgetvalue ( res , i , i_objsubid ) ) ; if ( dobj == NULL || dobj -> catId . tableoid != objId . tableoid || dobj -> catId . oid != objId . oid ) dobj = findObjectByCatalogId ( objId ) ; if ( dobj == NULL ) continue ; if ( subid != 0 && dobj -> objType == DO_TABLE && ( ( TableInfo * ) dobj ) -> relkind == RELKIND_COMPOSITE_TYPE ) { TypeInfo * cTypeInfo ; cTypeInfo = findTypeByOid ( ( ( TableInfo * ) dobj ) -> reltype ) ; if ( cTypeInfo ) cTypeInfo -> dobj . components |= DUMP_COMPONENT_SECLABEL ; } else dobj -> components |= DUMP_COMPONENT_SECLABEL ; seclabels [ nseclabels ] . label = pg_strdup ( PQgetvalue ( res , i , i_label ) ) ; seclabels [ nseclabels ] . provider = pg_strdup ( PQgetvalue ( res , i , i_provider ) ) ; seclabels [ nseclabels ] . classoid = objId . tableoid ; seclabels [ nseclabels ] . objoid = objId . oid ; seclabels [ nseclabels ] . objsubid = subid ; nseclabels ++ ; } PQclear ( res ) ; destroyPQExpBuffer ( query ) ; }
collectSecLabels
 Construct a table of all security labels available for database objects;
 also set the has-seclabel component flag for each relevant object.
collectSecLabels Construct a table of all security labels available for database objects ; also set the has - seclabel component flag for each relevant object .
/* Construct lookup table containing OIDs in numeric form */ /* We needn't remember labels that don't match any dumpable object */ /*
		 * Labels on columns of composite types are linked to the type's
		 * pg_class entry, but we need to set the DUMP_COMPONENT_SECLABEL flag
		 * in the type's own DumpableObject.
		 */