diff options
-rw-r--r-- | Source/SPTableData.m | 55 | ||||
-rw-r--r-- | Source/SPTableInfo.m | 154 |
2 files changed, 143 insertions, 66 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m index efb97540..0301fd41 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -728,7 +728,6 @@ // When views are selected, populate the table with a default dictionary - all values, including comment, return no // meaningful information for views so we may as well skip the query. if ([tableListInstance tableType] == SP_TABLETYPE_VIEW) { - [status setDictionary:[NSDictionary dictionaryWithObjectsAndKeys:@"View", @"Engine", @"No status information is available for views.", @"Comment", [tableListInstance tableName], @"Name", nil]]; return TRUE; } @@ -736,14 +735,29 @@ // Run the status query and retrieve as a dictionary. NSMutableString *escapedTableName = [NSMutableString stringWithString:[tableListInstance tableName]]; [escapedTableName replaceOccurrencesOfString:@"'" withString:@"\\\'" options:0 range:NSMakeRange(0, [escapedTableName length])]; - MCPResult *tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS LIKE '%@'", escapedTableName ]]; + + MCPResult *tableStatusResult; + + if ([tableListInstance tableType] == SP_TABLETYPE_PROC) { + NSMutableString *escapedDatabaseName = [NSMutableString stringWithString:[tableDocumentInstance database]]; + [escapedDatabaseName replaceOccurrencesOfString:@"'" withString:@"\\\'" options:0 range:NSMakeRange(0, [escapedDatabaseName length])]; + tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT * FROM information_schema.ROUTINES AS r WHERE r.SPECIFIC_NAME = '%@' AND r.ROUTINE_SCHEMA = '%@' AND r.ROUTINE_TYPE = 'PROCEDURE'", escapedTableName, escapedDatabaseName]]; + } + else if ([tableListInstance tableType] == SP_TABLETYPE_FUNC) { + NSMutableString *escapedDatabaseName = [NSMutableString stringWithString:[tableDocumentInstance database]]; + [escapedDatabaseName replaceOccurrencesOfString:@"'" withString:@"\\\'" options:0 range:NSMakeRange(0, [escapedDatabaseName length])]; + tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT * FROM information_schema.ROUTINES AS r WHERE r.SPECIFIC_NAME = '%@' AND r.ROUTINE_SCHEMA = '%@' AND r.ROUTINE_TYPE = 'FUNCTION'", escapedTableName, escapedDatabaseName]]; + } + else if ([tableListInstance tableType] == SP_TABLETYPE_TABLE) { + tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW TABLE STATUS LIKE '%@'", escapedTableName ]]; + } // Check for any errors, only displaying them if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving table status.\nMySQL said: %@", @"message of panel when retrieving view information failed"), + [NSString stringWithFormat:NSLocalizedString(@"An error occured while retrieving status data.\nMySQL said: %@", @"message of panel when retrieving view information failed"), [mySQLConnection getLastErrorMessage]]); } return FALSE; @@ -752,25 +766,28 @@ // Retrieve the status as a dictionary and set as the cache [status setDictionary:[tableStatusResult fetchRowAsDictionary]]; - // Reassign any "Type" key - for MySQL < 4.1 - to "Engine" for consistency. - if ([status objectForKey:@"Type"]) { - [status setObject:[status objectForKey:@"Type"] forKey:@"Engine"]; - } + if ([tableListInstance tableType] == SP_TABLETYPE_TABLE) { - // 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"]; - } else { - [status setObject:@"n" forKey:@"RowsCountAccurate"]; - } + // Reassign any "Type" key - for MySQL < 4.1 - to "Engine" for consistency. + if ([status objectForKey:@"Type"]) { + [status setObject:[status objectForKey:@"Type"] forKey:@"Engine"]; + } - // [status objectForKey:@"Rows"] is NULL then try to get the number of rows via SELECT COUNT(*) FROM `foo` - // this happens e.g. for db "information_schema" - if([[status objectForKey:@"Rows"] isKindOfClass:[NSNull class]]) { - tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(*) FROM %@", [escapedTableName backtickQuotedString] ]]; - if ([[mySQLConnection getLastErrorMessage] isEqualToString:@""]) - [status setObject:[[tableStatusResult fetchRowAsArray] objectAtIndex:0] forKey:@"Rows"]; + // 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"]; + } else { + [status setObject:@"n" forKey:@"RowsCountAccurate"]; + } + + // [status objectForKey:@"Rows"] is NULL then try to get the number of rows via SELECT COUNT(*) FROM `foo` + // this happens e.g. for db "information_schema" + if([[status objectForKey:@"Rows"] isKindOfClass:[NSNull class]]) { + tableStatusResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(*) FROM %@", [escapedTableName backtickQuotedString] ]]; + if ([[mySQLConnection getLastErrorMessage] isEqualToString:@""]) + [status setObject:[[tableStatusResult fetchRowAsArray] objectAtIndex:0] forKey:@"Rows"]; + [status setObject:@"y" forKey:@"RowsCountAccurate"]; + } } return TRUE; diff --git a/Source/SPTableInfo.m b/Source/SPTableInfo.m index 800a87dd..4f5e3d0a 100644 --- a/Source/SPTableInfo.m +++ b/Source/SPTableInfo.m @@ -84,67 +84,127 @@ return; } - if ([tableListInstance tableType] == SP_TABLETYPE_PROC) { - [info addObject:@"PROCEDURE INFORMATION"]; - [info addObject:@"no information available"]; + if ([[tableListInstance tableName] isEqualToString:@""]) { + [info addObject:@"INFORMATION"]; + [info addObject:@"multiple selection"]; [infoTable reloadData]; return; - } + } - if ([tableListInstance tableType] == SP_TABLETYPE_FUNC) { - [info addObject:@"FUNCTION INFORMATION"]; - [info addObject:@"no information available"]; - [infoTable reloadData]; - return; + // Get TABLE information + if ([tableListInstance tableType] == SP_TABLETYPE_TABLE) { + + [info addObject:@"TABLE INFORMATION"]; + + if ([tableListInstance tableName]) { + if ([[tableListInstance tableName] isEqualToString:@""]) { + [info addObject:@"multiple tables"]; + } + else { + // Retrieve the table status information via the data cache + tableStatus = [tableDataInstance statusValues]; + + // Check for errors + if (![tableStatus count]) { + [info addObject:@"error occurred"]; + return; + } + + // Check for 'Create_time' == NULL + if (![[tableStatus objectForKey:@"Create_time"] isNSNull]) { + + // Add the creation date to the infoTable + [info addObject:[NSString stringWithFormat:@"created: %@", [self _getUserDefinedDateStringFromMySQLDate:[tableStatus objectForKey:@"Create_time"]]]]; + } + + // Check for 'Update_time' == NULL - InnoDB tables don't have an update time + if (![[tableStatus objectForKey:@"Update_time"] isNSNull]) { + + // Add the update date to the infoTable + [info addObject:[NSString stringWithFormat:@"updated: %@", [self _getUserDefinedDateStringFromMySQLDate:[tableStatus objectForKey:@"Update_time"]]]]; + } + + // Check for 'Rows' == NULL - information_schema database doesn't report row count for it's tables + if (![[tableStatus objectForKey:@"Rows"] isNSNull]) { + [info addObject:[NSString stringWithFormat:[[tableStatus objectForKey:@"RowsCountAccurate"] boolValue] ? @"rows: %@" : @"rows: ~%@", + [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:[[tableStatus objectForKey:@"Rows"] longLongValue]]]]]; + } + + [info addObject:[NSString stringWithFormat:@"size: %@", [NSString stringForByteSize:[[tableStatus objectForKey:@"Data_length"] longLongValue]]]]; + [info addObject:[NSString stringWithFormat:@"encoding: %@", [tableDataInstance tableEncoding]]]; + + if (![[tableStatus objectForKey:@"Auto_increment"] isNSNull]) { + [info addObject:[NSString stringWithFormat:@"auto_increment: %@", + [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:[[tableStatus objectForKey:@"Auto_increment"] longLongValue]]]]]; + } + } + } } - [info addObject:@"TABLE INFORMATION"]; - - if ([tableListInstance tableName]) { - if ([[tableListInstance tableName] isEqualToString:@""]) { - [info addObject:@"multiple tables"]; - } - else { - // Retrieve the table status information via the data cache - tableStatus = [tableDataInstance statusValues]; - - // Check for errors - if (![tableStatus count]) { - [info addObject:@"error occurred"]; - return; - } + // Get PROC/FUNC information + else if ([tableListInstance tableType] == SP_TABLETYPE_PROC || [tableListInstance tableType] == SP_TABLETYPE_FUNC) { + + if ([tableListInstance tableType] == SP_TABLETYPE_PROC) + [info addObject:@"PROCEDURE INFORMATION"]; + else + [info addObject:@"FUNCTION INFORMATION"]; + + if ([tableListInstance tableName]) { + if ([[tableListInstance tableName] isEqualToString:@""]) { + [info addObject:@"multiple tables"]; + } else { + // Retrieve the table status information via the data cache + tableStatus = [tableDataInstance statusValues]; - // Check for 'Create_time' == NULL - if (![[tableStatus objectForKey:@"Create_time"] isNSNull]) { + // Check for errors + if (![tableStatus count]) { + [info addObject:@"error occurred"]; + return; + } // Add the creation date to the infoTable - [info addObject:[NSString stringWithFormat:@"created: %@", [self _getUserDefinedDateStringFromMySQLDate:[tableStatus objectForKey:@"Create_time"]]]]; - } + // Check for 'CREATED' == NULL + if (![[tableStatus objectForKey:@"CREATED"] isNSNull]) { + + // Add the creation date to the infoTable + [info addObject:[NSString stringWithFormat:@"created: %@", [self _getUserDefinedDateStringFromMySQLDate:[tableStatus objectForKey:@"CREATED"]]]]; + } - // Check for 'Update_time' == NULL - InnoDB tables don't have an update time - if (![[tableStatus objectForKey:@"Update_time"] isNSNull]) { + // Check for 'LAST_ALTERED' + if (![[tableStatus objectForKey:@"LAST_ALTERED"] isNSNull]) { - // Add the update date to the infoTable - [info addObject:[NSString stringWithFormat:@"updated: %@", [self _getUserDefinedDateStringFromMySQLDate:[tableStatus objectForKey:@"Update_time"]]]]; - } - - // Check for 'Rows' == NULL - information_schema database doesn't report row count for it's tables - if (![[tableStatus objectForKey:@"Rows"] isNSNull]) { - [info addObject:[NSString stringWithFormat:[[tableStatus objectForKey:@"RowsCountAccurate"] boolValue] ? @"rows: %@" : @"rows: ~%@", - [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:[[tableStatus objectForKey:@"Rows"] longLongValue]]]]]; - } - - [info addObject:[NSString stringWithFormat:@"size: %@", [NSString stringForByteSize:[[tableStatus objectForKey:@"Data_length"] longLongValue]]]]; - [info addObject:[NSString stringWithFormat:@"encoding: %@", [tableDataInstance tableEncoding]]]; - - if (![[tableStatus objectForKey:@"Auto_increment"] isNSNull]) { - [info addObject:[NSString stringWithFormat:@"auto_increment: %@", - [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:[[tableStatus objectForKey:@"Auto_increment"] longLongValue]]]]]; + // Add the update date to the infoTable + [info addObject:[NSString stringWithFormat:@"updated: %@", [self _getUserDefinedDateStringFromMySQLDate:[tableStatus objectForKey:@"LAST_ALTERED"]]]]; + } + + // Check for 'SQL ACCESS' and deterministic + if (![[tableStatus objectForKey:@"SQL_DATA_ACCESS"] isNSNull] && ![[tableStatus objectForKey:@"IS_DETERMINISTIC"] isNSNull]) { + [info addObject:[NSString stringWithFormat:@"data access: %@ (%@)", [tableStatus objectForKey:@"SQL_DATA_ACCESS"], ([[tableStatus objectForKey:@"IS_DETERMINISTIC"] isEqualToString:@"YES"]) ? @"deterministic" : @"non-deterministic"]]; + } + + if ([tableListInstance tableType] == SP_TABLETYPE_FUNC) { + // Check for 'DTD_IDENTIFIER' + if (![[tableStatus objectForKey:@"DTD_IDENTIFIER"] isNSNull]) { + [info addObject:[NSString stringWithFormat:@"return type: %@", [tableStatus objectForKey:@"DTD_IDENTIFIER"]]]; + } + } + + // Check for 'SECURITY_TYPE' + if (![[tableStatus objectForKey:@"SECURITY_TYPE"] isNSNull]) { + [info addObject:[NSString stringWithFormat:@"execution privilege: %@", [tableStatus objectForKey:@"SECURITY_TYPE"]]]; + } + + // Check for 'DEFINER' + if (![[tableStatus objectForKey:@"DEFINER"] isNSNull]) { + [info addObject:[NSString stringWithFormat:@"definer: %@", [tableStatus objectForKey:@"DEFINER"]]]; + } + } } } - + [infoTable reloadData]; + } #pragma mark - |