Permalink
Browse files

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)
  • Loading branch information...
dmoagx committed Aug 7, 2015
1 parent 5befad8 commit c7b5e880003153e599a452151ee1f3a3e40aff4c
@@ -108,6 +108,10 @@ - (void)_updateMaxQuerySize
// 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
@@ -42,10 +42,15 @@ @implementation SPMySQLConnection (Server_Info)
*/
- (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 @@ - (NSString *)serverVersionString
*/
- (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)serverMajorVersion
*/
- (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)serverMinorVersion
*/
- (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 @@ - (NSUInteger)serverReleaseVersion
*/
- (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;
@@ -100,7 +100,7 @@
BOOL previousEncodingUsesLatin1Transport;
// Server details
NSString *serverVersionString;
NSString *serverVariableVersion;
// Error state for the last query or connection state
NSUInteger queryErrorID;
@@ -175,7 +175,7 @@ - (id)init
[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 @@ - (void) dealloc
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 @@ - (void)_disconnect
}
// 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 @@ - (void)_updateConnectionVariables
}
// 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.
@@ -95,10 +95,10 @@ @implementation SPServerSupport
- (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];

0 comments on commit c7b5e88

Please sign in to comment.