aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/DBView.xib22
-rw-r--r--Source/TablesList.h1
-rw-r--r--Source/TablesList.m64
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 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="4811"/>
<integer value="3994"/>
+ <integer value="4811"/>
+ <integer value="500"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -3153,7 +3154,7 @@
</object>
</object>
</object>
- <int key="NSSelectedIndex">2</int>
+ <int key="NSSelectedIndex">13</int>
<bool key="NSPullDown">YES</bool>
<int key="NSPreferredEdge">1</int>
<bool key="NSUsesItemFromMenu">YES</bool>
@@ -4414,7 +4415,7 @@
<string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
<string key="NSWindowContentMinSize">{213, 107}</string>
<object class="NSView" key="NSWindowView" id="653204527">
- <nil key="NSNextResponder"/>
+ <reference key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -4522,6 +4523,7 @@
</object>
</object>
<string key="NSFrameSize">{262, 127}</string>
+ <reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1440, 878}}</string>
<string key="NSMinSize">{213, 129}</string>
@@ -12737,6 +12739,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<int key="connectionID">5426</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">copyTableMessageField</string>
+ <reference key="source" ref="438574515"/>
+ <reference key="destination" ref="395811856"/>
+ </object>
+ <int key="connectionID">5427</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -20154,7 +20164,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{1861, 680}, {200, 32}}</string>
+ <string>{{1739, 266}, {200, 32}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>{628, 654}</string>
<string>{{284, 769}, {200, 32}}</string>
@@ -21041,7 +21051,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">5426</int>
+ <int key="maxID">5427</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -22177,6 +22187,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addTableButton</string>
<string>copyTableContentSwitch</string>
+ <string>copyTableMessageField</string>
<string>copyTableNameField</string>
<string>copyTableSheet</string>
<string>customQueryInstance</string>
@@ -22202,6 +22213,7 @@ Y2hhbmdlIHRoZSBvcmRlcg</string>
<string>id</string>
<string>id</string>
<string>id</string>
+ <string>id</string>
<string>NSMenuItem</string>
<string>NSMenuItem</string>
<string>id</string>
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
{