diff options
author | stuconnolly <stuart02@gmail.com> | 2009-10-02 17:52:12 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2009-10-02 17:52:12 +0000 |
commit | 8884c0dfce8e22893c232648a314ba4e0604caae (patch) | |
tree | da4338cf8bdba61834b2104e06ccaf5d5e1d67dd /Source/TablesList.m | |
parent | 3cc8fe3e75f8b92e720eb714b0e1777550c15965 (diff) | |
download | sequelpro-8884c0dfce8e22893c232648a314ba4e0604caae.tar.gz sequelpro-8884c0dfce8e22893c232648a314ba4e0604caae.tar.bz2 sequelpro-8884c0dfce8e22893c232648a314ba4e0604caae.zip |
When duplicating table, but not its contents strip out any occurrence of a present AUTO_INCREMENT value. Fixes issue #391.
Diffstat (limited to 'Source/TablesList.m')
-rw-r--r-- | Source/TablesList.m | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Source/TablesList.m b/Source/TablesList.m index ed3cc651..11a931ec 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -1811,6 +1811,8 @@ return; } + BOOL copyTableContent = ([copyTableContentSwitch state] == NSOnState); + int tblType = [[filteredTableTypes objectAtIndex:[tablesListView selectedRow]] intValue]; switch (tblType){ @@ -1863,6 +1865,11 @@ // MySQL will generate the new names based on the new table name. scanString = [scanString stringByReplacingOccurrencesOfRegex:[NSString stringWithFormat:@"CONSTRAINT `[^`]+` "] withString:@""]; + // If we're not copying the tables content as well then we need to strip out any AUTO_INCREMENT presets. + if (!copyTableContent) { + scanString = [scanString stringByReplacingOccurrencesOfRegex:[NSString stringWithFormat:@"AUTO_INCREMENT=[0-9]+ "] withString:@""]; + } + [mySQLConnection queryString:[NSString stringWithFormat:@"CREATE TABLE %@ %@", [[copyTableNameField stringValue] backtickQuotedString], scanString]]; } else if(tblType == SP_TABLETYPE_FUNC || tblType == SP_TABLETYPE_PROC) @@ -1909,7 +1916,7 @@ [NSString stringWithFormat:NSLocalizedString(@"Couldn't create '%@'.\nMySQL said: %@", @"message of panel when table cannot be created"), [copyTableNameField stringValue], [mySQLConnection getLastErrorMessage]]); } else { - if ( [copyTableContentSwitch state] == NSOnState ) { + if (copyTableContent) { //copy table content [mySQLConnection queryString:[NSString stringWithFormat: @"INSERT INTO %@ SELECT * FROM %@", |