From 7869b1fb325a9f761dc896b2be5b84be8b4d8f74 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sat, 28 Mar 2009 02:33:59 +0000 Subject: - The status tab now no longer crashes when viewing Views. (Resolves Issue #212) - SQL dump now correctly exports the CREATE ALGORITHM statement for views, and no longer attempts to output data for views. Databases with views can now be exported/imported without errors. --- Source/TableDump.m | 47 +++++++++++++++++++++++++++++------------------ Source/TableStatus.m | 21 ++++++++++++++------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/Source/TableDump.m b/Source/TableDump.m index c1532b23..d3e7ffef 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -753,7 +753,7 @@ */ - (BOOL)dumpSelectedTablesAsSqlToFileHandle:(NSFileHandle *)fileHandle { - int i,j,t,rowCount, colCount, progressBarWidth, lastProgressValue, queryLength; + int i,j,t,rowCount, colCount, progressBarWidth, lastProgressValue, queryLength, tableType; CMMCPResult *queryResult; NSString *tableName, *tableColumnTypeGrouping; NSArray *fieldNames; @@ -766,7 +766,7 @@ NSDictionary *tableDetails; NSMutableArray *tableColumnNumericStatus; NSStringEncoding connectionEncoding = [mySQLConnection encoding]; - id createTableSyntax; + id createTableSyntax = nil; // Reset the interface [errorsView setString:@""]; @@ -823,27 +823,38 @@ [fileHandle writeData:[[NSString stringWithFormat:@"DROP TABLE IF EXISTS %@;\n\n", [tableName backtickQuotedString]] dataUsingEncoding:connectionEncoding]]; - // Add the create syntax for the table if specified in the export dialog - if ( [addCreateTableSwitch state] == NSOnState ) { - queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE %@", [tableName backtickQuotedString]]]; - if ( [queryResult numOfRows] ) { - createTableSyntax = [[queryResult fetchRowAsDictionary] objectForKey:@"Create Table"]; - if ( [createTableSyntax isKindOfClass:[NSData class]] ) { - createTableSyntax = [[[NSString alloc] initWithData:createTableSyntax encoding:connectionEncoding] autorelease]; - } - [fileHandle writeData:[createTableSyntax dataUsingEncoding:connectionEncoding]]; - [fileHandle writeData:[[NSString stringWithString:@";\n\n"] dataUsingEncoding:connectionEncoding]]; + + // Determine whether this table is a table or a view via the create table command, and keep the create table syntax + queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE %@", [tableName backtickQuotedString]]]; + if ( [queryResult numOfRows] ) { + tableDetails = [[NSDictionary alloc] initWithDictionary:[queryResult fetchRowAsDictionary]]; + if ([tableDetails objectForKey:@"Create View"]) { + createTableSyntax = [[[tableDetails objectForKey:@"Create View"] copy] autorelease]; + tableType = SP_TABLETYPE_VIEW; + } else { + createTableSyntax = [[[tableDetails objectForKey:@"Create Table"] copy] autorelease]; + tableType = SP_TABLETYPE_TABLE; } - if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - [errors appendString:[NSString stringWithFormat:@"%@\n", [mySQLConnection getLastErrorMessage]]]; - if ( [addErrorsSwitch state] == NSOnState ) { - [fileHandle writeData:[[NSString stringWithFormat:@"# Error: %@\n", [mySQLConnection getLastErrorMessage]] dataUsingEncoding:connectionEncoding]]; - } + [tableDetails release]; + } + if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { + [errors appendString:[NSString stringWithFormat:@"%@\n", [mySQLConnection getLastErrorMessage]]]; + if ( [addErrorsSwitch state] == NSOnState ) { + [fileHandle writeData:[[NSString stringWithFormat:@"# Error: %@\n", [mySQLConnection getLastErrorMessage]] dataUsingEncoding:connectionEncoding]]; + } + } + + // Add the create syntax for the table if specified in the export dialog + if ( [addCreateTableSwitch state] == NSOnState && createTableSyntax) { + if ( [createTableSyntax isKindOfClass:[NSData class]] ) { + createTableSyntax = [[[NSString alloc] initWithData:createTableSyntax encoding:connectionEncoding] autorelease]; } + [fileHandle writeData:[createTableSyntax dataUsingEncoding:connectionEncoding]]; + [fileHandle writeData:[[NSString stringWithString:@";\n\n"] dataUsingEncoding:connectionEncoding]]; } // Add the table content if required - if ( [addTableContentSwitch state] == NSOnState ) { + if ( [addTableContentSwitch state] == NSOnState && tableType == SP_TABLETYPE_TABLE ) { queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT * FROM %@", [tableName backtickQuotedString]]]; fieldNames = [queryResult fetchFieldNames]; rowCount = [queryResult numOfRows]; diff --git a/Source/TableStatus.m b/Source/TableStatus.m index 4edaa4e0..36aa2043 100644 --- a/Source/TableStatus.m +++ b/Source/TableStatus.m @@ -64,11 +64,21 @@ { // Store the table name away for future use... selectedTable = aTable; + + // Retrieve the table status information via the table data cache + statusFields = [tableDataInstance statusValues]; - // No table selected - if([aTable isEqualToString:@""] || !aTable) { - [tableName setStringValue:@"Name: --"]; - [tableType setStringValue:@"Type: --"]; + // No table selected or view selected + if([aTable isEqualToString:@""] || !aTable || [[statusFields objectForKey:@"Engine"] isEqualToString:@"View"]) { + + if ([[statusFields objectForKey:@"Engine"] isEqualToString:@"View"]) { + [tableName setStringValue:[NSString stringWithFormat:@"Name: %@", selectedTable]]; + [tableType setStringValue:@"Type: View"]; + } else { + [tableName setStringValue:@"Name: --"]; + [tableType setStringValue:@"Type: --"]; + } + [tableCreatedAt setStringValue:@"Created At: --"]; [tableUpdatedAt setStringValue:@"Updated At: --"]; @@ -90,9 +100,6 @@ return; } - // Retrieve the table status information via the table data cache - statusFields = [tableDataInstance statusValues]; - // Assign the table values... [tableName setStringValue:[NSString stringWithFormat:@"Name: %@",selectedTable]]; [tableType setStringValue:[self formatValueWithKey:@"Engine" inDictionary:statusFields withLabel:@"Type"]]; -- cgit v1.2.3