aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/SPQueryController.h2
-rw-r--r--Source/SPQueryController.m36
-rw-r--r--Source/TableContent.m58
3 files changed, 58 insertions, 38 deletions
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];