diff options
author | mltownsend <mltownsend@gmail.com> | 2009-08-11 17:00:46 +0000 |
---|---|---|
committer | mltownsend <mltownsend@gmail.com> | 2009-08-11 17:00:46 +0000 |
commit | 80f757d7f217ae836f6c8de60134bc2a5d005687 (patch) | |
tree | 6969e36a3bd1f63227d67d2f2bdb224c36b1aeed /Source/SPStringAdditions.m | |
parent | f6afd1e9699b891f1deee9058a1737e8c5744bd7 (diff) | |
download | sequelpro-80f757d7f217ae836f6c8de60134bc2a5d005687.tar.gz sequelpro-80f757d7f217ae836f6c8de60134bc2a5d005687.tar.bz2 sequelpro-80f757d7f217ae836f6c8de60134bc2a5d005687.zip |
User Manager feature
Diffstat (limited to 'Source/SPStringAdditions.m')
-rw-r--r-- | Source/SPStringAdditions.m | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Source/SPStringAdditions.m b/Source/SPStringAdditions.m index 81c501f9..5ddc14f3 100644 --- a/Source/SPStringAdditions.m +++ b/Source/SPStringAdditions.m @@ -163,6 +163,42 @@ return quotedString; } +// ------------------------------------------------------------------------------- +// tickQuotedString +// +// Returns the string quoted with ticks as required for MySQL identifiers +// eg.: tablename => 'tablename' +// my'table => 'my''table' +// ------------------------------------------------------------------------------- +- (NSString *)tickQuotedString +{ + // mutableCopy automatically retains the returned string, so don't forget to release it later... + NSMutableString *workingCopy = [self mutableCopy]; + + // First double all backticks in the string to escape them + // I don't want to use "stringByReplacingOccurrencesOfString:withString:" because it's only available in 10.5 + [workingCopy replaceOccurrencesOfString: @"'" + withString: @"''" + options: NSLiteralSearch + range: NSMakeRange(0, [workingCopy length]) ]; + + // Add the quotes around the string + NSString *quotedString = [NSString stringWithFormat: @"'%@'", workingCopy]; + + [workingCopy release]; + + return quotedString; +} + +- (NSString *)replaceUnderscoreWithSpace +{ + NSMutableString *workingCopy = [self mutableCopy]; + [workingCopy replaceOccurrencesOfString:@"_" + withString:@" " + options:NSLiteralSearch + range:NSMakeRange(0, [workingCopy length])]; + return [workingCopy autorelease]; +} // ------------------------------------------------------------------------------- // createViewSyntaxPrettifier |