diff options
author | rowanbeentje <rowan@beent.je> | 2010-05-01 01:36:52 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2010-05-01 01:36:52 +0000 |
commit | 8acde6bf2580ce1e2feac2b9ac74dfa34b1ddf7e (patch) | |
tree | 4c2411b8f04d038d03013cae244d54566761ec96 /Source/SPTableTriggers.m | |
parent | 9175848b8bbe6e4b9145a492d9b4da86adb8760d (diff) | |
download | sequelpro-8acde6bf2580ce1e2feac2b9ac74dfa34b1ddf7e.tar.gz sequelpro-8acde6bf2580ce1e2feac2b9ac74dfa34b1ddf7e.tar.bz2 sequelpro-8acde6bf2580ce1e2feac2b9ac74dfa34b1ddf7e.zip |
Review trigger fetching and storage:
- Trigger queries are no longer made for MySQL < 5.0.2
- Trigger loading has been deferred until the trigger tab is active, reducing queries when switching tables and thus increasing overall responsiveness
- Export triggers in MySQL dumps even if the Table Content switch is unchecked
Diffstat (limited to 'Source/SPTableTriggers.m')
-rw-r--r-- | Source/SPTableTriggers.m | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/Source/SPTableTriggers.m b/Source/SPTableTriggers.m index dde516a8..c202e9c9 100644 --- a/Source/SPTableTriggers.m +++ b/Source/SPTableTriggers.m @@ -77,12 +77,7 @@ selector:@selector(triggerStatementTextDidChange:) name:NSTextStorageDidProcessEditingNotification object:[triggerStatementTextView textStorage]]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(tableSelectionChanged:) - name:SPTableChangedNotification - object:tableDocumentInstance]; - + // Add observers for document task activity [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startDocumentTaskForTab:) @@ -94,6 +89,46 @@ object:tableDocumentInstance]; } +/** + * Called whenever the user selects the triggers tab for the first time, + * or switches between tables with the triggers tab active. + */ +- (void)loadTriggers +{ + BOOL enableInteraction = ((![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableTriggers]) || (![tableDocumentInstance isWorking])); + + // Disable all interface elements by default + [addTriggerButton setEnabled:NO]; + [refreshTriggersButton setEnabled:NO]; + [triggersTableView setEnabled:NO]; + [labelTextField setStringValue:@""]; + + // Show a warning if the version of MySQL is too low to support triggers + if ([connection serverMajorVersion] < 5 + || ([connection serverMajorVersion] == 5 + && [connection serverMinorVersion] == 0 + && [connection serverReleaseVersion] < 2)) + { + [labelTextField setStringValue:NSLocalizedString(@"This version of MySQL does not support triggers. Support for triggers was added in MySQL 5.0.2", @"triggers not supported label")]; + return; + } + + // If no item is selected, or the item selected is not a table, return. + if (![tablesListInstance tableName] || [tablesListInstance tableType] != SPTableTypeTable) + return; + + // Update the text label + [labelTextField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Triggers for table: %@", @"triggers for table label"), [tablesListInstance tableName]]]; + + // Enable interface elements + [addTriggerButton setEnabled:enableInteraction]; + [refreshTriggersButton setEnabled:enableInteraction]; + [triggersTableView setEnabled:YES]; + + // Ensure trigger data is loaded + [self _refreshTriggerDataForcingCacheRefresh:NO]; +} + #pragma mark - #pragma mark IB action methods @@ -185,49 +220,6 @@ [self _refreshTriggerDataForcingCacheRefresh:YES]; } -/** - * Called whenever the user selects a different table. - */ -- (void)tableSelectionChanged:(NSNotification *)notification -{ - BOOL enableInteraction = ((![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableTriggers]) || (![tableDocumentInstance isWorking])); - - // To begin enable all interface elements - [addTriggerButton setEnabled:enableInteraction]; - [refreshTriggersButton setEnabled:enableInteraction]; - [triggersTableView setEnabled:YES]; - - if (([connection serverMajorVersion] >= 5) && - ([connection serverMinorVersion] >= 0) && - ([connection serverReleaseVersion] >= 2)) { - - // Update the text label - [labelTextField setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Triggers for table: %@", @"triggers for table label"), [tablesListInstance tableName]]]; - - [addTriggerButton setEnabled:enableInteraction]; - [refreshTriggersButton setEnabled:enableInteraction]; - [triggersTableView setEnabled:YES]; - - [self _refreshTriggerDataForcingCacheRefresh:NO]; - } - else { - [addTriggerButton setEnabled:NO]; - [refreshTriggersButton setEnabled:NO]; - [triggersTableView setEnabled:NO]; - - [labelTextField setStringValue:NSLocalizedString(@"This version of MySQL does not support triggers. Support for triggers was added in MySQL 5.0.2", @"triggers not supported label")]; - } - - // If a proc or function is selected disable everything. - if (([tablesListInstance tableType] == SPTableTypeProc) || ([tablesListInstance tableType] == SPTableTypeFunc)) { - [addTriggerButton setEnabled:NO]; - [refreshTriggersButton setEnabled:NO]; - [triggersTableView setEnabled:NO]; - - [labelTextField setStringValue:@""]; - } -} - #pragma mark - #pragma mark Tableview datasource methods @@ -479,7 +471,10 @@ if ([tablesListInstance tableType] == SPTableTypeTable) { - if (clearAllCaches) [tableDataInstance updateInformationForCurrentTable]; + if (clearAllCaches) { + [tableDataInstance resetAllData]; + [tableDataInstance updateTriggersForCurrentTable]; + } NSArray *triggers = [tableDataInstance triggers]; |