aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m22
-rw-r--r--Source/CustomQuery.m21
2 files changed, 22 insertions, 21 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index 4e6e0ada..dd830e02 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -1352,14 +1352,8 @@ void performThreadedKeepAlive(void *ptr)
}
}
- // Lock on this thread for normal result sets...
- if (streamResultType == MCP_NO_STREAMING) {
- [queryLock lock];
-
- // ...but streaming result unlock on the main thread after processing, so ensure a lock on the main thread.
- } else {
- [self lockConnection];
- }
+ // Lock the connection
+ [self lockConnection];
// Run (or re-run) the query, timing the execution time of the query - note
// that this time will include network lag.
@@ -1378,7 +1372,7 @@ void performThreadedKeepAlive(void *ptr)
// For normal result sets, fetch the results and unlock the connection
if (streamResultType == MCP_NO_STREAMING) {
theResult = [[MCPResult alloc] initWithMySQLPtr:mConnection encoding:mEncoding timeZone:mTimeZone];
- [queryLock unlock];
+ [self unlockConnection];
// For streaming result sets, fetch the result pointer and leave the connection locked
} else if (streamResultType == MCP_FAST_STREAMING) {
@@ -1394,7 +1388,7 @@ void performThreadedKeepAlive(void *ptr)
break;
}
} else {
- [queryLock unlock];
+ [self unlockConnection];
}
queryErrorMessage = [[NSString alloc] initWithString:@""];
@@ -1405,7 +1399,7 @@ void performThreadedKeepAlive(void *ptr)
// On failure, set the error messages and IDs
} else {
- [queryLock unlock];
+ [self unlockConnection];
queryErrorMessage = [[NSString alloc] initWithString:[self stringWithCString:mysql_error(mConnection)]];
queryErrorId = mysql_errno(mConnection);
@@ -1487,7 +1481,8 @@ void performThreadedKeepAlive(void *ptr)
#pragma mark Connection locking
/**
- * Lock the connection from any thread
+ * Lock the connection from any thread; ensure the the connection is locked on
+ * the main thread, but as fast as possible.
*/
- (void)lockConnection
{
@@ -1496,7 +1491,8 @@ void performThreadedKeepAlive(void *ptr)
}
/**
- * Unlock the connection from any thread
+ * Unlock the connection from any thread; ensure the connection is unlocked on
+ * the main thread, but as fast as possible.
*/
- (void)unlockConnection
{
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index b9896a28..25c90dba 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -81,15 +81,20 @@
- (void) runAllQueriesCallback
{
- // If no error was selected reconstruct a given selection
- if([textView selectedRange].length == 0)
- [textView setSelectedRange:oldThreadedQueryRange];
+ // If no error was selected, reconstruct a given selection. This
+ // may no longer be valid if the query text has changed in the
+ // meantime, so error-checking is required.
+ if (oldThreadedQueryRange.location + oldThreadedQueryRange.length <= [[textView string] length]) {
- // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase
- NSRange oldRange = [textView selectedRange];
- [textView setSelectedRange:NSMakeRange(oldThreadedQueryRange.location,0)];
- [textView insertText:@""];
- [textView setSelectedRange:oldRange];
+ if ([textView selectedRange].length == 0)
+ [textView setSelectedRange:oldThreadedQueryRange];
+
+ // Invoke textStorageDidProcessEditing: for syntax highlighting and auto-uppercase
+ NSRange oldRange = [textView selectedRange];
+ [textView setSelectedRange:NSMakeRange(oldThreadedQueryRange.location,0)];
+ [textView insertText:@""];
+ [textView setSelectedRange:oldRange];
+ }
}
/*