diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-10-15 13:45:35 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-10-15 13:45:35 +0000 |
commit | 7e023c253e72c9a27bba0728160fbb8aaf19ffd1 (patch) | |
tree | 1e706e19da51c15ee51ee71de4dc69766f45ad6c /Source/TableContent.m | |
parent | 778c3556b551077d488af6378108db0630775953 (diff) | |
download | sequelpro-7e023c253e72c9a27bba0728160fbb8aaf19ffd1.tar.gz sequelpro-7e023c253e72c9a27bba0728160fbb8aaf19ffd1.tar.bz2 sequelpro-7e023c253e72c9a27bba0728160fbb8aaf19ffd1.zip |
• added the chance to set "allowConsoleUpdate"
- if set to YES the Console Log won't be updated after adding a new message even if the window is visible; this is useful if SP has to execute a large number of queries
• first steps to increase the deletion of a large number of rows in the Content pane
- removed deprecated 'selectedRowEnumerator'
- set Console Log's 'allowConsoleUpdate' to NO if more than 10 rows should be deleted
- instead of adding the successful deleted row indexes into a new array delete these indexes from the selectedRows NSIndexSet
Diffstat (limited to 'Source/TableContent.m')
-rw-r--r-- | Source/TableContent.m | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m index 8df1bbc1..5ceb6682 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -1725,12 +1725,13 @@ if contextInfo == removerow: removes row if user hits OK */ { - NSEnumerator *enumerator = [tableContentView selectedRowEnumerator]; - NSNumber *index; - NSMutableArray *tempArray = [NSMutableArray array]; + NSMutableArray *tempResult = [NSMutableArray array]; + NSMutableIndexSet *selectedRows = [NSMutableIndexSet indexSet]; NSString *wherePart; - int i, errors; + NSInteger i, errors; + BOOL consoleUpdateStatus; + BOOL reloadAfterRemovingRow = [prefs boolForKey:@"ReloadAfterRemovingRow"]; if ( [contextInfo isEqualToString:@"addrow"] ) { [sheet orderOut:self]; @@ -1767,29 +1768,44 @@ } } else if ( [contextInfo isEqualToString:@"removerow"] ) { if ( returnCode == NSAlertDefaultReturn ) { + errors = 0; - - while ( (index = [enumerator nextObject]) ) { - wherePart = [NSString stringWithString:[self argumentForRow:[index intValue]]]; + + [selectedRows addIndexes:[tableContentView selectedRowIndexes]]; + + // Disable updating of the Console Log window for large number of queries + // to speed the deletion + consoleUpdateStatus = [[SPQueryController sharedQueryController] allowConsoleUpdate]; + if([selectedRows count] > 10) + [[SPQueryController sharedQueryController] setAllowConsoleUpdate:NO]; + + NSUInteger index = [selectedRows firstIndex]; + + while (index != NSNotFound) { + + wherePart = [NSString stringWithString:[self argumentForRow:index]]; + //argumentForRow might return empty query, in which case we shouldn't execute the partial query - if([wherePart length] > 0) { + if([wherePart length]) { [mySQLConnection queryString:[NSString stringWithFormat:@"DELETE FROM %@ WHERE %@", [selectedTable backtickQuotedString], wherePart]]; - if ( ![mySQLConnection affectedRows] ) { - //no rows deleted - errors++; - } else if ( [[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - //rows deleted with success - [tempArray addObject:index]; - } else { - //error in mysql-query + + // Check for errors + if ( ![mySQLConnection affectedRows] || ![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + // If error delete that index from selectedRows for reloading table if + // "ReloadAfterRemovingRow" is disbaled + if(!reloadAfterRemovingRow) + [selectedRows removeIndex:index]; errors++; } } else { errors++; } - + index = [selectedRows indexGreaterThanIndex:index]; } - + + // Restore Console Log window's updating bahaviour + [[SPQueryController sharedQueryController] setAllowConsoleUpdate:consoleUpdateStatus]; + if ( errors ) { [self performSelector:@selector(showErrorSheetWith:) withObject:[NSArray arrayWithObjects:NSLocalizedString(@"Warning", @"warning"), @@ -1798,13 +1814,13 @@ afterDelay:0.3]; } - //do deleting (after enumerating) - if ( [prefs boolForKey:@"ReloadAfterRemovingRow"] ) { + // Refresh table content + if ( reloadAfterRemovingRow ) { [self loadTableValues]; [tableContentView reloadData]; } else { for ( i = 0 ; i < [tableValues count] ; i++ ) { - if ( ![tempArray containsObject:[NSNumber numberWithInt:i]] ) + if ( ![selectedRows containsIndex:i] ) [tempResult addObject:NSArrayObjectAtIndex(tableValues, i)]; } [tableValues setArray:tempResult]; |