diff options
author | rowanbeentje <rowan@beent.je> | 2009-04-08 23:15:03 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-04-08 23:15:03 +0000 |
commit | 291bc96e1c0b916b2106da936e4c732ec7897bcf (patch) | |
tree | ab97ab91a5e6d5008a4839b6781a783938be506f /Source/CMMCPConnection.m | |
parent | ce44079e15c6ad11589b0237fd78ee6b4b364bfa (diff) | |
download | sequelpro-291bc96e1c0b916b2106da936e4c732ec7897bcf.tar.gz sequelpro-291bc96e1c0b916b2106da936e4c732ec7897bcf.tar.bz2 sequelpro-291bc96e1c0b916b2106da936e4c732ec7897bcf.zip |
- Second part of r498: ensure that SQL imports are read in as UTF8, and queries are sent as UTF8, if possible; this correctly preserves encoding data when working with files export from Sequel Pro or via mysqldump, and attempts to fall back to the current connection encodings for other files. This should resolve Issue #116.
Diffstat (limited to 'Source/CMMCPConnection.m')
-rw-r--r-- | Source/CMMCPConnection.m | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index ac75819f..41a828e2 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -345,15 +345,25 @@ static void forcePingTimeout(int signalNumber); /* + * Override the standard queryString: method to default to the connection encoding, as before, + * before pssing on to queryString: usingEncoding:. + */ +- (CMMCPResult *)queryString:(NSString *) query +{ + return [self queryString:query usingEncoding:mEncoding]; +} + + +/* * Modified version of queryString to be used in Sequel Pro. * Error checks extensively - if this method fails, it will ask how to proceed and loop depending * on the status, not returning control until either the query has been executed and the result can * be returned or the connection and document have been closed. */ -- (CMMCPResult *)queryString:(NSString *) query +- (CMMCPResult *)queryString:(NSString *) query usingEncoding:(NSStringEncoding) encoding { CMMCPResult *theResult; - const char *theCQuery = [self cStringFromString:query]; + const char *theCQuery; int theQueryCode; NSDate *queryStartDate; @@ -362,6 +372,9 @@ static void forcePingTimeout(int signalNumber); [self stopKeepAliveTimer]; + // Generate the cString as appropriate + theCQuery = [self cStringFromString:query usingEncoding:encoding]; + // Check the connection. This triggers reconnects as necessary, and should only return false if a disconnection // has been requested - in which case return nil if (![self checkConnection]) return nil; @@ -662,4 +675,23 @@ static void forcePingTimeout(int signalNumber) } lastKeepAliveSuccess = [[NSDate alloc] initWithTimeIntervalSinceNow:0]; } -@end + + +/* + * Modified version of the original to support a supplied encoding. + * For internal use only. Transforms a NSString to a C type string (ending with \0). + * Lossy conversions are enabled. + */ +- (const char *) cStringFromString:(NSString *) theString usingEncoding:(NSStringEncoding) encoding +{ + NSMutableData *theData; + + if (! theString) { + return (const char *)NULL; + } + + theData = [NSMutableData dataWithData:[theString dataUsingEncoding:encoding allowLossyConversion:YES]]; + [theData increaseLengthBy:1]; + return (const char *)[theData bytes]; +} +@end
\ No newline at end of file |