diff options
author | Max <dmoagx@users.noreply.github.com> | 2018-05-03 22:26:12 +0200 |
---|---|---|
committer | Max <dmoagx@users.noreply.github.com> | 2018-05-03 22:26:27 +0200 |
commit | b49edf67744ba6e54b7c0bdab7dc197cf8faac96 (patch) | |
tree | 25333e30eabfc6c40c9251322d2342ff6c21a530 /Source/SPIndexesController.m | |
parent | 7f35608f0ab5f9192245a5bc8dd74da793788389 (diff) | |
download | sequelpro-b49edf67744ba6e54b7c0bdab7dc197cf8faac96.tar.gz sequelpro-b49edf67744ba6e54b7c0bdab7dc197cf8faac96.tar.bz2 sequelpro-b49edf67744ba6e54b7c0bdab7dc197cf8faac96.zip |
Replace all non-cyclic NSAutoreleasepools with @autoreleasepool
Diffstat (limited to 'Source/SPIndexesController.m')
-rw-r--r-- | Source/SPIndexesController.m | 240 |
1 files changed, 119 insertions, 121 deletions
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m index c5b5d14c..ace6d882 100644 --- a/Source/SPIndexesController.m +++ b/Source/SPIndexesController.m @@ -777,109 +777,106 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; */ - (void)_addIndexUsingDetails:(NSDictionary *)indexDetails { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + @autoreleasepool { + // Check whether a save of the current fields row is required. + if (![[tableStructure onMainThread] saveRowOnDeselect]) return; - // Check whether a save of the current fields row is required. - if (![[tableStructure onMainThread] saveRowOnDeselect]) return; - - // Retrieve index details - NSString *indexName = [indexDetails objectForKey:SPNewIndexIndexName]; - NSString *indexType = [indexDetails objectForKey:SPNewIndexIndexType]; - NSString *indexStorageType = [indexDetails objectForKey:SPNewIndexStorageType]; - NSNumber *indexKeyBlockSize = [indexDetails objectForKey:SPNewIndexKeyBlockSize]; - NSArray *indexedColumns = [indexDetails objectForKey:SPNewIndexIndexedColumns]; + // Retrieve index details + NSString *indexName = [indexDetails objectForKey:SPNewIndexIndexName]; + NSString *indexType = [indexDetails objectForKey:SPNewIndexIndexType]; + NSString *indexStorageType = [indexDetails objectForKey:SPNewIndexStorageType]; + NSNumber *indexKeyBlockSize = [indexDetails objectForKey:SPNewIndexKeyBlockSize]; + NSArray *indexedColumns = [indexDetails objectForKey:SPNewIndexIndexedColumns]; - // Interface validation should prevent this, but just to be safe - if ([indexedColumns count] > 0) { + // Interface validation should prevent this, but just to be safe + if ([indexedColumns count] > 0) { - NSMutableArray *tempIndexedColumns = [[NSMutableArray alloc] init]; + NSMutableArray *tempIndexedColumns = [[NSMutableArray alloc] init]; - if ([indexType isEqualToString:@"PRIMARY KEY"]) { - indexName = @""; - } - else { - indexName = ([indexName isEqualToString:@""]) ? @"" : [indexName backtickQuotedString]; - } + if ([indexType isEqualToString:@"PRIMARY KEY"]) { + indexName = @""; + } + else { + indexName = ([indexName isEqualToString:@""]) ? @"" : [indexName backtickQuotedString]; + } - // For each column add it to the temp array and check if size is required - for (NSDictionary *column in indexedColumns) - { - NSString *columnName = [column objectForKey:@"name"]; - NSString *columnType = [column objectForKey:@"type"]; + // For each column add it to the temp array and check if size is required + for (NSDictionary *column in indexedColumns) + { + NSString *columnName = [column objectForKey:@"name"]; + NSString *columnType = [column objectForKey:@"type"]; - if ((![columnName length]) || (![columnType length])) continue; + if ((![columnName length]) || (![columnType length])) continue; - BOOL isFullTextType = [indexType isEqualToString:@"FULLTEXT"]; - - // If this field type requires a length and one hasn't been specified (interface validation - // should ensure this doesn't happen), then skip it. - if ([requiresLength containsObject:[columnType uppercaseString]] && (![(NSString *)[column objectForKey:@"Size"] length]) && !isFullTextType) continue; + BOOL isFullTextType = [indexType isEqualToString:@"FULLTEXT"]; - if ([column objectForKey:@"Size"] && [supportsLength containsObject:columnType] && !isFullTextType) { + // If this field type requires a length and one hasn't been specified (interface validation + // should ensure this doesn't happen), then skip it. + if ([requiresLength containsObject:[columnType uppercaseString]] && (![(NSString *)[column objectForKey:@"Size"] length]) && !isFullTextType) continue; - [tempIndexedColumns addObject:[NSString stringWithFormat:@"%@ (%@)", [columnName backtickQuotedString], [column objectForKey:@"Size"]]]; - } - else { - [tempIndexedColumns addObject:[columnName backtickQuotedString]]; + if ([column objectForKey:@"Size"] && [supportsLength containsObject:columnType] && !isFullTextType) { + [tempIndexedColumns addObject:[NSString stringWithFormat:@"%@ (%@)", [columnName backtickQuotedString], [column objectForKey:@"Size"]]]; + } + else { + [tempIndexedColumns addObject:[columnName backtickQuotedString]]; + } } - } - if ([tempIndexedColumns count]) { + if ([tempIndexedColumns count]) { - if ((![indexType isEqualToString:@"INDEX"]) && (![indexType isEqualToString:@"PRIMARY KEY"])) indexType = [indexType stringByAppendingFormat:@" INDEX"]; + if ((![indexType isEqualToString:@"INDEX"]) && (![indexType isEqualToString:@"PRIMARY KEY"])) indexType = [indexType stringByAppendingFormat:@" INDEX"]; - // Build the query - NSMutableString *query = [NSMutableString stringWithFormat:@"ALTER TABLE %@ ADD %@", [table backtickQuotedString], indexType]; + // Build the query + NSMutableString *query = [NSMutableString stringWithFormat:@"ALTER TABLE %@ ADD %@", [table backtickQuotedString], indexType]; - // If supplied specify the index's name - if ([indexName length]) { - [query appendString:@" "]; - [query appendString:indexName]; - } + // If supplied specify the index's name + if ([indexName length]) { + [query appendString:@" "]; + [query appendString:indexName]; + } - // If supplied specify the index's storage type - if (indexStorageType) { - [query appendString:@" USING "]; - [query appendString:indexStorageType]; - } + // If supplied specify the index's storage type + if (indexStorageType) { + [query appendString:@" USING "]; + [query appendString:indexStorageType]; + } - // Add the columns - [query appendFormat:@" (%@)", [tempIndexedColumns componentsJoinedByCommas]]; + // Add the columns + [query appendFormat:@" (%@)", [tempIndexedColumns componentsJoinedByCommas]]; - // If supplied specify the index's key block size - if (indexKeyBlockSize) { - [query appendFormat:@" KEY_BLOCK_SIZE = %ld", (long)[indexKeyBlockSize integerValue]]; - } + // If supplied specify the index's key block size + if (indexKeyBlockSize) { + [query appendFormat:@" KEY_BLOCK_SIZE = %ld", (long)[indexKeyBlockSize integerValue]]; + } - // Execute the query - [connection queryString:query]; + // Execute the query + [connection queryString:query]; - // Check for errors, but only if the query wasn't cancelled - if ([connection queryErrored] && ![connection lastQueryWasCancelled]) { - SPOnewayAlertSheet( - NSLocalizedString(@"Unable to add index", @"add index error message"), - [dbDocument parentWindow], - [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to add the index.\n\nMySQL said: %@", @"add index error informative message"), [connection lastErrorMessage]] - ); - } - else { - [tableData resetAllData]; - [dbDocument setStatusRequiresReload:YES]; - - [tableStructure loadTable:table]; - } - } + // Check for errors, but only if the query wasn't cancelled + if ([connection queryErrored] && ![connection lastQueryWasCancelled]) { + SPOnewayAlertSheet( + NSLocalizedString(@"Unable to add index", @"add index error message"), + [dbDocument parentWindow], + [NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to add the index.\n\nMySQL said: %@", @"add index error informative message"), [connection lastErrorMessage]] + ); + } + else { + [tableData resetAllData]; + [dbDocument setStatusRequiresReload:YES]; - SPClear(tempIndexedColumns); - } + [tableStructure loadTable:table]; + } + } - // Reset indexed fields to default - [indexedFields removeAllObjects]; - [indexedFields addObject:[[[fields objectAtIndex:0] mutableCopy] autorelease]]; + [tempIndexedColumns release]; + } - [dbDocument endTask]; + // Reset indexed fields to default + [indexedFields removeAllObjects]; + [indexedFields addObject:[[[fields objectAtIndex:0] mutableCopy] autorelease]]; - [pool drain]; + [dbDocument endTask]; + } } /** @@ -889,61 +886,62 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; */ - (void)_removeIndexUsingDetails:(NSDictionary *)indexDetails { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + @autoreleasepool { + NSString *index = [indexDetails objectForKey:@"Key_name"]; + NSString *fkName = [indexDetails objectForKey:@"ForeignKey"]; - NSString *index = [indexDetails objectForKey:@"Key_name"]; - NSString *fkName = [indexDetails objectForKey:@"ForeignKey"]; + // Remove the foreign key dependency before the index if required + if ([fkName length]) { - // Remove the foreign key dependency before the index if required - if ([fkName length]) { + [connection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP FOREIGN KEY %@", [table backtickQuotedString], [fkName backtickQuotedString]]]; - [connection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP FOREIGN KEY %@", [table backtickQuotedString], [fkName backtickQuotedString]]]; + // Check for errors, but only if the query wasn't cancelled + if ([connection queryErrored] && ![connection lastQueryWasCancelled]) { + NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionary]; - // Check for errors, but only if the query wasn't cancelled - if ([connection queryErrored] && ![connection lastQueryWasCancelled]) { - NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionary]; + [errorDictionary setObject:NSLocalizedString(@"Unable to delete relation", @"error deleting relation message") forKey:@"title"]; + [errorDictionary setObject:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to delete the relation '%@'.\n\nMySQL said: %@", @"error deleting relation informative message"), fkName, [connection lastErrorMessage]] forKey:@"message"]; - [errorDictionary setObject:NSLocalizedString(@"Unable to delete relation", @"error deleting relation message") forKey:@"title"]; - [errorDictionary setObject:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to delete the relation '%@'.\n\nMySQL said: %@", @"error deleting relation informative message"), fkName, [connection lastErrorMessage]] forKey:@"message"]; + [[tableStructure onMainThread] showErrorSheetWith:errorDictionary]; + } + } - [(SPTableStructure*)[tableStructure onMainThread] showErrorSheetWith:errorDictionary]; + if ([index isEqualToString:@"PRIMARY"]) { + [connection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP PRIMARY KEY", [table backtickQuotedString]]]; + } + else { + [connection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP INDEX %@", + [table backtickQuotedString], [index backtickQuotedString]]]; } - } - if ([index isEqualToString:@"PRIMARY"]) { - [connection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP PRIMARY KEY", [table backtickQuotedString]]]; - } - else { - [connection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ DROP INDEX %@", - [table backtickQuotedString], [index backtickQuotedString]]]; - } + // Check for errors, but only if the query wasn't cancelled + if ([connection queryErrored] && ![connection lastQueryWasCancelled]) { + //if the last error was 1553 and we did not already try to remove a FK beforehand, we have to request to remove the foreign key before we can remove the index + if([connection lastErrorID] == 1553 /* ER_DROP_INDEX_FK */ && ![fkName length]) { + NSDictionary *details = @{ + @"Key_name": index, + @"error": SPBoxNil([connection lastErrorMessage]) + }; + [self performSelectorOnMainThread:@selector(_removingIndexFailedWithForeignKeyError:) withObject:details waitUntilDone:NO]; + } + else { + NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionary]; - // Check for errors, but only if the query wasn't cancelled - if ([connection queryErrored] && ![connection lastQueryWasCancelled]) { - //if the last error was 1553 and we did not already try to remove a FK beforehand, we have to request to remove the foreign key before we can remove the index - if([connection lastErrorID] == 1553 /* ER_DROP_INDEX_FK */ && ![fkName length]) { - NSDictionary *details = @{@"Key_name": index, @"error": SPBoxNil([connection lastErrorMessage])}; - [self performSelectorOnMainThread:@selector(_removingIndexFailedWithForeignKeyError:) withObject:details waitUntilDone:NO]; + [errorDictionary setObject:NSLocalizedString(@"Unable to delete index", @"error deleting index message") forKey:@"title"]; + [errorDictionary setObject:[NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to delete the index.\n\nMySQL said: %@", @"error deleting index informative message"), [connection lastErrorMessage]] forKey:@"message"]; + + [[tableStructure onMainThread] showErrorSheetWith:errorDictionary]; + } } else { - NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionary]; - - [errorDictionary setObject:NSLocalizedString(@"Unable to delete index", @"error deleting index message") forKey:@"title"]; - [errorDictionary setObject:[NSString stringWithFormat:NSLocalizedString(@"An error occured while trying to delete the index.\n\nMySQL said: %@", @"error deleting index informative message"), [connection lastErrorMessage]] forKey:@"message"]; - - [(SPTableStructure*)[tableStructure onMainThread] showErrorSheetWith:errorDictionary]; + [tableData resetAllData]; + [dbDocument setStatusRequiresReload:YES]; + + [tableStructure loadTable:table]; } - } - else { - [tableData resetAllData]; - [dbDocument setStatusRequiresReload:YES]; - [tableStructure loadTable:table]; + [dbDocument endTask]; } - - [dbDocument endTask]; - - [pool drain]; } /** |