diff options
author | stuconnolly <stuart02@gmail.com> | 2009-11-20 01:12:14 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-11-20 01:12:14 +0000 |
commit | dcaa35d218ad66e61eeba0bac5a767f9a206f0b3 (patch) | |
tree | f991b2791b34e0a806c0504ca03ac105dfc5142c /Source/SPTableData.m | |
parent | f5bbd06bdfb991fec371e9e56f8a52cb6b2b2ae4 (diff) | |
download | sequelpro-dcaa35d218ad66e61eeba0bac5a767f9a206f0b3.tar.gz sequelpro-dcaa35d218ad66e61eeba0bac5a767f9a206f0b3.tar.bz2 sequelpro-dcaa35d218ad66e61eeba0bac5a767f9a206f0b3.zip |
Delay the releasing of the createTableSyntax variable in SPTableData until we are about the replace it to prevent threading issues. Also, in fieldListForQuery check that dataColumns array is not empty before constructing the field list as well as only obtaining the table's columns if the field list is going to be built in the first place.
Diffstat (limited to 'Source/SPTableData.m')
-rw-r--r-- | Source/SPTableData.m | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m index c1fd0497..6f7c6702 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -120,7 +120,7 @@ * Retrieve a column with a specified name, using or refreshing the cache as appropriate. */ - (NSDictionary *) columnWithName:(NSString *)colName -{ +{ if ([columns count] == 0) { if ([tableListInstance tableType] == SP_TABLETYPE_VIEW) { [self updateInformationForCurrentView]; @@ -138,7 +138,7 @@ * Retrieve column names for the current table as an array, using or refreshing the cache as appropriate. */ - (NSArray *) columnNames -{ +{ if ([columnNames count] == 0) { if ([tableListInstance tableType] == SP_TABLETYPE_VIEW) { [self updateInformationForCurrentView]; @@ -154,7 +154,7 @@ * Retrieve a specified column for the current table as a dictionary, using or refreshing the cache as appropriate. */ - (NSDictionary *) columnAtIndex:(int)index -{ +{ if ([columns count] == 0) { if ([tableListInstance tableType] == SP_TABLETYPE_VIEW) { [self updateInformationForCurrentView]; @@ -171,7 +171,7 @@ */ - (BOOL) columnIsBlobOrText:(NSString *)colName -{ +{ if ([columns count] == 0) { if ([tableListInstance tableType] == SP_TABLETYPE_VIEW) { [self updateInformationForCurrentView]; @@ -266,7 +266,7 @@ NSDictionary *tableData = nil; NSDictionary *columnData; NSEnumerator *enumerator; - + if( [tableListInstance tableType] == SP_TABLETYPE_TABLE || [tableListInstance tableType] == SP_TABLETYPE_VIEW ) { tableData = [self informationForTable:[tableListInstance tableName]]; } @@ -303,7 +303,7 @@ * Returns a boolean indicating success. */ - (NSDictionary *) informationForTable:(NSString *)tableName -{ +{ SPSQLParser *createTableParser, *fieldsParser, *fieldParser; NSMutableArray *tableColumns, *fieldStrings, *definitionParts; NSMutableDictionary *tableColumn, *tableData; @@ -315,24 +315,21 @@ [columnNames removeAllObjects]; [constraints removeAllObjects]; - if (tableCreateSyntax != nil) [tableCreateSyntax release]; - // Catch unselected tables and return nil if ([tableName isEqualToString:@""] || !tableName) return nil; // Retrieve the CREATE TABLE syntax for the table - MCPResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@", - [tableName backtickQuotedString] - ]]; - + MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE %@", [tableName backtickQuotedString]]]; + // Check for any errors, but only display them if a connection still exists if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), + NSBeginAlertSheet(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 occured while retrieving table information.\nMySQL said: %@", @"message of panel when retrieving table information failed"), - [mySQLConnection getLastErrorMessage]]); + [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; } @@ -340,6 +337,8 @@ NSArray *syntaxResult = [theResult fetchRowAsArray]; NSArray *resultFieldNames = [theResult fetchFieldNames]; + if (tableCreateSyntax != nil) [tableCreateSyntax release]; + if ([[syntaxResult objectAtIndex:1] isKindOfClass:[NSData class]]) { tableCreateSyntax = [[NSString alloc] initWithData:[syntaxResult objectAtIndex:1] encoding:[mySQLConnection encoding]]; createTableParser = [[SPSQLParser alloc] initWithData:[syntaxResult objectAtIndex:1] encoding:[mySQLConnection encoding]]; |