aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-08-18 14:18:29 +0000
committerrowanbeentje <rowan@beent.je>2012-08-18 14:18:29 +0000
commiteda4399be690cb325bb03d3195654e38ed061738 (patch)
treede1b9e4d6492ab0ab2446c0747b4db0539777e3c /Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories
parent70467916504f6052869dfdf618e5a677bd0cf366 (diff)
downloadsequelpro-eda4399be690cb325bb03d3195654e38ed061738.tar.gz
sequelpro-eda4399be690cb325bb03d3195654e38ed061738.tar.bz2
sequelpro-eda4399be690cb325bb03d3195654e38ed061738.zip
Improve connection handling and recovery in general, and specifically to address Issue #877:
- On servers with very short timeouts set the wait_timeout for the session as well as the interactive_timeout to prevent the connection from dropping frequently - Improve recovery from connection errors, correctly restoring the connection if appropriate and possible - Allow reconnections to occur recursively by altering the internal tracking mechanism - Fix some edge cases where the connection would remain locked incorrectly - Improve error messaging for the "MySQL Server has gone away" network case
Diffstat (limited to 'Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories')
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m22
1 files changed, 16 insertions, 6 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
index 3b2614f1..9280c156 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
@@ -217,6 +217,8 @@
- (id)queryString:(NSString *)theQueryString usingEncoding:(NSStringEncoding)theEncoding withResultType:(SPMySQLResultType)theReturnType
{
double queryExecutionTime;
+ NSString *theErrorMessage;
+ NSUInteger theErrorID;
lastQueryWasCancelled = NO;
lastQueryWasCancelledUsingReconnect = NO;
@@ -282,11 +284,17 @@
// If the query succeeded, no need to re-attempt.
if (!queryStatus) {
+ theErrorMessage = nil;
+ theErrorID = 0;
break;
// If the query failed, determine whether to reattempt the query
} else {
+ // Store the error state
+ theErrorMessage = [self _stringForCString:mysql_error(mySQLConnection)];
+ theErrorID = mysql_errno(mySQLConnection);
+
// Prevent retries if the query was cancelled or not a connection error
if (lastQueryWasCancelled || ![SPMySQLConnection isErrorIDConnectionError:mysql_errno(mySQLConnection)]) {
break;
@@ -294,10 +302,11 @@
}
// Query has failed - check the connection
+ [self _unlockConnection];
if (![self checkConnection]) {
- [self _unlockConnection];
- return nil;
+ break;
}
+ [self _lockConnection];
queryAttemptsAllowed--;
}
@@ -330,11 +339,11 @@
theResult = [[SPMySQLFastStreamingResult alloc] initWithMySQLResult:mysqlResult stringEncoding:theEncoding connection:self];
break;
}
- }
- // Record the error state now, as it may be affected by subsequent clean-up queries
- NSString *theErrorMessage = [self _stringForCString:mysql_error(mySQLConnection)];
- NSUInteger theErrorID = mysql_errno(mySQLConnection);
+ // Update the error message, if appropriate, to reflect result store errors or overall success
+ theErrorMessage = [self _stringForCString:mysql_error(mySQLConnection)];
+ theErrorID = mysql_errno(mySQLConnection);
+ }
// Update the connection's stored insert ID if available
if (mySQLConnection->insert_id) {
@@ -350,6 +359,7 @@
// after query kills. This is also handled within the class for internal cancellations, but
// as other external classes may also cancel the query.
if (![self serverVersionIsGreaterThanOrEqualTo:5 minorVersion:0 releaseVersion:0]) {
+ [self _unlockConnection];
[self checkConnection];
}
}