From 414ac81a88a5d3da0f4b657769bd0ce6bd32fde8 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sat, 30 Jan 2010 01:13:30 +0000 Subject: - Bugfix: when the number of table columns for a content result set no longer matched the internal table representation, table storage exceptions would occur. Additional checks are now made against the column count; if a content result set is retrieved with an unexpected number of columns, the result set is discarded and a full table refresh is triggered to restore the state. --- Source/TableContent.m | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Source/TableContent.m b/Source/TableContent.m index f5e1feb4..c0814670 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -607,13 +607,25 @@ [tableContentView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES]; [self setUsedQuery:queryString]; streamingResult = [mySQLConnection streamingQueryString:queryString]; - if (streamingResult) { + + // Ensure the number of columns are unchanged; if the column count has changed, abort the load + // and queue a full table reload. + BOOL fullTableReloadRequired = NO; + if (streamingResult && [dataColumns count] != [streamingResult numOfFields]) { + [tableDocumentInstance disableTaskCancellation]; + [mySQLConnection cancelCurrentQuery]; + [streamingResult cancelResultLoad]; + fullTableReloadRequired = YES; + } + + // Process the result into the data store + if (!fullTableReloadRequired && streamingResult) { [self processResultIntoDataStorage:streamingResult approximateRowCount:rowsToLoad]; [streamingResult release]; } // If the result is empty, and a late page is selected, reset the page - if ([prefs boolForKey:SPLimitResults] && queryStringBeforeLimit && !tableRowsCount && ![mySQLConnection queryCancelled]) { + if (!fullTableReloadRequired && [prefs boolForKey:SPLimitResults] && queryStringBeforeLimit && !tableRowsCount && ![mySQLConnection queryCancelled]) { contentPage = 1; queryString = [NSMutableString stringWithFormat:@"%@ LIMIT 0,%ld", queryStringBeforeLimit, (long)[prefs integerForKey:SPLimitResultsValue]]; [self setUsedQuery:queryString]; @@ -652,6 +664,9 @@ // Notify listenters that the query has finished [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; + + // Trigger a full reload if required + if (fullTableReloadRequired) [self reloadTable:self]; } /* @@ -662,7 +677,7 @@ NSArray *tempRow; NSUInteger i; NSUInteger dataColumnsCount = [dataColumns count]; - BOOL *columnBlobStatuses = malloc(dataColumnsCount * sizeof(BOOL));; + BOOL *columnBlobStatuses = malloc(dataColumnsCount * sizeof(BOOL)); // Set the column count on the data store [tableValues setColumnCount:dataColumnsCount]; -- cgit v1.2.3