From c7b5e880003153e599a452151ee1f3a3e40aff4c Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 7 Aug 2015 23:45:15 +0200 Subject: Added fallback code for server version identification. Good news: Sequel Pro can now connect to sphinxql server. Bad news: It will treat it like a MySQL 2 server (or whatever version of Sphinx is running) --- .../SPMySQLConnection Categories/Max Packet Size.m | 4 +++ .../SPMySQLConnection Categories/Server Info.m | 30 ++++++++++++++-------- .../SPMySQLFramework/Source/SPMySQLConnection.h | 2 +- .../SPMySQLFramework/Source/SPMySQLConnection.m | 10 ++++---- Source/SPServerSupport.m | 8 +++--- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Max Packet Size.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Max Packet Size.m index 4f1f1b7b..dc453624 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Max Packet Size.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Max Packet Size.m @@ -108,6 +108,10 @@ // Make a standard query to the server to retrieve the information SPMySQLResult *result = [self queryString:packetQueryString]; + if(!result) { // query fails on sphinxql + NSLog(@"Query for max_allowed_packet failed: %@ (%lu) (on %@)", [self lastErrorMessage], [self lastErrorID], [self serverVersionString]); + return; + } [result setReturnDataAsStrings:YES]; // Get the maximum size string diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m index c9bf0bfd..dd684c78 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m @@ -42,10 +42,15 @@ */ - (NSString *)serverVersionString { - if (serverVersionString) { - return [NSString stringWithString:serverVersionString]; + if (serverVariableVersion) { + return [NSString stringWithString:serverVariableVersion]; } +#warning FIXME: There is probably a race condition here with -[self _disconnect] + if(mySQLConnection) { + return [self _stringForCString:mysql_get_server_info(mySQLConnection)]; + } + return nil; } @@ -54,9 +59,9 @@ */ - (NSUInteger)serverMajorVersion { - - if (serverVersionString != nil) { - NSString *s = [[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:0]; + NSString *ver; + if ((ver = [self serverVersionString]) != nil) { + NSString *s = [[ver componentsSeparatedByString:@"."] objectAtIndex:0]; return (NSUInteger)[s integerValue]; } @@ -68,8 +73,9 @@ */ - (NSUInteger)serverMinorVersion { - if (serverVersionString != nil) { - NSString *s = [[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:1]; + NSString *ver; + if ((ver = [self serverVersionString]) != nil) { + NSString *s = [[ver componentsSeparatedByString:@"."] objectAtIndex:1]; return (NSUInteger)[s integerValue]; } @@ -81,8 +87,9 @@ */ - (NSUInteger)serverReleaseVersion { - if (serverVersionString != nil) { - NSString *s = [[serverVersionString componentsSeparatedByString:@"."] objectAtIndex:2]; + NSString *ver; + if ((ver = [self serverVersionString]) != nil) { + NSString *s = [[ver componentsSeparatedByString:@"."] objectAtIndex:2]; return (NSUInteger)[[[s componentsSeparatedByString:@"-"] objectAtIndex:0] integerValue]; } @@ -98,9 +105,10 @@ */ - (BOOL)serverVersionIsGreaterThanOrEqualTo:(NSUInteger)aMajorVersion minorVersion:(NSUInteger)aMinorVersion releaseVersion:(NSUInteger)aReleaseVersion { - if (!serverVersionString) return NO; + NSString *ver; + if (!(ver = [self serverVersionString])) return NO; - NSArray *serverVersionParts = [serverVersionString componentsSeparatedByString:@"."]; + NSArray *serverVersionParts = [ver componentsSeparatedByString:@"."]; NSUInteger serverMajorVersion = (NSUInteger)[[serverVersionParts objectAtIndex:0] integerValue]; if (serverMajorVersion < aMajorVersion) return NO; diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h index 8fe79573..c65ec2fb 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.h @@ -100,7 +100,7 @@ BOOL previousEncodingUsesLatin1Transport; // Server details - NSString *serverVersionString; + NSString *serverVariableVersion; // Error state for the last query or connection state NSUInteger queryErrorID; diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m index dfe4802f..40c95321 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m @@ -175,7 +175,7 @@ const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RS [connectionLock setName:@"SPMySQLConnection query lock"]; // Ensure the server detail records are initialised - serverVersionString = nil; + serverVariableVersion = nil; // Start with a blank error state queryErrorID = 0; @@ -249,7 +249,7 @@ const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RS if (database) [database release], database = nil; if (databaseToRestore) [databaseToRestore release], databaseToRestore = nil; - if (serverVersionString) [serverVersionString release], serverVersionString = nil; + if (serverVariableVersion) [serverVariableVersion release], serverVariableVersion = nil; if (queryErrorMessage) [queryErrorMessage release], queryErrorMessage = nil; if (querySqlstate) [querySqlstate release], querySqlstate = nil; [delegateDecisionLock release]; @@ -911,7 +911,7 @@ asm(".desc ___crashreporter_info__, 0x10"); } // Clear host-specific information - if (serverVersionString) [serverVersionString release], serverVersionString = nil; + if (serverVariableVersion) [serverVariableVersion release], serverVariableVersion = nil; if (database) [database release], database = nil; state = SPMySQLDisconnected; @@ -940,8 +940,8 @@ asm(".desc ___crashreporter_info__, 0x10"); } // Copy the server version string to the instance variable - if (serverVersionString) [serverVersionString release], serverVersionString = nil; - serverVersionString = [[variables objectForKey:@"version"] retain]; + if (serverVariableVersion) [serverVariableVersion release], serverVariableVersion = nil; + serverVariableVersion = [[variables objectForKey:@"version"] retain]; // Get the connection encoding. Although a specific encoding may have been requested on // connection, it may be overridden by init_connect commands or connection state changes. diff --git a/Source/SPServerSupport.m b/Source/SPServerSupport.m index 489acc04..a3b2a1a7 100644 --- a/Source/SPServerSupport.m +++ b/Source/SPServerSupport.m @@ -95,10 +95,10 @@ - (id)initWithMajorVersion:(NSInteger)majorVersion minor:(NSInteger)minorVersion release:(NSInteger)releaseVersion { if ((self = [super init])) { - - serverMajorVersion = majorVersion; - serverMinorVersion = minorVersion; - serverReleaseVersion = releaseVersion; + // Might be NSNotFound if unknown. unknown should also lose against "0". + serverMajorVersion = (majorVersion != NSNotFound)? majorVersion : -1; + serverMinorVersion = (minorVersion != NSNotFound)? minorVersion : -1; + serverReleaseVersion = (releaseVersion != NSNotFound)? releaseVersion : -1; // Determine what the server supports [self evaluate]; -- cgit v1.2.3