aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax Lohrmann <dmoagx@users.noreply.github.com>2017-03-12 09:46:59 +0100
committerMax Lohrmann <dmoagx@users.noreply.github.com>2017-03-12 09:46:59 +0100
commit95250e0f0c5780ac113a9a4c948c452038b4c02a (patch)
tree18d41b1a2bae49b38e58d986e5d3934aac8b3227 /Source
parentf5e022b6667815a05c0b2478db07f50af2e52d0b (diff)
downloadsequelpro-95250e0f0c5780ac113a9a4c948c452038b4c02a.tar.gz
sequelpro-95250e0f0c5780ac113a9a4c948c452038b4c02a.tar.bz2
sequelpro-95250e0f0c5780ac113a9a4c948c452038b4c02a.zip
Replace some legacy NSIndexSet enumeration with 10.6+ style -enumerateIndexesUsingBlock:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPAppController.m6
-rw-r--r--Source/SPArrayAdditions.m8
-rw-r--r--Source/SPConnectionController.m13
-rw-r--r--Source/SPContentFilterManager.m17
-rw-r--r--Source/SPCopyTable.m69
-rw-r--r--Source/SPFieldMapperController.m17
-rw-r--r--Source/SPProcessListController.m9
-rw-r--r--Source/SPQueryController.m9
-rw-r--r--Source/SPQueryFavoriteManager.m15
-rw-r--r--Source/SPServerVariablesController.m16
-rw-r--r--Source/SPTableRelations.m13
-rw-r--r--Source/SPTableTriggers.m11
-rw-r--r--Source/SPTablesList.m59
13 files changed, 83 insertions, 179 deletions
diff --git a/Source/SPAppController.m b/Source/SPAppController.m
index 24b981af..c7412419 100644
--- a/Source/SPAppController.m
+++ b/Source/SPAppController.m
@@ -1323,11 +1323,9 @@
if([firstResponder numberOfSelectedRows]) {
NSMutableArray *sel = [NSMutableArray array];
NSIndexSet *selectedRows = [firstResponder selectedRowIndexes];
- NSUInteger rowIndex = [selectedRows firstIndex];
- while ( rowIndex != NSNotFound ) {
+ [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
[sel addObject:[NSString stringWithFormat:@"%ld", (long)rowIndex]];
- rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
- }
+ }];
[env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices];
}
diff --git a/Source/SPArrayAdditions.m b/Source/SPArrayAdditions.m
index 0fe75483..0b851c1d 100644
--- a/Source/SPArrayAdditions.m
+++ b/Source/SPArrayAdditions.m
@@ -133,14 +133,10 @@
NSMutableArray *subArray = [NSMutableArray arrayWithCapacity:[indexes count]];
NSUInteger count = [self count];
- NSUInteger index = [indexes firstIndex];
- while ( index != NSNotFound )
- {
+ [indexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL * _Nonnull stop) {
if ( index < count )
[subArray addObject: [self objectAtIndex: index]];
-
- index = [indexes indexGreaterThanIndex: index];
- }
+ }];
return subArray;
}
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index a2159b4f..9a8f9e2e 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -875,14 +875,9 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
NSMutableArray *nodes = [NSMutableArray array];
NSIndexSet *indexes = [favoritesOutlineView selectedRowIndexes];
- NSUInteger currentIndex = [indexes firstIndex];
-
- while (currentIndex != NSNotFound)
- {
+ [indexes enumerateIndexesUsingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[nodes addObject:[favoritesOutlineView itemAtRow:currentIndex]];
-
- currentIndex = [indexes indexGreaterThanIndex:currentIndex];
- }
+ }];
return nodes;
}
@@ -1604,8 +1599,8 @@ static NSComparisonResult _compareFavoritesUsingKey(id favorite1, id favorite2,
[self _sortTreeNode:treeNode usingKey:key];
}
}
-
- NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
+#warning What is this supposed to do? We create an empty indexset, iterate it (still empty) and release it again!?
+ NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
NSUInteger i = [indexes lastIndex];
diff --git a/Source/SPContentFilterManager.m b/Source/SPContentFilterManager.m
index fe20bcf1..6356f416 100644
--- a/Source/SPContentFilterManager.m
+++ b/Source/SPContentFilterManager.m
@@ -609,11 +609,9 @@ static NSString *SPExportFilterAction = @"SPExportFilter";
// TODO: still rely on a NSArray but in the future rewrite it to use the NSIndexSet directly
NSMutableArray *draggedRows = [[NSMutableArray alloc] initWithCapacity:1];
- NSUInteger rowIndex = [draggedIndexes firstIndex];
- while ( rowIndex != NSNotFound ) {
+ [draggedIndexes enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
[draggedRows addObject:[NSNumber numberWithInteger:rowIndex]];
- rowIndex = [draggedIndexes indexGreaterThanIndex: rowIndex];
- }
+ }];
NSInteger destinationRow = row;
@@ -805,16 +803,9 @@ static NSString *SPExportFilterAction = @"SPExportFilter";
if (returnCode == NSAlertDefaultReturn) {
NSIndexSet *indexes = [contentFilterTableView selectedRowIndexes];
- // Get last index
- NSUInteger currentIndex = [indexes lastIndex];
-
- while (currentIndex != NSNotFound)
- {
+ [indexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[contentFilters removeObjectAtIndex:currentIndex];
-
- // Get next index (beginning from the end)
- currentIndex = [indexes indexLessThanIndex:currentIndex];
- }
+ }];
if ([contentFilters count] == 2) {
[contentFilterNameTextField setStringValue:@""];
diff --git a/Source/SPCopyTable.m b/Source/SPCopyTable.m
index 8a8c8fa9..ed7b1d71 100644
--- a/Source/SPCopyTable.m
+++ b/Source/SPCopyTable.m
@@ -168,19 +168,15 @@ static const NSInteger kBlobAsImageFile = 4;
[result appendString:@"\n"];
}
- NSUInteger c;
- id cellData = nil;
-
// Create an array of table column mappings for fast iteration
NSUInteger *columnMappings = calloc(numColumns, sizeof(NSUInteger));
- for ( c = 0; c < numColumns; c++ )
- columnMappings[c] = (NSUInteger)[[NSArrayObjectAtIndex(columns, c) identifier] integerValue];
+ for (NSUInteger ci = 0; ci < numColumns; ci++ )
+ columnMappings[ci] = (NSUInteger)[[NSArrayObjectAtIndex(columns, ci) identifier] integerValue];
// Loop through the rows, adding their descriptive contents
- NSUInteger rowIndex = [selectedRows firstIndex];
NSString *nullString = [prefs objectForKey:SPNullValue];
Class spmysqlGeometryData = [SPMySQLGeometryData class];
- NSUInteger rowCounter = 0;
+ __block NSUInteger rowCounter = 0;
if((withBlobHandling == kBlobAsFile || withBlobHandling == kBlobAsImageFile) && tmpBlobFileDirectory && [tmpBlobFileDirectory length]) {
NSFileManager *fm = [NSFileManager defaultManager];
@@ -188,10 +184,9 @@ static const NSInteger kBlobAsImageFile = 4;
[fm createDirectoryAtPath:tmpBlobFileDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}
- while ( rowIndex != NSNotFound )
- {
- for ( c = 0; c < numColumns; c++ ) {
- cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
+ [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
+ for (NSUInteger c = 0; c < numColumns; c++ ) {
+ id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
// Copy the shown representation of the cell - custom NULL display strings, (not loaded),
// definable representation of any blobs or binary texts.
@@ -262,10 +257,7 @@ static const NSInteger kBlobAsImageFile = 4;
[result deleteCharactersInRange:NSMakeRange([result length]-1, 1)];
}
[result appendString:@"\n"];
-
- // Select the next row index
- rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
- }
+ }];
// Remove the trailing line end
if ([result length]) {
@@ -306,20 +298,16 @@ static const NSInteger kBlobAsImageFile = 4;
[result appendString:@"\n"];
}
- NSUInteger c;
- id cellData = nil;
-
// Create an array of table column mappings for fast iteration
NSUInteger *columnMappings = calloc(numColumns, sizeof(NSUInteger));
- for ( c = 0; c < numColumns; c++ )
- columnMappings[c] = (NSUInteger)[[NSArrayObjectAtIndex(columns, c) identifier] integerValue];
+ for (NSUInteger ci = 0; ci < numColumns; ci++ )
+ columnMappings[ci] = (NSUInteger)[[NSArrayObjectAtIndex(columns, ci) identifier] integerValue];
// Loop through the rows, adding their descriptive contents
- NSUInteger rowIndex = [selectedRows firstIndex];
NSString *nullString = [prefs objectForKey:SPNullValue];
Class spmysqlGeometryData = [SPMySQLGeometryData class];
- NSUInteger rowCounter = 0;
+ __block NSUInteger rowCounter = 0;
if((withBlobHandling == kBlobAsFile || withBlobHandling == kBlobAsImageFile) && tmpBlobFileDirectory && [tmpBlobFileDirectory length]) {
NSFileManager *fm = [NSFileManager defaultManager];
@@ -327,10 +315,9 @@ static const NSInteger kBlobAsImageFile = 4;
[fm createDirectoryAtPath:tmpBlobFileDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}
- while ( rowIndex != NSNotFound )
- {
- for ( c = 0; c < numColumns; c++ ) {
- cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
+ [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
+ for (NSUInteger c = 0; c < numColumns; c++ ) {
+ id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
// Copy the shown representation of the cell - custom NULL display strings, (not loaded),
// definable representation of any blobs or binary texts.
@@ -401,10 +388,7 @@ static const NSInteger kBlobAsImageFile = 4;
[result deleteCharactersInRange:NSMakeRange([result length]-1, 1)];
}
[result appendString:@"\n"];
-
- // Select the next row index
- rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
- }
+ }];
// Remove the trailing line end
if ([result length]) {
@@ -625,24 +609,20 @@ static const NSInteger kBlobAsImageFile = 4;
NSIndexSet *selectedRows = [self selectedRowIndexes];
NSMutableString *result = [NSMutableString stringWithCapacity:2000];
- NSUInteger c;
- id cellData = nil;
// Create an array of table column mappings for fast iteration
NSUInteger *columnMappings = calloc(numColumns, sizeof(NSUInteger));
- for ( c = 0; c < numColumns; c++ )
- columnMappings[c] = (NSUInteger)[[NSArrayObjectAtIndex(columns, c) identifier] integerValue];
+ for (NSUInteger ci = 0; ci < numColumns; ci++ )
+ columnMappings[ci] = (NSUInteger)[[NSArrayObjectAtIndex(columns, ci) identifier] integerValue];
// Loop through the rows, adding their descriptive contents
- NSUInteger rowIndex = [selectedRows firstIndex];
NSString *nullString = [prefs objectForKey:SPNullValue];
Class nsDataClass = [NSData class];
Class spmysqlGeometryData = [SPMySQLGeometryData class];
NSStringEncoding connectionEncoding = [mySQLConnection stringEncoding];
- while ( rowIndex != NSNotFound )
- {
- for ( c = 0; c < numColumns; c++ ) {
- cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
+ [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
+ for (NSUInteger c = 0; c < numColumns; c++ ) {
+ id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
// Copy the shown representation of the cell - custom NULL display strings, (not loaded),
// and the string representation of any blobs or binary texts.
@@ -673,10 +653,7 @@ static const NSInteger kBlobAsImageFile = 4;
}
[result appendString:@"\n"];
-
- // Retrieve the next selected row index
- rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
- }
+ }];
// Trim the trailing line ending
if ([result length]) {
@@ -1307,11 +1284,9 @@ static const NSInteger kBlobAsImageFile = 4;
if([self numberOfSelectedRows]) {
NSMutableArray *sel = [NSMutableArray array];
NSIndexSet *selectedRows = [self selectedRowIndexes];
- NSUInteger rowIndex = [selectedRows firstIndex];
- while ( rowIndex != NSNotFound ) {
+ [selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
[sel addObject:[NSString stringWithFormat:@"%llu", (unsigned long long)rowIndex]];
- rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
- }
+ }];
[env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices];
}
diff --git a/Source/SPFieldMapperController.m b/Source/SPFieldMapperController.m
index 6d5caf41..ca40d71a 100644
--- a/Source/SPFieldMapperController.m
+++ b/Source/SPFieldMapperController.m
@@ -992,14 +992,12 @@ static NSUInteger SPSourceColumnTypeInteger = 1;
[toBeEditedRowIndexes removeIndex:toBeRemovedIndex];
// Renumber indexes greater than toBeRemovedIndex
- NSInteger currentIndex = [toBeEditedRowIndexes firstIndex];
- while(currentIndex != NSNotFound) {
- if(currentIndex > toBeRemovedIndex) {
+ [toBeEditedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
+ if(currentIndex > (NSUInteger)toBeRemovedIndex) {
[toBeEditedRowIndexes addIndex:currentIndex-1];
[toBeEditedRowIndexes removeIndex:currentIndex];
}
- currentIndex = [toBeEditedRowIndexes indexGreaterThanIndex:currentIndex];
- }
+ }];
[self _setupFieldMappingPopUpMenus];
[fieldMapperTableView reloadData];
@@ -1155,15 +1153,10 @@ static NSUInteger SPSourceColumnTypeInteger = 1;
NSIndexSet *indexes = [globalValuesTableView selectedRowIndexes];
- // get last index
- NSUInteger currentIndex = [indexes lastIndex];
-
- while (currentIndex != NSNotFound) {
+ [indexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[fieldMappingGlobalValues removeObjectAtIndex:currentIndex+numberOfImportColumns];
[fieldMappingGlobalValuesSQLMarked removeObjectAtIndex:currentIndex+numberOfImportColumns];
- // get next index (beginning from the end)
- currentIndex = [indexes indexLessThanIndex:currentIndex];
- }
+ }];
[globalValuesTableView reloadData];
diff --git a/Source/SPProcessListController.m b/Source/SPProcessListController.m
index d04273e1..84cd32e8 100644
--- a/Source/SPProcessListController.m
+++ b/Source/SPProcessListController.m
@@ -140,10 +140,7 @@ static NSString *SPTableViewIDColumnIdentifier = @"Id";
NSMutableString *string = [NSMutableString string];
NSIndexSet *rows = [processListTableView selectedRowIndexes];
- NSUInteger i = [rows firstIndex];
-
- while (i != NSNotFound)
- {
+ [rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) {
if (i < [processesFiltered count]) {
NSDictionary *process = NSArrayObjectAtIndex(processesFiltered, i);
@@ -160,9 +157,7 @@ static NSString *SPTableViewIDColumnIdentifier = @"Id";
[string appendString:stringTmp];
[string appendString:@"\n"];
}
-
- i = [rows indexGreaterThanIndex:i];
- }
+ }];
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m
index c57621d8..dbdc3d44 100644
--- a/Source/SPQueryController.m
+++ b/Source/SPQueryController.m
@@ -158,16 +158,13 @@ static SPQueryController *sharedQueryController = nil;
NSMutableString *string = [NSMutableString string];
NSIndexSet *rows = [consoleTableView selectedRowIndexes];
- NSUInteger i = [rows firstIndex];
-
BOOL includeTimestamps = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] isHidden];
BOOL includeConnections = ![[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] isHidden];
BOOL includeDatabases = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] isHidden];
[string setString:@""];
- while (i != NSNotFound)
- {
+ [rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) {
if (i < [messagesVisibleSet count]) {
SPConsoleMessage *message = NSArrayObjectAtIndex(messagesVisibleSet, i);
@@ -195,9 +192,7 @@ static SPQueryController *sharedQueryController = nil;
[string appendFormat:@"%@\n", [message message]];
}
-
- i = [rows indexGreaterThanIndex:i];
- }
+ }];
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
diff --git a/Source/SPQueryFavoriteManager.m b/Source/SPQueryFavoriteManager.m
index ceb1efc4..2f88bbcf 100644
--- a/Source/SPQueryFavoriteManager.m
+++ b/Source/SPQueryFavoriteManager.m
@@ -730,11 +730,9 @@
// TODO: still rely on a NSArray but in the future rewrite it to use the NSIndexSet directly
NSMutableArray *draggedRows = [[NSMutableArray alloc] initWithCapacity:1];
- NSUInteger rowIndex = [draggedIndexes firstIndex];
- while ( rowIndex != NSNotFound ) {
+ [draggedIndexes enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
[draggedRows addObject:[NSNumber numberWithUnsignedInteger:rowIndex]];
- rowIndex = [draggedIndexes indexGreaterThanIndex: rowIndex];
- }
+ }];
NSInteger destinationRow = row;
NSInteger offset = 0;
@@ -791,14 +789,9 @@
if (returnCode == NSAlertDefaultReturn) {
NSIndexSet *indexes = [favoritesTableView selectedRowIndexes];
- // get last index
- NSUInteger currentIndex = [indexes lastIndex];
-
- while (currentIndex != NSNotFound) {
+ [indexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[favorites removeObjectAtIndex:currentIndex];
- // get next index (beginning from the end)
- currentIndex = [indexes indexLessThanIndex:currentIndex];
- }
+ }];
[favoritesArrayController rearrangeObjects];
[favoritesTableView reloadData];
diff --git a/Source/SPServerVariablesController.m b/Source/SPServerVariablesController.m
index dade0687..d99f8671 100644
--- a/Source/SPServerVariablesController.m
+++ b/Source/SPServerVariablesController.m
@@ -342,13 +342,10 @@
if ((firstResponder == variablesTableView) && ([variablesTableView numberOfSelectedRows] > 0)) {
- NSString *string = @"";
+ NSMutableString *string = [[NSMutableString alloc] init];
NSIndexSet *rows = [variablesTableView selectedRowIndexes];
- NSUInteger i = [rows firstIndex];
-
- while (i != NSNotFound)
- {
+ [rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) {
if (i < [variablesFiltered count]) {
NSDictionary *variable = NSArrayObjectAtIndex(variablesFiltered, i);
@@ -357,21 +354,20 @@
// Decide what to include in the string
if (name && value) {
- string = [string stringByAppendingFormat:@"%@ = %@\n", variableName, variableValue];
+ [string appendFormat:@"%@ = %@\n", variableName, variableValue];
}
else {
- string = [string stringByAppendingFormat:@"%@\n", (name) ? variableName : variableValue];
+ [string appendFormat:@"%@\n", (name) ? variableName : variableValue];
}
}
-
- i = [rows indexGreaterThanIndex:i];
- }
+ }];
NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];
// Copy the string to the pasteboard
[pasteBoard declareTypes:@[NSStringPboardType] owner:nil];
[pasteBoard setString:string forType:NSStringPboardType];
+ [string release];
}
}
diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m
index f358d133..64a7b98b 100644
--- a/Source/SPTableRelations.m
+++ b/Source/SPTableRelations.m
@@ -529,10 +529,7 @@ static NSString *SPRelationOnDeleteKey = @"on_delete";
NSString *thisTable = [tablesListInstance tableName];
NSIndexSet *selectedSet = [relationsTableView selectedRowIndexes];
- NSUInteger row = [selectedSet lastIndex];
-
- while (row != NSNotFound)
- {
+ [selectedSet enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger row, BOOL * _Nonnull stop) {
NSString *relationName = [[relationData objectAtIndex:row] objectForKey:SPRelationNameKey];
NSString *query = [NSString stringWithFormat:@"ALTER TABLE %@ DROP FOREIGN KEY %@", [thisTable backtickQuotedString], [relationName backtickQuotedString]];
@@ -547,11 +544,9 @@ static NSString *SPRelationOnDeleteKey = @"on_delete";
);
// Abort loop
- break;
- }
-
- row = [selectedSet indexLessThanIndex:row];
- }
+ *stop = YES;
+ }
+ }];
[self _refreshRelationDataForcingCacheRefresh:YES];
}
diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m
index 96d2fb40..02a7503a 100644
--- a/Source/SPTableTriggers.m
+++ b/Source/SPTableTriggers.m
@@ -414,10 +414,7 @@ static SPTriggerEventTag TagForEvent(NSString *mysql);
NSString *database = [tableDocumentInstance database];
NSIndexSet *selectedSet = [triggersTableView selectedRowIndexes];
- NSUInteger row = [selectedSet lastIndex];
-
- while (row != NSNotFound)
- {
+ [selectedSet enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger row, BOOL * _Nonnull stop) {
NSString *triggerName = [[triggerData objectAtIndex:row] objectForKey:SPTriggerName];
NSString *query = [NSString stringWithFormat:@"DROP TRIGGER %@.%@", [database backtickQuotedString], [triggerName backtickQuotedString]];
@@ -431,11 +428,9 @@ static SPTriggerEventTag TagForEvent(NSString *mysql);
[NSString stringWithFormat:NSLocalizedString(@"The selected trigger couldn't be deleted.\n\nMySQL said: %@", @"error deleting trigger informative message"), [connection lastErrorMessage]]
);
// Abort loop
- break;
+ *stop = YES;
}
-
- row = [selectedSet indexLessThanIndex:row];
- }
+ }];
[self _refreshTriggerDataForcingCacheRefresh:YES];
}
diff --git a/Source/SPTablesList.m b/Source/SPTablesList.m
index 3cc8ae3a..b82a44e3 100644
--- a/Source/SPTablesList.m
+++ b/Source/SPTablesList.m
@@ -1212,14 +1212,13 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
- NSUInteger currentIndex = [indexes firstIndex];
- NSMutableArray *selTables = [NSMutableArray array];
+ NSMutableArray *selTables = [NSMutableArray arrayWithCapacity:[indexes count]];
- while (currentIndex != NSNotFound) {
+ [indexes enumerateIndexesUsingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
if([[filteredTableTypes objectAtIndex:currentIndex] integerValue] == SPTableTypeTable)
[selTables addObject:[filteredTables objectAtIndex:currentIndex]];
- currentIndex = [indexes indexGreaterThanIndex:currentIndex];
- }
+ }];
+
return selTables;
}
@@ -1227,13 +1226,12 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
- NSUInteger currentIndex = [indexes firstIndex];
- NSMutableArray *selTables = [NSMutableArray array];
+ NSMutableArray *selTables = [NSMutableArray arrayWithCapacity:[indexes count]];
- while (currentIndex != NSNotFound) {
+ [indexes enumerateIndexesUsingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[selTables addObject:[filteredTables objectAtIndex:currentIndex]];
- currentIndex = [indexes indexGreaterThanIndex:currentIndex];
- }
+ }];
+
return selTables;
}
@@ -1241,13 +1239,12 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
- NSUInteger currentIndex = [indexes firstIndex];
- NSMutableArray *selTables = [NSMutableArray array];
+ NSMutableArray *selTables = [NSMutableArray arrayWithCapacity:[indexes count]];
- while (currentIndex != NSNotFound) {
+ [indexes enumerateIndexesUsingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[selTables addObject:[filteredTableTypes objectAtIndex:currentIndex]];
- currentIndex = [indexes indexGreaterThanIndex:currentIndex];
- }
+ }];
+
return selTables;
}
@@ -2168,7 +2165,7 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
- (void)setDatabaseDocument:(SPDatabaseDocument*)val
{
tableDocumentInstance = val;
- }
+}
#endif
#pragma mark -
@@ -2304,33 +2301,23 @@ static NSString *SPDuplicateTable = @"SPDuplicateTable";
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];
- // Get last index
- NSUInteger currentIndex = [indexes lastIndex];
-
- while (currentIndex != NSNotFound)
- {
+ [indexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[mySQLConnection queryString:[NSString stringWithFormat: @"TRUNCATE TABLE %@", [[filteredTables objectAtIndex:currentIndex] backtickQuotedString]]];
// Couldn't truncate table
if ([mySQLConnection queryErrored]) {
- NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error truncating table", @"error truncating table message")
- defaultButton:NSLocalizedString(@"OK", @"OK button")
- alternateButton:nil
- otherButton:nil
- informativeTextWithFormat:NSLocalizedString(@"An error occurred while trying to truncate the table '%@'.\n\nMySQL said: %@", @"error truncating table informative message"),
- [filteredTables objectAtIndex:currentIndex], [mySQLConnection lastErrorMessage]];
-
- [alert setAlertStyle:NSCriticalAlertStyle];
+ SPOnewayAlertSheetWithStyle(
+ NSLocalizedString(@"Error truncating table", @"error truncating table message"),
+ nil,
+ [tableDocumentInstance parentWindow],
+ [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to truncate the table '%@'.\n\nMySQL said: %@", @"error truncating table informative message"), [filteredTables objectAtIndex:currentIndex], [mySQLConnection lastErrorMessage]],
+ NSCriticalAlertStyle
+ );
- [alert beginSheetModalForWindow:[tableDocumentInstance parentWindow]
- modalDelegate:self
- didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
- contextInfo:@"truncateTableError"];
+ *stop = YES;
}
- // Get next index (beginning from the end)
- currentIndex = [indexes indexLessThanIndex:currentIndex];
- }
+ }];
// Ensure the the table's content view is updated to show that it has been truncated
[tableDocumentInstance setContentRequiresReload:YES];