Commits

Tuukka Norri  committed a2846eb

Added some checks to WHERE clause creation
- We should now get log messages for problematic NSPredicates.

  • Participants
  • Parent commits d5a99f1

Comments (0)

Files changed (3)

File Sources/BXPGQueryHandler.h

 
 
 BX_EXPORT NSString* kBXPGExceptionCollectAllNoneNotAllowed;
+BX_EXPORT NSString* kBXPGExceptionInternalInconsistency;
+
 
 @interface BXPGExceptionCollectAllNoneNotAllowed : NSException
 {
 @end
 
 
+@interface BXPGExceptionInternalInconsistency : NSException
+{
+}
+@end
+
+
 @interface BXPGQueryHandler : NSObject 
 {
 }

File Sources/BXPGQueryHandler.m

 #import "BXForeignKey.h"
 
 NSString* kBXPGExceptionCollectAllNoneNotAllowed = @"kBXPGExceptionCollectAllNoneNotAllowed";
+NSString* kBXPGExceptionInternalInconsistency = @"kBXPGExceptionInternalInconsistency";
 
 
 @implementation BXPGExceptionCollectAllNoneNotAllowed
 @end
 
 
+@implementation BXPGExceptionInternalInconsistency
+@end
+
+
 @implementation BXPGQueryHandler
 - (id) init
 {

File Sources/BXPredicateVisitor.m

 static NSString*
 Comparison1 (NSString* lval, NSString* operatorString, NSString* rval, NSComparisonPredicateModifier modifier)
 {
+	if (! (lval && rval && operatorString))
+		[BXPGExceptionInternalInconsistency raise: kBXPGExceptionInternalInconsistency format: nil];
+	
+	if (! (0 < [lval length] && 0 < [rval length] && 0 < [operatorString length]))
+		[BXPGExceptionInternalInconsistency raise: kBXPGExceptionInternalInconsistency format: nil];
+
 	NSString* format = @"%@ %@ %@";
 	if (NSDirectPredicateModifier != modifier)
 		format = @"%@ %@ (%@)";
 		{
 			retval.p_where_clause = nil;
 		}
+		@catch (BXPGExceptionInternalInconsistency* e) 
+		{
+			BXLogError (@"Unable to convert predicate: %@", [predicate predicateFormat]);
+			retval.p_where_clause = nil;
+		}
 	}
 	else
 	{