From 7e023c253e72c9a27bba0728160fbb8aaf19ffd1 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 15 Oct 2009 13:45:35 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20the=20chance=20to=20set=20"allowCon?= =?UTF-8?q?soleUpdate"=20-=20if=20set=20to=20YES=20the=20Console=20Log=20w?= =?UTF-8?q?on't=20be=20updated=20after=20adding=20a=20new=20message=20even?= =?UTF-8?q?=20if=20the=20window=20is=20visible;=20this=20is=20useful=20if?= =?UTF-8?q?=20SP=20has=20to=20execute=20a=20large=20number=20of=20queries?= =?UTF-8?q?=20=E2=80=A2=20first=20steps=20to=20increase=20the=20deletion?= =?UTF-8?q?=20of=20a=20large=20number=20of=20rows=20in=20the=20Content=20p?= =?UTF-8?q?ane=20-=20removed=20deprecated=20'selectedRowEnumerator'=20-=20?= =?UTF-8?q?set=20Console=20Log's=20'allowConsoleUpdate'=20to=20NO=20if=20m?= =?UTF-8?q?ore=20than=2010=20rows=20should=20be=20deleted=20-=20instead=20?= =?UTF-8?q?of=20adding=20the=20successful=20deleted=20row=20indexes=20into?= =?UTF-8?q?=20a=20new=20array=20delete=20these=20indexes=20from=20the=20se?= =?UTF-8?q?lectedRows=20NSIndexSet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPQueryController.h | 2 ++ Source/SPQueryController.m | 36 ++++++++++++++-------------- Source/TableContent.m | 58 +++++++++++++++++++++++++++++----------------- 3 files changed, 58 insertions(+), 38 deletions(-) (limited to 'Source') diff --git a/Source/SPQueryController.h b/Source/SPQueryController.h index 65287961..8a350a32 100644 --- a/Source/SPQueryController.h +++ b/Source/SPQueryController.h @@ -42,6 +42,7 @@ BOOL showSelectStatementsAreDisabled; BOOL showHelpStatementsAreDisabled; BOOL filterIsActive; + BOOL allowConsoleUpdate; NSMutableString *activeFilterString; @@ -57,6 +58,7 @@ } @property (readwrite, retain) NSFont *consoleFont; +@property (readwrite) BOOL allowConsoleUpdate; + (SPQueryController *)sharedQueryController; diff --git a/Source/SPQueryController.m b/Source/SPQueryController.m index 86fa9908..3a3a2982 100644 --- a/Source/SPQueryController.m +++ b/Source/SPQueryController.m @@ -54,32 +54,33 @@ static SPQueryController *sharedQueryController = nil; @implementation SPQueryController @synthesize consoleFont; +@synthesize allowConsoleUpdate; /* * Returns the shared query console. */ + (SPQueryController *)sharedQueryController { - @synchronized(self) { - if (sharedQueryController == nil) { - [[self alloc] init]; - } - } - - return sharedQueryController; + @synchronized(self) { + if (sharedQueryController == nil) { + [[self alloc] init]; + } + } + + return sharedQueryController; } + (id)allocWithZone:(NSZone *)zone { - @synchronized(self) { - if (sharedQueryController == nil) { - sharedQueryController = [super allocWithZone:zone]; - - return sharedQueryController; - } - } - - return nil; // On subsequent allocation attempts return nil + @synchronized(self) { + if (sharedQueryController == nil) { + sharedQueryController = [super allocWithZone:zone]; + + return sharedQueryController; + } + } + + return nil; // On subsequent allocation attempts return nil } - (id)init @@ -98,6 +99,7 @@ static SPQueryController *sharedQueryController = nil; untitledDocumentCounter = 1; numberOfMaxAllowedHistory = 100; + allowConsoleUpdate = YES; favoritesContainer = [[NSMutableDictionary alloc] init]; historyContainer = [[NSMutableDictionary alloc] init]; @@ -757,7 +759,7 @@ static SPQueryController *sharedQueryController = nil; } // Reload the table and scroll to the new message if it's visible (for speed) - if ( [[self window] isVisible] ) { + if ( allowConsoleUpdate && [[self window] isVisible] ) { [consoleTableView reloadData]; [consoleTableView scrollRowToVisible:([messagesVisibleSet count] - 1)]; } 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]; -- cgit v1.2.3