diff options
author | Abhi Beckert <abhi@abhibeckert.com> | 2016-01-29 06:40:18 +1000 |
---|---|---|
committer | Abhi Beckert <abhi@abhibeckert.com> | 2016-01-29 06:40:18 +1000 |
commit | f4c4300dca0c416c12b3992204778ef9f37981ec (patch) | |
tree | e76a4747bf1c3f82bc037990bf84e3f13062601e /Source/SPTableTriggers.m | |
parent | 465062dacc96c2c84bfe9cff1ded58c14d01bdcd (diff) | |
parent | 3aadea1be33212ca50e7faffcd0620ea976f9d59 (diff) | |
download | sequelpro-f4c4300dca0c416c12b3992204778ef9f37981ec.tar.gz sequelpro-f4c4300dca0c416c12b3992204778ef9f37981ec.tar.bz2 sequelpro-f4c4300dca0c416c12b3992204778ef9f37981ec.zip |
Merge remote-tracking branch 'sequelpro/master'
Diffstat (limited to 'Source/SPTableTriggers.m')
-rw-r--r-- | Source/SPTableTriggers.m | 90 |
1 files changed, 61 insertions, 29 deletions
diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m index 179e509e..96d2fb40 100644 --- a/Source/SPTableTriggers.m +++ b/Source/SPTableTriggers.m @@ -47,6 +47,20 @@ static const NSString *SPTriggerDefiner = @"TriggerDefiner"; static const NSString *SPTriggerCreated = @"TriggerCreated"; static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; +typedef NS_ENUM(NSInteger, SPTriggerActionTimeTag) { + SPTriggerActionTimeBeforeTag = 0, + SPTriggerActionTimeAfterTag = 1 +}; + +typedef NS_ENUM(NSInteger, SPTriggerEventTag) { + SPTriggerEventInsertTag = 0, + SPTriggerEventUpdateTag = 1, + SPTriggerEventDeleteTag = 2 +}; + +static SPTriggerActionTimeTag TagForActionTime(NSString *mysql); +static SPTriggerEventTag TagForEvent(NSString *mysql); + @interface SPTableTriggers () - (void)_editTriggerAtIndex:(NSInteger)index; @@ -199,7 +213,7 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; if ([connection queryErrored]) { SPBeginAlertSheet(NSLocalizedString(@"Unable to delete trigger", @"error deleting trigger message"), NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], self, @selector(_reopenTriggerSheet:returnCode:contextInfo:), nil, + nil, nil, [NSApp mainWindow], self, @selector(_reopenTriggerSheet:returnCode:contextInfo:), NULL, [NSString stringWithFormat:NSLocalizedString(@"The selected trigger couldn't be deleted.\n\nMySQL said: %@", @"error deleting trigger informative message"), [connection lastErrorMessage]]); @@ -208,18 +222,29 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; } NSString *triggerName = [triggerNameTextField stringValue]; - NSString *triggerActionTime = ([triggerActionTimePopUpButton indexOfSelectedItem]) ? @"AFTER" : @"BEFORE"; - NSString *triggerEvent = @""; - switch ([triggerEventPopUpButton indexOfSelectedItem]) + NSString *triggerActionTime = @""; + switch ([triggerActionTimePopUpButton selectedTag]) + { + case SPTriggerActionTimeBeforeTag: + triggerActionTime = @"BEFORE"; + break; + + case SPTriggerActionTimeAfterTag: + triggerActionTime = @"AFTER"; + break; + } + + NSString *triggerEvent = @""; + switch ([triggerEventPopUpButton selectedTag]) { - case 0: + case SPTriggerEventInsertTag: triggerEvent = @"INSERT"; break; - case 1: + case SPTriggerEventUpdateTag: triggerEvent = @"UPDATE"; break; - case 2: + case SPTriggerEventDeleteTag: triggerEvent = @"DELETE"; break; } @@ -256,7 +281,7 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; SPBeginAlertSheet(NSLocalizedString(@"Error creating trigger", @"error creating trigger message"), NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], self, @selector(_reopenTriggerSheet:returnCode:contextInfo:), nil, + nil, nil, [NSApp mainWindow], self, @selector(_reopenTriggerSheet:returnCode:contextInfo:), NULL, [NSString stringWithFormat:NSLocalizedString(@"The specified trigger was unable to be created.\n\nMySQL said: %@", @"error creating trigger informative message"), createTriggerError]); } @@ -400,11 +425,11 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; if ([connection queryErrored]) { [[alert window] orderOut:self]; - SPBeginAlertSheet(NSLocalizedString(@"Unable to delete trigger", @"error deleting trigger message"), - NSLocalizedString(@"OK", @"OK button"), - nil, nil, [tableDocumentInstance parentWindow], nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"The selected trigger couldn't be deleted.\n\nMySQL said: %@", @"error deleting trigger informative message"), [connection lastErrorMessage]]); - + SPOnewayAlertSheet( + NSLocalizedString(@"Unable to delete trigger", @"error deleting trigger message"), + [tableDocumentInstance parentWindow], + [NSString stringWithFormat:NSLocalizedString(@"The selected trigger couldn't be deleted.\n\nMySQL said: %@", @"error deleting trigger informative message"), [connection lastErrorMessage]] + ); // Abort loop break; } @@ -531,23 +556,9 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; [triggerNameTextField setStringValue:[trigger objectForKey:SPTriggerName]]; [triggerStatementTextView setString:[trigger objectForKey:SPTriggerStatement]]; - // Timin title is different then what we have saved in the database (case difference) - for (NSUInteger i = 0; i < [[triggerActionTimePopUpButton itemArray] count]; i++) - { - if ([[[triggerActionTimePopUpButton itemTitleAtIndex:i] uppercaseString] isEqualToString:[[trigger objectForKey:SPTriggerActionTime] uppercaseString]]) { - [triggerActionTimePopUpButton selectItemAtIndex:i]; - break; - } - } + [triggerActionTimePopUpButton selectItemWithTag:TagForActionTime([trigger objectForKey:SPTriggerActionTime])]; - // Event title is different then what we have saved in the database (case difference) - for (NSUInteger i = 0; i < [[triggerEventPopUpButton itemArray] count]; i++) - { - if ([[[triggerEventPopUpButton itemTitleAtIndex:i] uppercaseString] isEqualToString:[[trigger objectForKey:SPTriggerEvent] uppercaseString]]) { - [triggerEventPopUpButton selectItemAtIndex:i]; - break; - } - } + [triggerEventPopUpButton selectItemWithTag:TagForEvent([trigger objectForKey:SPTriggerEvent])]; // Change button label from Add to Edit [confirmAddTriggerButton setTitle:NSLocalizedString(@"Save", @"Save trigger button label")]; @@ -642,3 +653,24 @@ static const NSString *SPTriggerSQLMode = @"TriggerSQLMode"; } @end + +#pragma mark - + +SPTriggerActionTimeTag TagForActionTime(NSString *mysql) +{ + NSString *uc = [mysql uppercaseString]; + if([uc isEqualToString:@"BEFORE"]) return SPTriggerActionTimeBeforeTag; + if([uc isEqualToString:@"AFTER"]) return SPTriggerActionTimeAfterTag; + SPLog(@"Unknown trigger action time: %@",uc); + return -1; +} + +SPTriggerEventTag TagForEvent(NSString *mysql) +{ + NSString *uc = [mysql uppercaseString]; + if([uc isEqualToString:@"INSERT"]) return SPTriggerEventInsertTag; + if([uc isEqualToString:@"UPDATE"]) return SPTriggerEventUpdateTag; + if([uc isEqualToString:@"DELETE"]) return SPTriggerEventDeleteTag; + SPLog(@"Unknown trigger event: %@",uc); + return -1; +} |