Commits

Tuukka Norri  committed 2c0b522

View metadata and immediate entity validation
- Added error parameter to various methods in BXPGInterface and elsewhere.
- Also added assertions to BXPGInterface to check that the error parameter has been set.
- Made some of the NSErrors safer to create.
- BXDatabaseContext now validates entities immediately.
- -entityForTable: methods in BXDatabaseContext require the error parameter from now on.
- BaseTen schema now contains a view, viewdependencies, which shows the relations to which views have references.
- PGTSTableInfo can now extract the information.
- Clarified BaseTenTests.sql a bit.
- Removed view and pkey metadata from unit tests.

  • Participants
  • Parent commits 57228ad
  • Branches PGTS

Comments (0)

Files changed (5)

File Framework/Sources/PGTSAbstractClassInfo.h

 - (void) addACLItem: (PGTSACLItem *) item;
 - (PGTSRoleDescription *) owner;
 - (void) setOwner: (PGTSRoleDescription *) anOwner;
+- (void) setKind: (char) kind;
 @end
 
 

File Framework/Sources/PGTSAbstractClassInfo.m

     }
 }
 
+- (void) setKind: (char) kind
+{
+    relkind = kind;
+}
+
 @end
 
 

File Framework/Sources/PGTSDatabaseInfo.m

     if (nil == rval)
     {
         NSString* queryString = 
-        @"SELECT c.oid AS oid, c.relnamespace AS schemaoid, c.relacl, c.relowner, r.rolname "
+        @"SELECT c.oid AS oid, c.relnamespace AS schemaoid, c.relacl, c.relowner, c.relkind, r.rolname "
         " FROM pg_class c, pg_namespace n, pg_roles r "
         " WHERE c.relowner = r.oid AND c.relname = $1 AND n.nspname = $2";
         PGTSResultSet* res = [connection executeQuery: queryString parameters: tableName, schemaName];
             [res advanceRow];
             rval = [self tableInfoForTableWithOid: [[res valueForKey: @"oid"] PGTSOidValue]];
             [rval setName: tableName];
+            [rval setKind: [[res valueForKey: @"relkind"] characterAtIndex: 0]];
             [rval setSchemaOid: [[res valueForKey: @"schemaoid"] PGTSOidValue]];
 
             PGTSRoleDescription* role = [[connection databaseInfo] roleNamed: [res valueForKey: @"rolname"]

File Framework/Sources/PGTSTableInfo.h

     NSMutableSet* foreignKeys;
     BOOL hasReferencingForeignKeys;
     NSMutableSet* referencingForeignKeys;
+
+    NSArray* relationOidsBasedOn;
 }
 
 - (void) setDatabase: (PGTSDatabaseInfo *) aDatabase;
 - (PGTSDatabaseInfo *) database;
 - (void) setUniqueIndexes: (NSArray *) anArray;
 - (void) setFieldCount: (unsigned int) anInt;
+- (void) setRelationOidsBasedOn: (NSArray *) anArray;
 
 - (NSSet *) foreignKeySetWithResult: (PGTSResultSet *) res selfAsSource: (BOOL) selfAsSource;
 @end
 - (NSArray *) allFields;
 - (NSSet *) foreignKeys;
 - (NSSet *) referencingForeignKeys;
+- (NSArray *) relationOidsBasedOn;
 @end

File Framework/Sources/PGTSTableInfo.m

     [schemaName release];
     [foreignKeys release];
     [referencingForeignKeys release];
+    [relationOidsBasedOn release];
     [super dealloc];
 }
 
     fieldCount = anInt;
 }
 
+- (NSArray *) relationOidsBasedOn
+{
+    return relationOidsBasedOn; 
+}
+
+- (void) setRelationOidsBasedOn: (NSArray *) aRelationOidsBasedOn
+{
+    if (relationOidsBasedOn != aRelationOidsBasedOn) 
+    {
+        [relationOidsBasedOn release];
+        relationOidsBasedOn = [aRelationOidsBasedOn retain];
+    }
+}
+
 - (NSSet *) foreignKeySetWithResult: (PGTSResultSet *) res selfAsSource: (BOOL) selfAsSource
 {
     PGTSTableInfo* src = nil;
         "c.conname AS name, "
         "c.conrelid AS oid, "           //Source table's OID
         "c.conkey AS sources, "         //Constrained columns
-        "c.confkey AS references "       //Referenced columns
+        "c.confkey AS references "      //Referenced columns
         "FROM pg_constraint c "
         "WHERE c.contype = 'f' AND "    //Foreign keys
         "c.confrelid = $1 ";            //Reference's OID
     return referencingForeignKeys;
 }
 
+- (NSArray *) relationOidsBasedOn
+{
+    if ('v' == [self kind] && nil == relationOidsBasedOn)
+    {
+        NSString* query = @"SELECT reloid FROM \"" PGTS_SCHEMA_NAME "\".viewdependencies WHERE viewoid = $1";
+        PGTSResultSet* res = [connection executeQuery: query parameters: PGTSOidAsObject ([self oid])];
+        NSMutableArray* oids = [NSMutableArray arrayWithCapacity: [res countOfRows]];
+        while (([res advanceRow]))
+            [oids addObject: [res valueForKey: @"reloid"]];
+        
+        [self setRelationOidsBasedOn: oids];
+    }
+    return relationOidsBasedOn;
+}
+
 @end