From 00121910e9ac01c130cffd1f80ba92213c5570d3 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 23 Apr 2009 08:21:32 +0000 Subject: =?UTF-8?q?=E2=80=A2=20ADDED=20support=20to=20duplicate=20views?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 22 ++++++++++--- Source/TablesList.h | 1 + Source/TablesList.m | 64 ++++++++++++++++++++++++++----------- 3 files changed, 64 insertions(+), 23 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index ff4011c2..f0c6595c 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -8,8 +8,9 @@ 353.00 YES - + + YES @@ -3153,7 +3154,7 @@ - 2 + 13 YES 1 YES @@ -4414,7 +4415,7 @@ {3.40282e+38, 3.40282e+38} {213, 107} - + 256 YES @@ -4522,6 +4523,7 @@ {262, 127} + {{0, 0}, {1440, 878}} {213, 129} @@ -12737,6 +12739,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 5426 + + + copyTableMessageField + + + + 5427 + @@ -20154,7 +20164,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{1861, 680}, {200, 32}} + {{1739, 266}, {200, 32}} com.apple.InterfaceBuilder.CocoaPlugin {628, 654} {{284, 769}, {200, 32}} @@ -21041,7 +21051,7 @@ Y2hhbmdlIHRoZSBvcmRlcg - 5426 + 5427 @@ -22177,6 +22187,7 @@ Y2hhbmdlIHRoZSBvcmRlcg YES addTableButton copyTableContentSwitch + copyTableMessageField copyTableNameField copyTableSheet customQueryInstance @@ -22202,6 +22213,7 @@ Y2hhbmdlIHRoZSBvcmRlcg id id id + id NSMenuItem NSMenuItem id diff --git a/Source/TablesList.h b/Source/TablesList.h index f3abca1b..265fb73b 100644 --- a/Source/TablesList.h +++ b/Source/TablesList.h @@ -47,6 +47,7 @@ enum sp_table_types IBOutlet id copyTableSheet; IBOutlet id tablesListView; IBOutlet id copyTableNameField; + IBOutlet id copyTableMessageField; IBOutlet id copyTableContentSwitch; IBOutlet id tabView; IBOutlet id tableSheet; diff --git a/Source/TablesList.m b/Source/TablesList.m index c78ca385..47dbc3c2 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -257,7 +257,7 @@ } /** - * Copies a table, if desired with content + * Copies a table, if desired with content, or view */ - (IBAction)copyTable:(id)sender { @@ -267,6 +267,8 @@ // NSMutableString *rowValue = [NSMutableString string]; // NSMutableArray *fieldValues; int code; + BOOL isView; + NSString *tblType; // int rowCount, i, j; // BOOL errors = NO; @@ -277,9 +279,24 @@ } [tableWindow endEditingFor:nil]; + // Detect table type: table or view + isView = [[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_VIEW; + //open copyTableSheet [copyTableNameField setStringValue:[NSString stringWithFormat:@"%@Copy", [tables objectAtIndex:[tablesListView selectedRow]]]]; [copyTableContentSwitch setState:NSOffState]; + // Hide if selected item is a view + [copyTableContentSwitch setEnabled:!isView]; + // Set message according to table type and the table type string + if(isView) { + [copyTableMessageField setStringValue:NSLocalizedString(@"Duplicate view to", @"duplicate view message")]; + tblType = @"VIEW"; + } else { + [copyTableMessageField setStringValue:NSLocalizedString(@"Duplicate table to", @"duplicate table message")]; + tblType = @"TABLE"; + } + + [NSApp beginSheet:copyTableSheet modalForWindow:tableWindow modalDelegate:self @@ -299,30 +316,38 @@ } //get table structure - queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE TABLE %@", + queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW CREATE %@ %@", + tblType, [[tables objectAtIndex:[tablesListView selectedRow]] backtickQuotedString] ]]; if ( ![queryResult numOfRows] ) { //error while getting table structure - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"Couldn't get table information.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection getLastErrorMessage]]); + NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"Couldn't get table information.\nMySQL said: %@", @"message of panel when table information cannot be retrieved"), [mySQLConnection getLastErrorMessage]]); } else { //insert new table name in create syntax and create new table NSScanner *scanner = [NSScanner alloc]; NSString *scanString; - [scanner initWithString:[[queryResult fetchRowAsDictionary] objectForKey:@"Create Table"]]; - [scanner scanUpToString:@"(" intoString:nil]; - [scanner scanUpToString:@"" intoString:&scanString]; - [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE %@ %@", [[copyTableNameField stringValue] backtickQuotedString], scanString]]; + if(isView){ + [scanner initWithString:[[queryResult fetchRowAsDictionary] objectForKey:@"Create View"]]; + [scanner scanUpToString:@"AS" intoString:nil]; + [scanner scanUpToString:@"" intoString:&scanString]; + [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE VIEW %@ %@", [[copyTableNameField stringValue] backtickQuotedString], scanString]]; + } else { + [scanner initWithString:[[queryResult fetchRowAsDictionary] objectForKey:@"Create Table"]]; + [scanner scanUpToString:@"(" intoString:nil]; + [scanner scanUpToString:@"" intoString:&scanString]; + [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE %@ %@", [[copyTableNameField stringValue] backtickQuotedString], scanString]]; + } [scanner release]; if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { //error while creating new table - NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"Couldn't create table.\nMySQL said: %@", @"message of panel when table cannot be created"), [mySQLConnection getLastErrorMessage]]); + NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"Couldn't create table.\nMySQL said: %@", @"message of panel when table cannot be created"), [mySQLConnection getLastErrorMessage]]); } else { if ( [copyTableContentSwitch state] == NSOnState ) { @@ -349,13 +374,16 @@ } } - [tables insertObject:[copyTableNameField stringValue] atIndex:[tablesListView selectedRow]+1]; - [tableTypes insertObject:[NSNumber numberWithInt:SP_TABLETYPE_TABLE] atIndex:[tablesListView selectedRow]+1]; - [tablesListView reloadData]; - [tablesListView selectRow:[tablesListView selectedRow]+1 byExtendingSelection:NO]; - [tablesListView scrollRowToVisible:[tablesListView selectedRow]]; - } - } + [tables insertObject:[copyTableNameField stringValue] atIndex:[tablesListView selectedRow]+1]; + [tableTypes insertObject:[NSNumber numberWithInt:(isView)?SP_TABLETYPE_VIEW : SP_TABLETYPE_TABLE] atIndex:[tablesListView selectedRow]+1]; + [tablesListView reloadData]; + [tablesListView selectRow:[tablesListView selectedRow]+1 byExtendingSelection:NO]; + [tablesListView scrollRowToVisible:[tablesListView selectedRow]]; + [self updateTables:self]; + [tablesListView scrollRowToVisible:[tablesListView selectedRow]]; + + } + } } #pragma mark Alert sheet methods @@ -385,7 +413,7 @@ #pragma mark Additional methods /** - * Removes selected table(s) from mysql-db and tableView + * Removes selected table(s) or view(s) from mysql-db and tableView */ - (void)removeTable { -- cgit v1.2.3