diff options
author | stuconnolly <stuart02@gmail.com> | 2009-10-02 17:19:03 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-10-02 17:19:03 +0000 |
commit | 3cc8fe3e75f8b92e720eb714b0e1777550c15965 (patch) | |
tree | d63b5200edb3df58bdb8ee92a9067a44766df9a5 /Source | |
parent | 05c67607d85168d4fcfbaae242ca2086625481da (diff) | |
download | sequelpro-3cc8fe3e75f8b92e720eb714b0e1777550c15965.tar.gz sequelpro-3cc8fe3e75f8b92e720eb714b0e1777550c15965.tar.bz2 sequelpro-3cc8fe3e75f8b92e720eb714b0e1777550c15965.zip |
When duplicating a table strip out the names of any occurrences of InnoDB foreign key references as the names must be unique. MySQL will create the new names based on the new table name. Fixes issue #398.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/TablesList.m | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/Source/TablesList.m b/Source/TablesList.m index 546fe2e0..ed3cc651 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -1858,6 +1858,11 @@ [scanner initWithString:[[queryResult fetchRowAsDictionary] objectForKey:@"Create Table"]]; [scanner scanUpToString:@"(" intoString:nil]; [scanner scanUpToString:@"" intoString:&scanString]; + + // If there are any InnoDB referencial constraints we need to strip out the names as they must be unique. + // MySQL will generate the new names based on the new table name. + scanString = [scanString stringByReplacingOccurrencesOfRegex:[NSString stringWithFormat:@"CONSTRAINT `[^`]+` "] withString:@""]; + [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE %@ %@", [[copyTableNameField stringValue] backtickQuotedString], scanString]]; } else if(tblType == SP_TABLETYPE_FUNC || tblType == SP_TABLETYPE_PROC) @@ -1887,7 +1892,9 @@ // replace the old name by the new one and drop the old one [mySQLConnection queryString:[tableSyntax stringByReplacingOccurrencesOfRegex:[NSString stringWithFormat:@"(?<=%@ )(`[^`]+?`)", [tableType uppercaseString]] withString:[[copyTableNameField stringValue] backtickQuotedString]]]; + [tableSyntax release]; + if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { NSBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, tableWindow, self, nil, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't duplicate '%@'.\nMySQL said: %@", @"message of panel when an item cannot be renamed"), [copyTableNameField stringValue], [mySQLConnection getLastErrorMessage]]); |