Skip to content

Commit

Permalink
Fix an issue where the wrong table could be deleted when switching ta…
Browse files Browse the repository at this point in the history
…bles (by key press) fast enough after confirming deletion (#2742)

This was caused by the delete code being called via a `performSelector:…` timer event instead of directly, which gave the run loop a chance to handle the key event between confirming the delete and actually executing it.
  • Loading branch information
dmoagx committed Mar 26, 2017
1 parent 430ff7b commit 2aad505
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions Source/SPTablesList.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@

@interface SPTablesList ()

- (void)_removeTable:(NSNumber *)force;
- (void)_removeTable:(BOOL)force;
- (void)_truncateTable;
- (void)_addTable;
- (void)_copyTable;
Expand Down Expand Up @@ -730,9 +730,7 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt
}
else if ([contextInfo isEqualToString:SPRemoveTable]) {
if (returnCode == NSAlertDefaultReturn) {
[self performSelector:@selector(_removeTable:)
withObject:[NSNumber numberWithInteger:[[(NSAlert *)sheet suppressionButton] state]]
afterDelay:0.0];
[self _removeTable:([[(NSAlert *)sheet suppressionButton] state] == NSOnState)];
}
}
#ifndef SP_CODA
Expand Down Expand Up @@ -2185,7 +2183,7 @@ - (void)setDatabaseDocument:(SPDatabaseDocument*)val
/**
* Removes the selected object (table, view, procedure, function, etc.) from the database and tableView.
*/
- (void)_removeTable:(NSNumber *)force
- (void)_removeTable:(BOOL)force
{
NSIndexSet *indexes = [tablesListView selectedRowIndexes];

Expand All @@ -2194,7 +2192,7 @@ - (void)_removeTable:(NSNumber *)force
// Get last index
NSUInteger currentIndex = [indexes lastIndex];

if ([force boolValue]) {
if (force) {
[mySQLConnection queryString:@"SET FOREIGN_KEY_CHECKS = 0"];
}

Expand Down Expand Up @@ -2274,7 +2272,7 @@ - (void)_removeTable:(NSNumber *)force
}
}

if ([force boolValue]) {
if (force) {
[mySQLConnection queryString:@"SET FOREIGN_KEY_CHECKS = 1"];
}

Expand Down

0 comments on commit 2aad505

Please sign in to comment.