From 223dd9139ae61d9319ea5f719a1a08feb63bfeb4 Mon Sep 17 00:00:00 2001 From: bamse16 Date: Sun, 31 Jan 2010 18:56:25 +0000 Subject: Added preliminary support for triggers. You can access the tab via the menu item View > Table Triggers (apple-6). Heavily copied from Relations tab, lots of functionality missing. Just lists the triggers for the table now. M Source/SPTableData.m M Source/SPConstants.h M Source/SPConstants.m A Source/SPTableTriggers.h A Source/SPTableTriggers.m M Source/TableDocument.h M Source/TableDocument.m M Source/SPTableData.h M Interfaces/English.lproj/MainMenu.xib M Interfaces/English.lproj/DBView.xib M sequel-pro.xcodeproj/project.pbxproj --- Source/SPTableData.m | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'Source/SPTableData.m') diff --git a/Source/SPTableData.m b/Source/SPTableData.m index a0a4d860..1c00758a 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -44,6 +44,7 @@ columnNames = [[NSMutableArray alloc] init]; constraints = [[NSMutableArray alloc] init]; status = [[NSMutableDictionary alloc] init]; + triggers = [[NSMutableArray alloc] init]; tableEncoding = nil; tableCreateSyntax = nil; @@ -117,6 +118,11 @@ return constraints; } +- (NSArray *) triggers +{ + return (NSArray *)triggers; +} + /* * Retrieve a column with a specified name, using or refreshing the cache as appropriate. */ @@ -558,6 +564,31 @@ [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 getLastErrorMessage] isEqualToString:@""]) { + 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]]); + } + + return nil; + } + + [triggers removeAllObjects]; + if( [theResult numOfRows] ) { + for(int i=0; i<[theResult numOfRows]; i++){ + [triggers addObject:[theResult fetchRowAsDictionary]]; + } + } + tableData = [NSMutableDictionary dictionary]; // this will be 'Table' or 'View' @@ -565,6 +596,7 @@ [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]; @@ -1030,6 +1062,7 @@ [columns release]; [columnNames release]; [constraints release]; + [triggers release]; [status release]; if (tableEncoding) [tableEncoding release]; -- cgit v1.2.3