aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPSQLParser.m
diff options
context:
space:
mode:
authormtvee <emptyvee@gmail.com>2009-05-13 00:56:36 +0000
committermtvee <emptyvee@gmail.com>2009-05-13 00:56:36 +0000
commit12b84cb69a904fb6ea714ab6d4b0b885f4d54436 (patch)
tree8e0df64c75a9300f375960d1c2dfcfd90e4d9959 /Source/SPSQLParser.m
parent35e6aaac3997475a04984b09fac24ab02574ab27 (diff)
downloadsequelpro-12b84cb69a904fb6ea714ab6d4b0b885f4d54436.tar.gz
sequelpro-12b84cb69a904fb6ea714ab6d4b0b885f4d54436.tar.bz2
sequelpro-12b84cb69a904fb6ea714ab6d4b0b885f4d54436.zip
- added ability to view function and procedures and preliminary ability to input same via the editor
Diffstat (limited to 'Source/SPSQLParser.m')
-rw-r--r--Source/SPSQLParser.m47
1 files changed, 47 insertions, 0 deletions
diff --git a/Source/SPSQLParser.m b/Source/SPSQLParser.m
index e5c490da..ad3697d6 100644
--- a/Source/SPSQLParser.m
+++ b/Source/SPSQLParser.m
@@ -30,6 +30,53 @@
@implementation SPSQLParser : NSMutableString
+/*
+ * return an array of queries
+ */
+- (NSArray *) parseQueries
+{
+ [self deleteComments];
+
+ /* this is a hack so I could test the funcs and procs viewing, needed a way to get those in.
+ * all this does is look for 'delimiter' in the text to trigger this parser. basically
+ * it runs through the query, line by line, and sets the delimiter accordingly to break
+ * out the individual queries. this is not very rebust but works for testing purposes.
+ * I believe Hans is currently working on a more robust parser. :mtv
+ */
+ if( [string rangeOfString:@"delimiter" options:NSCaseInsensitiveSearch].location != NSNotFound ) {
+ NSString *delim = @";";
+ NSString *thisLine = @"";
+ NSMutableArray *nq = [[NSMutableArray alloc] init];
+ NSArray *lines = [self splitStringByCharacter:'\n'];
+ for( NSString *line in lines ) {
+ line = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ if( [line hasPrefix:@"delimiter"] ) {
+ delim = [line substringFromIndex:9];
+ delim = [delim stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ NSLog( @"delimiter now [%@]", delim );
+ continue;
+ }
+ if( [line hasSuffix:delim] ) {
+ thisLine = [thisLine stringByAppendingString:line];
+ [nq addObject:[thisLine substringWithRange:NSMakeRange(0,[thisLine length]-[delim length])]];
+ NSLog( @"query: [%@]", [thisLine substringWithRange:NSMakeRange(0,[thisLine length]-[delim length])] );
+ thisLine = @"";
+ }
+ else {
+ thisLine = [thisLine stringByAppendingString:line];
+ thisLine = [thisLine stringByAppendingString:@"\n"];
+ }
+ }
+ if( thisLine != @"" ) {
+ [nq addObject:thisLine];
+ NSLog( @"query: [%@]", thisLine );
+ }
+ return nq;
+ } else {
+ // just split as normal
+ return [self splitStringByCharacter:';'];
+ }
+}
/*
* Removes comments within the current string, trimming "#", "--[/s]", and "/* * /" style strings.