diff options
author | rowanbeentje <rowan@beent.je> | 2010-01-03 13:37:54 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2010-01-03 13:37:54 +0000 |
commit | 44cdc2f18931a6d5a7571b2dc485120a73b33b57 (patch) | |
tree | 6b7b49f0c7efb80f1fe42b6ab37656660f5c2884 /Source/TableDocument.m | |
parent | e42f000e98e9ff33a91a86a3e2a0cf04c6778102 (diff) | |
download | sequelpro-44cdc2f18931a6d5a7571b2dc485120a73b33b57.tar.gz sequelpro-44cdc2f18931a6d5a7571b2dc485120a73b33b57.tar.bz2 sequelpro-44cdc2f18931a6d5a7571b2dc485120a73b33b57.zip |
- Ensure all results for server variable requests are returned as strings, to avoid binary-mode result issues with certain versions of MySQL (including 4.1.14). This should address Issue #509.
- TableDocument now requests the server version string from MCPConnection, aiding caching
Diffstat (limited to 'Source/TableDocument.m')
-rw-r--r-- | Source/TableDocument.m | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 0bd76f6f..c7ab7105 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -648,15 +648,7 @@ } // Get the mysql version - theResult = [mySQLConnection queryString:@"SHOW VARIABLES LIKE 'version'"]; - version = [[theResult fetchRowAsArray] objectAtIndex:1]; - if (mySQLVersion) [mySQLVersion release], mySQLVersion = nil; - if ( [version isKindOfClass:[NSData class]] ) { - // starting with MySQL 4.1.14 the mysql variables are returned as nsdata - mySQLVersion = [[NSString alloc] initWithData:version encoding:[mySQLConnection encoding]]; - } else { - mySQLVersion = [[NSString alloc] initWithString:version]; - } + mySQLVersion = [[NSString alloc] initWithString:[mySQLConnection serverVersionString]]; // Update the selected database if appropriate if ([connectionController database] && ![[connectionController database] isEqualToString:@""]) { @@ -1640,17 +1632,22 @@ */ - (NSString *)databaseEncoding { + MCPResult *charSetResult; + NSString *mysqlEncoding; + // MySQL > 4.0 - id mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set_connection'"] fetchRowAsDictionary] objectForKey:@"Value"]; + charSetResult = [mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set_connection'"]; + [charSetResult setReturnDataAsStrings:YES]; + mysqlEncoding = [[charSetResult fetchRowAsDictionary] objectForKey:@"Value"]; _supportsEncoding = (mysqlEncoding != nil); - if ( [mysqlEncoding isKindOfClass:[NSData class]] ) { // MySQL 4.1.14 returns the mysql variables as nsdata - mysqlEncoding = [mySQLConnection stringWithText:mysqlEncoding]; - } - if ( !mysqlEncoding ) { // mysql 4.0 or older -> only default character set possible, cannot choose others using "set names xy" + // mysql 4.0 or older -> only default character set possible, cannot choose others using "set names xy" + if ( !mysqlEncoding ) { mysqlEncoding = [[[mySQLConnection queryString:@"SHOW VARIABLES LIKE 'character_set'"] fetchRowAsDictionary] objectForKey:@"Value"]; } - if ( !mysqlEncoding ) { // older version? -> set encoding to mysql default encoding latin1 + + // older version? -> set encoding to mysql default encoding latin1 + if ( !mysqlEncoding ) { NSLog(@"Error: no character encoding found, mysql version is %@", [self mySQLVersion]); mysqlEncoding = @"latin1"; } @@ -1709,6 +1706,7 @@ if (query == nil) return; MCPResult *theResult = [mySQLConnection queryString:query]; + [theResult setReturnDataAsStrings:YES]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { @@ -1719,10 +1717,7 @@ return; } - id tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs]; - - if ([tableSyntax isKindOfClass:[NSData class]]) - tableSyntax = [[[NSString alloc] initWithData:tableSyntax encoding:[mySQLConnection encoding]] autorelease]; + NSString *tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs]; [createTableSyntaxTextField setStringValue:[NSString stringWithFormat:@"Create syntax for %@ '%@'", typeString, [self table]]]; @@ -1767,6 +1762,7 @@ return; MCPResult *theResult = [mySQLConnection queryString:query]; + [theResult setReturnDataAsStrings:YES]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { @@ -1776,10 +1772,7 @@ return; } - id tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs]; - - if ([tableSyntax isKindOfClass:[NSData class]]) - tableSyntax = [[[NSString alloc] initWithData:tableSyntax encoding:[mySQLConnection encoding]] autorelease]; + NSString *tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs]; // copy to the clipboard NSPasteboard *pb = [NSPasteboard generalPasteboard]; |