aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-11-01 23:54:10 +0000
committerrowanbeentje <rowan@beent.je>2009-11-01 23:54:10 +0000
commit7db6c4e18fb52c2e5ada02ad108ab6415a49843d (patch)
tree4b0af2b28ee1e8022928fd556834d6a760d841b1
parentb5b5b411b5a8adf460ddd5ba7db03d429d7f2a8e (diff)
downloadsequelpro-7db6c4e18fb52c2e5ada02ad108ab6415a49843d.tar.gz
sequelpro-7db6c4e18fb52c2e5ada02ad108ab6415a49843d.tar.bz2
sequelpro-7db6c4e18fb52c2e5ada02ad108ab6415a49843d.zip
- Tweak connection locking to avoid occasional NSLock warnings when running custom queries
- Add error connection to query reselection to avoid exceptions when editing queries while running them
-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];
+ }
}
/*