Permalink
Browse files

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 63ef786ffa86a3b095d55178f34c6b90dcfaf1bc
Showing with 6 additions and 5 deletions.
  1. +6 −5 Source/SPTableCopy.m
@@ -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];
@@ -59,8 +59,6 @@ - (BOOL)copyTable:(NSString *)tableName from:(NSString *)sourceDB to:(NSString *
return ![connection queryErrored];
}
[createTableStatement release];
return NO;
}
@@ -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.