aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/dbcommands.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-08-09 16:45:16 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-08-09 16:45:16 +0000
commit4ab8e69094452286a5894f1b2b237304808f4391 (patch)
tree53d99383e8b52541832c510308f8d0ddb3bbc20f /src/backend/commands/dbcommands.c
parent65dc2e0d8c1200a63e5d293f0cfa95a836eb984c (diff)
downloadpostgresql-4ab8e69094452286a5894f1b2b237304808f4391.tar.gz
postgresql-4ab8e69094452286a5894f1b2b237304808f4391.zip
has_table_privilege spawns scions has_database_privilege, has_function_privilege,
has_language_privilege, has_schema_privilege to let SQL queries test all the new privilege types in 7.3. Also, add functions pg_table_is_visible, pg_type_is_visible, pg_function_is_visible, pg_operator_is_visible, pg_opclass_is_visible to test whether objects contained in schemas are visible in the current search path. Do some minor cleanup to centralize accesses to pg_database, as well.
Diffstat (limited to 'src/backend/commands/dbcommands.c')
-rw-r--r--src/backend/commands/dbcommands.c77
1 files changed, 76 insertions, 1 deletions
diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c
index d043d95b784..53c8391c0c5 100644
--- a/src/backend/commands/dbcommands.c
+++ b/src/backend/commands/dbcommands.c
@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.98 2002/08/05 03:29:16 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.99 2002/08/09 16:45:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -746,3 +746,78 @@ remove_dbdirs(const char *nominal_loc, const char *alt_loc)
return success;
}
+
+
+/*
+ * get_database_oid - given a database name, look up the OID
+ *
+ * Returns InvalidOid if database name not found.
+ *
+ * This is not actually used in this file, but is exported for use elsewhere.
+ */
+Oid
+get_database_oid(const char *dbname)
+{
+ Relation pg_database;
+ ScanKeyData entry[1];
+ HeapScanDesc scan;
+ HeapTuple dbtuple;
+ Oid oid;
+
+ /* There's no syscache for pg_database, so must look the hard way */
+ pg_database = heap_openr(DatabaseRelationName, AccessShareLock);
+ ScanKeyEntryInitialize(&entry[0], 0x0,
+ Anum_pg_database_datname, F_NAMEEQ,
+ CStringGetDatum(dbname));
+ scan = heap_beginscan(pg_database, SnapshotNow, 1, entry);
+
+ dbtuple = heap_getnext(scan, ForwardScanDirection);
+
+ /* We assume that there can be at most one matching tuple */
+ if (HeapTupleIsValid(dbtuple))
+ oid = HeapTupleGetOid(dbtuple);
+ else
+ oid = InvalidOid;
+
+ heap_endscan(scan);
+ heap_close(pg_database, AccessShareLock);
+
+ return oid;
+}
+
+/*
+ * get_database_owner - given a database OID, fetch the owner's usesysid.
+ *
+ * Errors out if database not found.
+ *
+ * This is not actually used in this file, but is exported for use elsewhere.
+ */
+Oid
+get_database_owner(Oid dbid)
+{
+ Relation pg_database;
+ ScanKeyData entry[1];
+ HeapScanDesc scan;
+ HeapTuple dbtuple;
+ int32 dba;
+
+ /* There's no syscache for pg_database, so must look the hard way */
+ pg_database = heap_openr(DatabaseRelationName, AccessShareLock);
+ ScanKeyEntryInitialize(&entry[0], 0x0,
+ ObjectIdAttributeNumber, F_OIDEQ,
+ ObjectIdGetDatum(dbid));
+ scan = heap_beginscan(pg_database, SnapshotNow, 1, entry);
+
+ dbtuple = heap_getnext(scan, ForwardScanDirection);
+
+ if (!HeapTupleIsValid(dbtuple))
+ elog(ERROR, "database %u does not exist", dbid);
+
+ dba = ((Form_pg_database) GETSTRUCT(dbtuple))->datdba;
+
+ heap_endscan(scan);
+ heap_close(pg_database, AccessShareLock);
+
+ /* XXX some confusion about whether userids are OID or int4 ... */
+ return (Oid) dba;
+}