Commits

Tuukka Norri committed ae1f4ed

Bug fixes
- Added missing fields to queries.
- Simplified validation methods; if the database interface sets the validation bit, the whole process becomes more clear.

Comments (0)

Files changed (5)

Sources/BXDatabaseContext.m

 - (NSArray *) executeFetchForEntity: (BXEntityDescription *) entity withPredicate: (NSPredicate *) predicate 
                     returningFaults: (BOOL) returnFaults updateAutomatically: (BOOL) shouldUpdate error: (NSError **) error
 {
-	[NSException raise: NSInvalidArgumentException format: @"Entity %@ can't access its relationships.", self];
     return [self executeFetchForEntity: entity withPredicate: predicate
                        returningFaults: returnFaults excludingFields: nil
                          returnedClass: (shouldUpdate ? [BXArrayProxy class] : Nil) 
 		//Check again in case someone else had the lock.
 		if (! [entity isValidated])
 		{
-			//Even if an entity has already been validated, allow a database interface to do something with it.
 			[mDatabaseInterface validateEntity: entity error: error];
 			if (nil == *error)
 			{
-				if (! [entity isValidated])
+				if ([entity hasCapability: kBXEntityCapabilityRelationships])
 				{
-					if (! [entity hasCapability: kBXEntityCapabilityRelationships])
-						[entity setValidated: YES];
-					else
-					{
-						[entity setRelationships: nil];
-						NSDictionary* relationships = [mDatabaseInterface relationshipsForEntity: entity error: error];
-						if (nil == *error)
-						{
-							[entity setRelationships: relationships];
-							[entity setValidated: YES];
-						}
-						
-						if ([entity isValidated])
-							[mRelationships addObjectsFromArray: [[entity relationshipsByName] allValues]];
-					}			
-				}
+					[entity setRelationships: nil];
+					NSDictionary* relationships = [mDatabaseInterface relationshipsForEntity: entity error: error];
+					if (nil == *error)
+						[entity setRelationships: relationships];
+					
+					if ([entity isValidated])
+						[mRelationships addObjectsFromArray: [[entity relationshipsByName] allValues]];
+				}			
 			}
 		}
 		

Sources/BXEntityDescription.m

 /** Whether this entity is marked as a view or not. */
 - (BOOL) isView
 {
-    return mFlags & kBXEntityIsView ? YES : NO;
+    return (mFlags & kBXEntityIsView) ? YES : NO;
 }
 
 - (NSComparisonResult) caseInsensitiveCompare: (BXEntityDescription *) anotherEntity
  */
 - (BOOL) isValidated
 {
-	return mFlags & kBXEntityIsValidated ? YES : NO;
+	return (mFlags & kBXEntityIsValidated) ? YES : NO;
 }
 
 /**
 
 - (BOOL) isEnabled
 {
-	return mFlags & kBXEntityIsEnabled ? YES : NO;
+	return (mFlags & kBXEntityIsEnabled) ? YES : NO;
 }
 @end
 

Sources/BXPGDatabaseDescription.m

 	if ([self hasBaseTenSchema])
 	{
 		queryString = 
-		@"SELECT c.oid AS oid, c.relnamespace AS schemaoid, c.relacl, c.relowner, c.relkind, r.rolname, baseten.isobservingcompatible (c.oid) AS isenabled "
-		" FROM pg_class c, pg_namespace n, pg_roles r "
-		" WHERE c.relowner = r.oid AND c.relnamespace = n.oid AND c.relname = $1 AND n.nspname = $2";		
+		@"SELECT c.oid AS oid, c.relnamespace AS schemaoid, c.relname, n.nspname, "
+		"   c.relacl, c.relowner, c.relkind, r.rolname, baseten.isobservingcompatible (c.oid) AS isenabled "
+		"  FROM pg_class c, pg_namespace n, pg_roles r "
+		"  WHERE c.relowner = r.oid AND c.relnamespace = n.oid AND c.relname = $1 AND n.nspname = $2";		
 	}
 	else
 	{
 		queryString = 
-		@"SELECT c.oid AS oid, c.relnamespace AS schemaoid, c.relacl, c.relowner, c.relkind, r.rolname, false AS isenabled "
-		" FROM pg_class c, pg_namespace n, pg_roles r "
-		" WHERE c.relowner = r.oid AND c.relnamespace = n.oid AND c.relname = $1 AND n.nspname = $2";		
+		@"SELECT c.oid AS oid, c.relnamespace AS schemaoid, c.relname, n.nspname, "
+		"   c.relacl, c.relowner, c.relkind, r.rolname, false AS isenabled "
+		"  FROM pg_class c, pg_namespace n, pg_roles r "
+		"  WHERE c.relowner = r.oid AND c.relnamespace = n.oid AND c.relname = $1 AND n.nspname = $2";		
 	}
 	return queryString;
 }
 	if ([self hasBaseTenSchema])
 	{
 		queryString = @"SELECT c.oid AS oid, c.relnamespace AS schemaoid, c.relname, n.nspname, "
-		" c.relacl, c.relowner, c.relkind, r.rolname, baseten.isobservingcompatible (c.oid) AS isenabled "
+		"  c.relacl, c.relowner, c.relkind, r.rolname, baseten.isobservingcompatible (c.oid) AS isenabled "
 		" FROM pg_class c, pg_namespace n, pg_roles r "
 		" WHERE c.relowner = r.oid AND c.relnamespace = n.oid AND c.oid = ANY ($1)";
 	}
 	else
 	{
 		queryString = @"SELECT c.oid AS oid, c.relnamespace AS schemaoid, c.relname, n.nspname, "
-		" c.relacl, c.relowner, c.relkind, r.rolname, false AS isenabled "
+		"  c.relacl, c.relowner, c.relkind, r.rolname, false AS isenabled "
 		" FROM pg_class c, pg_namespace n, pg_roles r "
 		" WHERE c.relowner = r.oid AND c.relnamespace = n.oid AND c.oid = ANY ($1)";
 	}

Sources/BXPGInterface.m

 	{
 		if (! [entity isValidated])
 		{
+			[entity setValidated: YES];
+			
 			//If attributes exists, it only contains primary key fields but we haven't received them from the database.
 			NSMutableDictionary* attributes = ([[[entity attributesByName] mutableCopy] autorelease] ?: [NSMutableDictionary dictionary]);
 			

common-xcconfig/release.xcconfig

 //ARCHS = ppc i386 ppc64 x86_64
+//FIXME: doesn't work for iPhone
 ARCHS = ppc i386
 DEPLOYMENT_POSTPROCESSING = YES
 GCC_DEBUGGING_SYMBOLS =