diff options
author | rowanbeentje <rowan@beent.je> | 2010-08-01 19:32:27 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2010-08-01 19:32:27 +0000 |
commit | 43a9629aecaf21c37348c81a88f249fc8afe04dd (patch) | |
tree | 745d60716a9e748dfdaa436ea51c72fcb0851f26 /Source/SPTableData.m | |
parent | c2f2a6d1d126e8cb658b745bf5a534ca7307476d (diff) | |
download | sequelpro-43a9629aecaf21c37348c81a88f249fc8afe04dd.tar.gz sequelpro-43a9629aecaf21c37348c81a88f249fc8afe04dd.tar.bz2 sequelpro-43a9629aecaf21c37348c81a88f249fc8afe04dd.zip |
Merge in a range of bugfixes from trunk:
r2201, r2470 (Table trigger improvements, and fixes for MySQL <3.23.5x)
r2211, r2214, r2232, r2245, r2247, r2265, r2266, r2267, r2280 (User manager fixes)
r2213 (Incorrect count display)
r2215, r2270, r2283, r2285, r2471 (Thread-safety fixes)
r2216 (Task progress indicator fixes)
r2217 (CSV import field mapping fix)
r2218, r2219 (Custom queries fixes)
r2222 (Fix issues when opening files)
r2223 (Fixes problems copying binary data as tab-delimited strings)
r2224 (Fixes 10.5 not appending correct extension on export)
r2225, r2324 (Fixes to background database structure querying, extend structure querying to MySQL 3 & 4)
r2227 (Fixes to table saving on right-clicking)
r2228 (Memory use fixes)
r2272, r2279, r2286, r2398, r2399, r2420 (Favourites sorting)
r2275 (Improved handling of corrupt tables, disabled storage engines etc)
r2278 (Custom query autocomplete tab snippets not working under 10.5)
r2297 (Fix structure editing errors)
r2307 (Make return key behaviour in structure view consistent with content view)
r2335 (Fix crashes when cancelling/stopping queries on MySQL 3 & 4)
r2345 (Import from clipboard improvements)
r2362 (Improve robustness when closing windows quickly)
r2384 (Respect "Reload after editing" preference when editing custom query results)
r2385 (Prevent custom query uppercasing of reserved keywords which are quoted)
r2396 (Improve reordering of TIMESTAMP fields)
r2411, r2444, r2446 (Improve Xcode 3.2.3 project compatibility)
r2438 (Fix exceptions printing extended table info)
r2441 (Fix resizing table information after initial collapsed state)
r2445 (Improve default socket search paths)
r2463 (Fix custom query capturing up/down arrow when autocomplete finds no matches)
r2479, r2482 (Replace Core Animation with custom code to fix hangs)
r2486 (Improve data storage exceptions)
Diffstat (limited to 'Source/SPTableData.m')
-rw-r--r-- | Source/SPTableData.m | 95 |
1 files changed, 61 insertions, 34 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m index 51d490d9..d9332e65 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; @@ -334,7 +352,7 @@ 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, + nil, nil, [NSApp mainWindow], self, 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]]); // If the current table doesn't exist anymore reload table list @@ -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]; @@ -711,7 +702,7 @@ if ([mySQLConnection queryErrored]) { if ([mySQLConnection isConnected]) { SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], self, nil, nil, nil, + nil, nil, [NSApp mainWindow], self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), [mySQLConnection getLastErrorMessage]]); } @@ -743,7 +734,7 @@ if ([mySQLConnection queryErrored]) { if ([mySQLConnection isConnected]) { SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], self, nil, nil, nil, + nil, nil, [NSApp mainWindow], self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), [mySQLConnection getLastErrorMessage]]); } @@ -841,7 +832,7 @@ if ([mySQLConnection queryErrored]) { if ([mySQLConnection isConnected]) { SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], self, nil, nil, nil, + nil, nil, [NSApp mainWindow], self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\nMySQL said: %@", @"message of panel when retrieving view information failed"), [mySQLConnection getLastErrorMessage]]); } @@ -858,6 +849,12 @@ [status setObject:[status objectForKey:@"Type"] forKey:@"Engine"]; } + // If the "Engine" key is NULL, a problem occurred when retrieving the table information. + if ([[status objectForKey:@"Engine"] isNSNull]) { + [status setDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"Error", @"Engine", [NSString stringWithFormat:@"An error occurred retrieving table information. MySQL said: %@", [status objectForKey:@"Comment"]], @"Comment", [tableListInstance tableName], @"Name", nil]]; + return FALSE; + } + // Add a note for whether the row count is accurate or not - only for MyISAM if ([[status objectForKey:@"Engine"] isEqualToString:@"MyISAM"]) { [status setObject:@"y" forKey:@"RowsCountAccurate"]; @@ -878,6 +875,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, + [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 +1149,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]; |