From 297086a539bc69bf389979e68e3d8dcfc64f56d4 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 28 May 2009 09:15:53 +0000 Subject: =?UTF-8?q?=E2=80=A2=20Table=20Info=20-=20show=20create=20syntax?= =?UTF-8?q?=20for=20views=20-=20fixed=20editing=20behaviour=20of=20the=20C?= =?UTF-8?q?omments=20field=20(esp.=20for=20views)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPExtendedTableInfo.m | 17 +++++++++++++---- Source/SPTableData.m | 25 ++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m index d2e39509..2b20fbab 100644 --- a/Source/SPExtendedTableInfo.m +++ b/Source/SPExtendedTableInfo.m @@ -187,6 +187,14 @@ if ([[statusFields objectForKey:@"Engine"] isEqualToString:@"View"]) { [tableTypePopUpButton addItemWithTitle:@"View"]; + // Set create syntax + [tableCreateSyntaxTextView setEditable:YES]; + [tableCreateSyntaxTextView setString:@""]; + [tableCreateSyntaxTextView insertText:[[tableDataInstance tableCreateSyntax] createViewSyntaxPrettifier]]; + [tableCreateSyntaxTextView setEditable:NO]; + } else { + [tableCreateSyntaxTextView setEditable:NO]; + [tableCreateSyntaxTextView setString:@""]; } [tableCreatedAt setStringValue:@"Created at: "]; @@ -206,9 +214,8 @@ // Set comments [tableCommentsTextView setString:@""]; + [tableCommentsTextView setEditable:NO]; - // Set create syntax - [tableCreateSyntaxTextView setString:@""]; return; } @@ -274,6 +281,7 @@ [tableSizeFree setStringValue:[self _formatValueWithKey:@"Data_free" inDictionary:statusFields withLabel:@"Free data size"]]; // Set comments + [tableCommentsTextView setEditable:YES]; [tableCommentsTextView setString:[statusFields objectForKey:@"Comment"]]; // Set create syntax @@ -288,11 +296,12 @@ */ - (void)textDidEndEditing:(NSNotification *)notification { - if (([notification object] == tableCommentsTextView) && ([selectedTable length] > 0)) { + id object = [notification object]; + if ((object == tableCommentsTextView) && ([object isEditable]) && ([selectedTable length] > 0)) { NSString *currentComment = [tableDataInstance statusValueForKey:@"Comment"]; NSString *newComment = [[tableCommentsTextView string] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; - + // Check that the user actually changed the tables comment if (![currentComment isEqualToString:newComment]) { diff --git a/Source/SPTableData.m b/Source/SPTableData.m index bedc9dc1..e1467c2d 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -585,8 +585,31 @@ // Catch unselected views and return nil if ([viewName isEqualToString:@""] || !viewName) return nil; + // Retrieve the CREATE TABLE syntax for the table + CMMCPResult *theResult = [mySQLConnection queryString: [NSString stringWithFormat: @"SHOW CREATE TABLE %@", + [viewName backtickQuotedString] + ]]; + + // Check for any errors, but only display them if a connection still exists + if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + if ([mySQLConnection isConnected]) { + NSRunAlertPanel(@"Error", [NSString stringWithFormat:@"An error occured while retrieving table information:\n\n%@", [mySQLConnection getLastErrorMessage]], @"OK", nil, nil); + } + return nil; + } + + // Retrieve the table syntax string + NSArray *syntaxResult = [theResult fetchRowAsArray]; + + if ([[syntaxResult objectAtIndex:1] isKindOfClass:[NSData class]]) { + tableCreateSyntax = [[NSString alloc] initWithData:[syntaxResult objectAtIndex:1] encoding:[mySQLConnection encoding]]; + } else { + tableCreateSyntax = [[NSString alloc] initWithString:[syntaxResult objectAtIndex:1]]; + } + + // Retrieve the SHOW COLUMNS syntax for the table - CMMCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [viewName backtickQuotedString]]]; + theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [viewName backtickQuotedString]]]; // Check for any errors, but only display them if a connection still exists if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { -- cgit v1.2.3