aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPStringAdditions.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-05-08 14:23:31 +0000
committerstuconnolly <stuart02@gmail.com>2012-05-08 14:23:31 +0000
commit343e4ed439ba0ccc255460df4fc69e25c4a3f91e (patch)
treefb1d7a981f2a371785d7008bf6563a9caf188cd0 /Source/SPStringAdditions.m
parentcb29bcb923804e844411fb4872f55993bf29ee91 (diff)
downloadsequelpro-343e4ed439ba0ccc255460df4fc69e25c4a3f91e.tar.gz
sequelpro-343e4ed439ba0ccc255460df4fc69e25c4a3f91e.tar.bz2
sequelpro-343e4ed439ba0ccc255460df4fc69e25c4a3f91e.zip
Improve formatting of SQL keywords in view syntax prettifier and add an associated test.
Diffstat (limited to 'Source/SPStringAdditions.m')
-rw-r--r--Source/SPStringAdditions.m32
1 files changed, 19 insertions, 13 deletions
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;
}
/**