diff options
author | jakob <jakob@eggerapps.at> | 2010-06-30 13:40:38 +0000 |
---|---|---|
committer | jakob <jakob@eggerapps.at> | 2010-06-30 13:40:38 +0000 |
commit | 92b97ba3f3ee634e101483f5129f25b4f8230117 (patch) | |
tree | 6e2592ed4d177b29529df6774cf2dd3a6108a65b /Frameworks | |
parent | e7502a90d7f5ff4a33c73d54ea81a4e539d0e3ce (diff) | |
download | sequelpro-92b97ba3f3ee634e101483f5129f25b4f8230117.tar.gz sequelpro-92b97ba3f3ee634e101483f5129f25b4f8230117.tar.bz2 sequelpro-92b97ba3f3ee634e101483f5129f25b4f8230117.zip |
Improved calling of stored procedures:
- added the CLIENT_MULTI_RESULTS flag to the connection flags
- automatically discard all remaining results when unlocking the connection
This is not a perfect solution, but will improve usability a lot for those who often call stored procedures. Sequel Pro still doesn't support multiple results -- it will show only the first and silently discard all the remaining ones.
Diffstat (limited to 'Frameworks')
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h | 1 | ||||
-rw-r--r-- | Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 32 |
2 files changed, 31 insertions, 2 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h index 60c9dcb6..4b2e0cdb 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h @@ -277,6 +277,7 @@ void performThreadedKeepAlive(void *ptr); - (void)cancelCurrentQuery; - (BOOL)queryCancelled; - (BOOL)queryCancellationUsedReconnect; +- (void)flushMultiResults; // Locking - (void)lockConnection; diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index b2080c26..9ca945a7 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -43,7 +43,7 @@ BOOL lastPingSuccess; BOOL pingActive; -const NSUInteger kMCPConnectionDefaultOption = CLIENT_COMPRESS | CLIENT_REMEMBER_OPTIONS ; +const NSUInteger kMCPConnectionDefaultOption = CLIENT_COMPRESS | CLIENT_REMEMBER_OPTIONS | CLIENT_MULTI_RESULTS; const char *kMCPConnectionDefaultSocket = MYSQL_UNIX_ADDR; const NSUInteger kMCPConnection_Not_Inited = 1000; const NSUInteger kLengthOfTruncationForLog = 100; @@ -1485,7 +1485,9 @@ void performThreadedKeepAlive(void *ptr) // For normal result sets, fetch the results and unlock the connection if (streamResultType == MCPStreamingNone) { theResult = [[MCPResult alloc] initWithMySQLPtr:mConnection encoding:mEncoding timeZone:mTimeZone]; - if (!queryCancelled || !queryCancelUsedReconnect) [self unlockConnection]; + if (!queryCancelled || !queryCancelUsedReconnect) { + [self unlockConnection]; + } // For streaming result sets, fetch the result pointer and leave the connection locked } else if (streamResultType == MCPStreamingFast) { @@ -1695,6 +1697,25 @@ void performThreadedKeepAlive(void *ptr) return queryCancelUsedReconnect; } +/** + * Retrieves all remaining results and discards them. + * Necessary if we only retrieve one result, and want to discard all the others. + */ +- (void)flushMultiResults +{ + // repeat as long as there are results + while(!mysql_next_result(mConnection)) + { + MYSQL_RES *result = mysql_use_result(mConnection); + // check if the result is really a result + if (result) { + // retrieve all rows + while (mysql_fetch_row(result)); + mysql_free_result(result); + } + } +} + #pragma mark - #pragma mark Connection locking @@ -1746,6 +1767,13 @@ void performThreadedKeepAlive(void *ptr) NSLog(@"Tried to unlock the connection, but it wasn't locked."); } + // Since we connected with CLIENT_MULTI_RESULT, we must make sure there are nor more results! + // This is still a bit of a dirty hack + if (mysql_more_results(mConnection)) { + NSLog(@"Discarding unretrieved results. This is currently normal when using CALL."); + [self flushMultiResults]; + } + // We tell everyone that the connection is available again! [connectionLock unlockWithCondition:MCPConnectionIdle]; } |