diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPSQLExporter.m | 8 | ||||
-rw-r--r-- | Source/SPStringAdditions.m | 32 |
2 files changed, 23 insertions, 17 deletions
diff --git a/Source/SPSQLExporter.m b/Source/SPSQLExporter.m index 907360ea..4def00d3 100644 --- a/Source/SPSQLExporter.m +++ b/Source/SPSQLExporter.m @@ -251,10 +251,10 @@ } // Add a 'DROP TABLE' command if required - if (sqlOutputIncludeDropSyntax) + if (sqlOutputIncludeDropSyntax) { [[self exportOutputFile] writeData:[[NSString stringWithFormat:@"DROP %@ IF EXISTS %@;\n\n", ((tableType == SPTableTypeTable) ? @"TABLE" : @"VIEW"), [tableName backtickQuotedString]] - dataUsingEncoding:[self exportOutputEncoding]]]; - + dataUsingEncoding:[self exportOutputEncoding]]]; + } // Add the create syntax for the table if specified in the export dialog if (sqlOutputIncludeStructure && createTableSyntax) { @@ -575,7 +575,7 @@ [metaString setString:@"\n\n"]; // Add the name of table [metaString appendFormat:@"# Replace placeholder table for %@ with correct view syntax\n# ------------------------------------------------------------\n\n", tableName]; - [metaString appendFormat:@"DROP TABLE %@;\n", [tableName backtickQuotedString]]; + [metaString appendFormat:@"DROP TABLE %@;\n\n", [tableName backtickQuotedString]]; [metaString appendFormat:@"%@;\n", [viewSyntaxes objectForKey:tableName]]; [[self exportOutputFile] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 84c5fa86..55d83a76 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -265,37 +265,43 @@ { NSRange searchRange = NSMakeRange(0, [self length]); NSRange matchedRange; - NSError *err = NULL; NSMutableString *tblSyntax = [NSMutableString stringWithCapacity:[self length]]; - NSString * re = @"(.*?) AS select (.*?) (from.*)"; + NSString *re = @"(.*?) AS select (.*?) (from.*)"; // Create view syntax - matchedRange = [self rangeOfRegex:re options:(RKLMultiline|RKLDotAll) inRange:searchRange capture:1 error:&err]; + matchedRange = [self rangeOfRegex:re options:(RKLMultiline|RKLDotAll) inRange:searchRange capture:1 error:nil]; - if (!matchedRange.length || matchedRange.length > [self length]) return([self description]); + if (!matchedRange.length || matchedRange.length > [self length]) return [self description]; [tblSyntax appendString:[self substringWithRange:matchedRange]]; - [tblSyntax appendString:@"\nAS select\n "]; + [tblSyntax appendString:@"\nAS SELECT\n "]; // Match all column definitions, split them by ',', and rejoin them by '\n' - matchedRange = [self rangeOfRegex:re options:(RKLMultiline|RKLDotAll) inRange:searchRange capture:2 error:&err]; + matchedRange = [self rangeOfRegex:re options:(RKLMultiline|RKLDotAll) inRange:searchRange capture:2 error:nil]; - if (!matchedRange.length || matchedRange.length > [self length]) return([self description]); + if (!matchedRange.length || matchedRange.length > [self length]) return [self description]; [tblSyntax appendString:[[[self substringWithRange:matchedRange] componentsSeparatedByString:@"`,`"] componentsJoinedByString:@"`,\n `"]]; - // From ... at a new line - matchedRange = [self rangeOfRegex:re options:(RKLMultiline|RKLDotAll) inRange:searchRange capture:3 error:&err]; + // FROM ... on a new line + matchedRange = [self rangeOfRegex:re options:(RKLMultiline|RKLDotAll) inRange:searchRange capture:3 error:nil]; - if (!matchedRange.length || matchedRange.length > [self length]) return([self description]); + if (!matchedRange.length || matchedRange.length > [self length]) return [self description]; + + NSMutableString *from = [[NSMutableString alloc] initWithString:[self substringWithRange:matchedRange]]; + + // Uppercase FROM + [from replaceCharactersInRange:NSMakeRange(0, 4) withString:@"FROM"]; [tblSyntax appendString:@"\n"]; - [tblSyntax appendString:[self substringWithRange:matchedRange]]; + [tblSyntax appendString:from]; + + [from release]; // Where clause at a new line if given - [tblSyntax replaceOccurrencesOfString:@" where (" withString:@"\nwhere (" options:NSLiteralSearch range:NSMakeRange(0, [tblSyntax length])]; + [tblSyntax replaceOccurrencesOfString:@" WHERE (" withString:@"\nWHERE (" options:NSLiteralSearch range:NSMakeRange(0, [tblSyntax length])]; - return(tblSyntax); + return tblSyntax; } /** |