aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMMCPConnection.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-04-09 22:50:38 +0000
committerrowanbeentje <rowan@beent.je>2009-04-09 22:50:38 +0000
commit5b6f8231ebfeea5d24fa6163325c0215d3829e7c (patch)
tree724e19f6893736875fa23d54132ce8c5a1232c12 /Source/CMMCPConnection.m
parentb065a02186bd8497c503505a09ceb5a0905693cc (diff)
downloadsequelpro-5b6f8231ebfeea5d24fa6163325c0215d3829e7c.tar.gz
sequelpro-5b6f8231ebfeea5d24fa6163325c0215d3829e7c.tar.bz2
sequelpro-5b6f8231ebfeea5d24fa6163325c0215d3829e7c.zip
- If a connection is reestablished automatically by the mysql libraries, ensure the connection encoding is similarly reset. This addresses Issue #79.
Diffstat (limited to 'Source/CMMCPConnection.m')
-rw-r--r--Source/CMMCPConnection.m23
1 files changed, 19 insertions, 4 deletions
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m
index 41a828e2..9f8c78fa 100644
--- a/Source/CMMCPConnection.m
+++ b/Source/CMMCPConnection.m
@@ -146,8 +146,8 @@ static void forcePingTimeout(int signalNumber);
if (delegate && [delegate valueForKey:@"_encoding"]) {
currentEncoding = [NSString stringWithString:[delegate valueForKey:@"_encoding"]];
}
- if (delegate && [delegate boolForKey:@"_encodingViaLatin1"]) {
- currentEncodingUsesLatin1Transport = [delegate boolForKey:@"_encodingViaLatin1"];
+ if (delegate && [delegate respondsToSelector:@selector(connectionEncodingViaLatin1)]) {
+ currentEncodingUsesLatin1Transport = [delegate connectionEncodingViaLatin1];
}
// Close the connection if it exists.
@@ -178,10 +178,10 @@ static void forcePingTimeout(int signalNumber);
[self selectDB:currentDatabase];
}
if (currentEncoding) {
- [self queryString:[NSString stringWithFormat:@"SET NAMES '%@'", currentEncoding]];
+ [self queryString:[NSString stringWithFormat:@"/*!40101 SET NAMES '%@' */", currentEncoding]];
[self setEncoding:[CMMCPConnection encodingForMySQLEncoding:[currentEncoding UTF8String]]];
if (currentEncodingUsesLatin1Transport) {
- [self queryString:@"SET CHARACTER_SET_RESULTS=latin1"];
+ [self queryString:@"/*!40101 SET CHARACTER_SET_RESULTS=latin1 */"];
}
}
} else if (parentWindow) {
@@ -444,10 +444,15 @@ static void forcePingTimeout(int signalNumber);
*/
- (BOOL)checkConnection
{
+ unsigned long threadid;
+
if (!mConnected) return NO;
BOOL connectionVerified = FALSE;
+ // Get the current thread ID for this connection
+ threadid = mConnection->thread_id;
+
// Check whether the connection is still operational via a wrapped version of MySQL ping.
connectionVerified = [self pingConnection];
@@ -474,6 +479,16 @@ static void forcePingTimeout(int signalNumber);
default:
return [self checkConnection];
}
+
+ // If a connection exists, check whether the thread id differs; if so, the connection has
+ // probably been reestablished and we need to reset the connection encoding
+ } else if (threadid != mConnection->thread_id) {
+ if (delegate && [delegate valueForKey:@"_encoding"]) {
+ [self queryString:[NSString stringWithFormat:@"/*!40101 SET NAMES '%@' */", [NSString stringWithString:[delegate valueForKey:@"_encoding"]]]];
+ if (delegate && [delegate respondsToSelector:@selector(connectionEncodingViaLatin1)]) {
+ if ([delegate connectionEncodingViaLatin1]) [self queryString:@"/*!40101 SET CHARACTER_SET_RESULTS=latin1 */"];
+ }
+ }
}
return connectionVerified;