Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix a rare issue where duplicating a database could cause an exceptio…
…n if a SHOW CREATE TABLE statement failed (#2413)
  • Loading branch information
dmoagx committed Feb 21, 2016
1 parent f2575a3 commit 63ef786
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Source/SPTableCopy.m
Expand Up @@ -44,9 +44,9 @@ @implementation SPTableCopy
- (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *)targetDB
{
NSString *createTableResult = [self _createTableStatementFor:tableName inDatabase:sourceDB];
NSMutableString *createTableStatement = [[NSMutableString alloc] initWithString:createTableResult];

if ([[createTableStatement substringToIndex:12] isEqualToString:@"CREATE TABLE"]) {
if ([createTableResult hasPrefix:@"CREATE TABLE"]) {
NSMutableString *createTableStatement = [[NSMutableString alloc] initWithString:createTableResult];

// Add the target DB name and the separator dot after "CREATE TABLE ".
[createTableStatement insertString:@"." atIndex:13];
Expand All @@ -59,8 +59,6 @@ - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *
return ![connection queryErrored];
}

[createTableStatement release];

return NO;
}

Expand Down Expand Up @@ -151,7 +149,10 @@ - (NSString *)_createTableStatementFor:(NSString *)tableName inDatabase:(NSStrin

SPMySQLResult *theResult = [connection queryString:showCreateTableStatment];

return [theResult numberOfRows] > 0 ? [[theResult getRowAsArray] objectAtIndex:1] : @"";
if([theResult numberOfRows] > 0) return [[theResult getRowAsArray] objectAtIndex:1];

NSLog(@"query <%@> failed to return the expected result.\n Error state: %@ (%lu)",showCreateTableStatment,[connection lastErrorMessage],[connection lastErrorID]);
return nil;
}

@end

0 comments on commit 63ef786

Please sign in to comment.