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 /Frameworks/MCPKit/MCPFoundationKit/MCPResult.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 'Frameworks/MCPKit/MCPFoundationKit/MCPResult.m')
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPResult.m | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPResult.m b/Frameworks/MCPKit/MCPFoundationKit/MCPResult.m index d2061fca..98f26b6c 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPResult.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPResult.m @@ -243,6 +243,8 @@ const OUR_CHARSET our_charsets60[] = { if ((self = [super init])) { mEncoding = [MCPConnection defaultMySQLEncoding]; + mReturnDataAsStrings = NO; + mTimeZone = nil; if (mResult) { mysql_free_result(mResult); @@ -269,6 +271,7 @@ const OUR_CHARSET our_charsets60[] = if ((self = [super init])) { mEncoding = iEncoding; mTimeZone = [iTimeZone retain]; + mReturnDataAsStrings = NO; if (mResult) { mysql_free_result(mResult); @@ -303,6 +306,7 @@ const OUR_CHARSET our_charsets60[] = if ((self = [super init])) { mEncoding = iEncoding; mTimeZone = [iTimeZone retain]; + mReturnDataAsStrings = NO; if (mResult) { mysql_free_result(mResult); @@ -452,8 +456,9 @@ const OUR_CHARSET our_charsets60[] = case FIELD_TYPE_LONG_BLOB: theCurrentObj = [NSData dataWithBytes:theData length:theLengths[i]]; - // It is TEXT and NOT BLOB - if (!(theField[i].flags & BINARY_FLAG)) { + // If the field is TEXT and NOT BLOB, or if force-return-as-string is + // enabled, return a NSString instead of NSData + if (mReturnDataAsStrings || !(theField[i].flags & BINARY_FLAG)) { theCurrentObj = [self stringWithText:theCurrentObj]; } @@ -989,6 +994,19 @@ const OUR_CHARSET our_charsets60[] = #pragma mark Conversion /** + * Set whether the result should return data types as strings. This may be useful + * for queries where the result may be returned in either string or data form, but + * will be converted to string for display and use anyway. + * Note that certain MySQL versions also return data types for strings - eg SHOW + * commands like SHOW CREATE TABLE or SHOW VARIABLES, and this conversion can be + * necessary there. + */ +- (void) setReturnDataAsStrings:(BOOL)alwaysConvertData +{ + mReturnDataAsStrings = alwaysConvertData; +} + +/** * Use the string encoding to convert the returned NSData to a string (for a TEXT field). */ - (NSString *)stringWithText:(NSData *)theTextData @@ -1325,14 +1343,10 @@ const OUR_CHARSET our_charsets60[] = */ - (void) dealloc { - if (mResult) { - mysql_free_result(mResult); - } - - if (mNames) { - [mNames autorelease]; - } - + if (mResult) mysql_free_result(mResult); + if (mNames) [mNames autorelease]; + if (mTimeZone) [mTimeZone release]; + [super dealloc]; } |