From 50a283b6d1f3ce48e3a06eceeed3a466c6259fe7 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sun, 15 Nov 2009 23:58:21 +0000 Subject: Implement query cancellation support within MCPKit, and add it to the task functionality: - MCPKit now supports cancelling the active query; for MySQL servers >= 5.0.0 a query kill is attempted from a new connection, and if that fails or for MySQL < 5 a reconnect is triggered. - TableDocument now supports enabling a cancel task button on the task interface, including an optional callback - Implement query cancellation for custom queries. This addresses Issue #86. - Implement query cancellation for table content loads, filters, and sorts. --- Source/TableContent.m | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'Source/TableContent.m') diff --git a/Source/TableContent.m b/Source/TableContent.m index 552fbd41..d5c9e8d1 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -86,6 +86,7 @@ isFiltered = NO; isLimited = NO; + isInterruptedLoad = NO; prefs = [NSUserDefaults standardUserDefaults]; @@ -532,7 +533,10 @@ rowsToLoad = rowsToLoad - ([limitRowsField intValue]-1); if (rowsToLoad > [prefs integerForKey:SPLimitResultsValue]) rowsToLoad = [prefs integerForKey:SPLimitResultsValue]; } - + + // If within a task, allow this query to be cancelled + [tableDocumentInstance enableTaskCancellationWithTitle:NSLocalizedString(@"Stop", @"Stop load") callbackObject:nil callbackFunction:NULL]; + // Perform and process the query [tableContentView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES]; [self setUsedQuery:queryString]; @@ -541,7 +545,7 @@ [streamingResult release]; // If the result is empty, and a limit is active, reset the limit - if ([prefs boolForKey:SPLimitResults] && queryStringBeforeLimit && !tableRowsCount) { + if ([prefs boolForKey:SPLimitResults] && queryStringBeforeLimit && !tableRowsCount && ![mySQLConnection queryCancelled]) { [limitRowsField setStringValue:@"1"]; queryString = [NSMutableString stringWithFormat:@"%@ LIMIT 0,%d", queryStringBeforeLimit, [prefs integerForKey:SPLimitResultsValue]]; [self setUsedQuery:queryString]; @@ -549,6 +553,14 @@ [self processResultIntoDataStorage:streamingResult approximateRowCount:[prefs integerForKey:SPLimitResultsValue]]; [streamingResult release]; } + + if ([mySQLConnection queryCancelled] || ![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) + isInterruptedLoad = YES; + else + isInterruptedLoad = NO; + + // End cancellation ability + [tableDocumentInstance disableTaskCancellation]; if ([prefs boolForKey:SPLimitResults] && ([limitRowsField intValue] > 1 @@ -821,8 +833,15 @@ NSString *rowString; NSMutableString *countString = [NSMutableString string]; + // If the result is partial due to an error or query cancellation, show a very basic count + if (isInterruptedLoad) { + if (tableRowsCount == 1) + [countString appendFormat:NSLocalizedString(@"%d row in partial load", @"text showing a single row a partially loaded result"), tableRowsCount]; + else + [countString appendFormat:NSLocalizedString(@"%d rows in partial load", @"text showing how many rows are in a partially loaded result"), tableRowsCount]; + // If no filter or limit is active, show just the count of rows in the table - if (!isFiltered && !isLimited) { + } else if (!isFiltered && !isLimited) { if (tableRowsCount == 1) [countString appendFormat:NSLocalizedString(@"%d row in table", @"text showing a single row in the result"), tableRowsCount]; else @@ -1128,7 +1147,7 @@ NSString *contextInfo = @"removerow"; - if (([tableContentView numberOfSelectedRows] == [tableContentView numberOfRows]) && !isFiltered && !isLimited) { + if (([tableContentView numberOfSelectedRows] == [tableContentView numberOfRows]) && !isFiltered && !isLimited && !isInterruptedLoad) { contextInfo = @"removeallrows"; @@ -2288,7 +2307,7 @@ BOOL checkStatusCount = NO; // For unfiltered and non-limited tables, use the result count - and update the status count - if (!isLimited && !isFiltered) { + if (!isLimited && !isFiltered && !isInterruptedLoad) { maxNumRows = tableRowsCount; maxNumRowsIsEstimate = NO; [tableDataInstance setStatusValue:[NSString stringWithFormat:@"%d", maxNumRows] forKey:@"Rows"]; -- cgit v1.2.3