Commits

Tuukka Norri committed 062c759

Added a method for getting an error message for schema version mismatch

Comments (0)

Files changed (3)

Sources/BXPGCurrentCompatVersion.m.m4

 {
     return [[NSNumber alloc] initWithString: @"_bx_compat_version_"];
 }
-

Sources/BXPGInterface.h

     BXDatabaseContext* mContext; //Weak
 	NSMutableDictionary* mForeignKeys;
 	BXPGTransactionHandler* mTransactionHandler;
+	NSNumber* mFrameworkCompatVersion;
 	
 	NSMutableSet* mLockedObjects;
 	BOOL mLocking;
 - (NSNumber *) schemaVersion;
 - (NSNumber *) schemaCompatibilityVersion;
 - (NSNumber *) frameworkCompatibilityVersion;
+- (BOOL) checkSchemaCompatibility: (NSError **) error;
 @end
 
 

Sources/BXPGInterface.m

 #import "BXAttributeDescriptionPrivate.h"
 
 
-#define BXPG_COMPAT_VERSION_DEC         [NSDecimalNumber decimalNumberWithMantissa: 14 exponent: -2 isNegative: NO]
-
-
 static NSString* kBXPGLockerKey = @"BXPGLockerKey";
 static NSString* kBXPGWhereClauseKey = @"BXPGWhereClauseKey";
 static NSString* kBXPGParametersKey = @"BXPGParametersKey";
 	[mForeignKeys release];
 	[mTransactionHandler release];
 	[mLockedObjects release];
+	[mFrameworkCompatVersion release];
 	[super dealloc];
 }
 
 
 - (NSNumber *) frameworkCompatibilityVersion
 {
-	return BXPG_COMPAT_VERSION_DEC;
+	if (! mFrameworkCompatVersion)
+		mFrameworkCompatVersion = BXPGCopyCurrentCompatibilityVersionNumber ();
+	return mFrameworkCompatVersion;
+}
+
+- (BOOL) checkSchemaCompatibility: (NSError **) outError;
+{
+	ExpectR (outError, NO);
+	
+	BOOL retval = YES;
+	NSNumber* current = [self schemaCompatibilityVersion];
+	NSNumber* builtWith = [self frameworkCompatibilityVersion];
+	if (NSOrderedDescending == [current compare: builtWith])
+	{
+		NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+								  @"The database version is newer than what this application is capable of handling", NSLocalizedFailureReasonErrorKey,
+								  @"Try upgrading your client application.", NSLocalizedRecoverySuggestionErrorKey,
+								  nil];
+		//FIXME: set domain and code.
+		NSError* error = [NSError errorWithDomain: @"" code: 1 userInfo: userInfo];
+		*outError = error;
+	}
+	return retval;
 }
 @end