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/SPTableData.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/SPTableData.m')
-rw-r--r-- | Source/SPTableData.m | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m index 51d490d9..ab1857f6 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -42,8 +42,8 @@ columnNames = [[NSMutableArray alloc] init]; constraints = [[NSMutableArray alloc] init]; status = [[NSMutableDictionary alloc] init]; - triggers = [[NSMutableArray alloc] init]; - + + triggers = nil; tableEncoding = nil; tableCreateSyntax = nil; mySQLConnection = nil; @@ -121,6 +121,19 @@ - (NSArray *) triggers { + + // If triggers is nil, the triggers need to be loaded - if a table is selected on MySQL >= 5.0.2 + if (!triggers) { + if ([tableListInstance tableType] == SPTableTypeTable + && [mySQLConnection serverMajorVersion] >= 5 + && [mySQLConnection serverMinorVersion] >= 0) + { + [self updateTriggersForCurrentTable]; + } else { + return [NSArray array]; + } + } + return (NSArray *)triggers; } @@ -234,6 +247,11 @@ [columnNames removeAllObjects]; [status removeAllObjects]; + if (triggers != nil) { + [triggers release]; + triggers = nil; + } + if (tableEncoding != nil) { [tableEncoding release]; tableEncoding = nil; @@ -608,39 +626,12 @@ [createTableParser release]; [fieldParser release]; - // Triggers - theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"/*!50003 SHOW TRIGGERS WHERE `Table` = %@ */", - [tableName tickQuotedString]]]; - [theResult setReturnDataAsStrings:YES]; - - // Check for any errors, but only display them if a connection still exists - if ([mySQLConnection queryErrored]) { - if ([mySQLConnection isConnected]) { - SPBeginAlertSheet(NSLocalizedString(@"Error retrieving table information", @"error retrieving table information message"), NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving the information for table '%@'. Please try again.\n\nMySQL said: %@", @"error retrieving table information informative message"), - tableName, [mySQLConnection getLastErrorMessage]]); - } - [tableColumns release]; - if (encodingString) [encodingString release]; - - return nil; - } - - [triggers removeAllObjects]; - if( [theResult numOfRows] ) { - for(i=0; i<[theResult numOfRows]; i++){ - [triggers addObject:[theResult fetchRowAsDictionary]]; - } - } - // this will be 'Table' or 'View' [tableData setObject:[resultFieldNames objectAtIndex:0] forKey:@"type"]; [tableData setObject:[NSString stringWithString:encodingString] forKey:@"encoding"]; [tableData setObject:[NSArray arrayWithArray:tableColumns] forKey:@"columns"]; [tableData setObject:[NSArray arrayWithArray:constraints] forKey:@"constraints"]; - [tableData setObject:[NSArray arrayWithArray:triggers] forKey:@"triggers"]; [encodingString release]; [tableColumns release]; @@ -878,6 +869,36 @@ return TRUE; } +/** + * Retrieve the triggers for the current table and add to local cache for reuse. + */ +- (BOOL) updateTriggersForCurrentTable +{ + MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"/*!50003 SHOW TRIGGERS WHERE `Table` = %@ */", + [[tableListInstance tableName] tickQuotedString]]]; + [theResult setReturnDataAsStrings:YES]; + + // Check for any errors, but only display them if a connection still exists + if ([mySQLConnection queryErrored]) { + if ([mySQLConnection isConnected]) { + SPBeginAlertSheet(NSLocalizedString(@"Error retrieving trigger information", @"error retrieving trigger information message"), NSLocalizedString(@"OK", @"OK button"), + nil, nil, [NSApp mainWindow], self, nil, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving the trigger information for table '%@'. Please try again.\n\nMySQL said: %@", @"error retrieving table information informative message"), + [tableListInstance tableName], [mySQLConnection getLastErrorMessage]]); + if (triggers) [triggers release], triggers = nil; + } + + return NO; + } + + if (triggers) [triggers release]; + triggers = [[NSMutableArray alloc] init]; + for (int i=0; i<[theResult numOfRows]; i++) { + [triggers addObject:[theResult fetchRowAsDictionary]]; + } + + return YES; +} /* * Parse an array of field definition parts - not including name but including type and optionally unsigned/zerofill/null @@ -1122,9 +1143,9 @@ [columns release]; [columnNames release]; [constraints release]; - [triggers release]; [status release]; + if (triggers) [triggers release]; if (tableEncoding) [tableEncoding release]; if (tableCreateSyntax) [tableCreateSyntax release]; if (mySQLConnection) [mySQLConnection release]; |