aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CustomQuery.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2009-06-04 15:25:20 +0000
committerBibiko <bibiko@eva.mpg.de>2009-06-04 15:25:20 +0000
commitb3dee5036052523e1af4bac535d5b97452ff2995 (patch)
tree574ab0c029ea9f3efd1e8b9c264df0c680523633 /Source/CustomQuery.m
parentfa3a82bd89eee142c575e13e47eb6a7bd5e1fc89 (diff)
downloadsequelpro-b3dee5036052523e1af4bac535d5b97452ff2995.tar.gz
sequelpro-b3dee5036052523e1af4bac535d5b97452ff2995.tar.bz2
sequelpro-b3dee5036052523e1af4bac535d5b97452ff2995.zip
• updated queryTextRangeForQuery: method to make usage of the new SQLParser
Diffstat (limited to 'Source/CustomQuery.m')
-rw-r--r--Source/CustomQuery.m26
1 files changed, 11 insertions, 15 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 8e7d3325..49b2f64a 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -739,16 +739,17 @@
{
SPSQLParser *customQueryParser;
NSArray *queries;
- int i;
// If the supplied position is negative or beyond the end of the string, return nil.
if (position < 0 || position > [[textView string] length])
return NSMakeRange(NSNotFound,0);
- // Split the current text into queries
+ // Split the current text into ranges of queries
customQueryParser = [[SPSQLParser alloc] initWithString:[[textView string] substringWithRange:NSMakeRange(position, [[textView string] length]-position)]];
- queries = [[NSArray alloc] initWithArray:[customQueryParser splitStringByCharacter:';']];
+ queries = [[NSArray alloc] initWithArray:[customQueryParser splitSqlStringIntoRangesByCharacter:';']];
[customQueryParser release];
+
+ // Check for a valid index
anIndex--;
if(anIndex < 0 || anIndex >= [queries count])
{
@@ -756,21 +757,16 @@
return NSMakeRange(NSNotFound, 0);
}
- NSString *theQuery = [queries objectAtIndex:anIndex];
-
- // Calculate the text length before that query at index anIndex
- long prevQueriesLength = 0;
- for (i = 0; i < anIndex; i++ ) {
- prevQueriesLength += [[queries objectAtIndex:i] length] + 1;
- }
-
+ NSRange theQueryRange = [[queries objectAtIndex:anIndex] rangeValue];
+ NSString *theQueryString = [[textView string] substringWithRange:theQueryRange];
+
[queries release];
// Remove all leading white spaces
- NSError *err;
- int offset = [theQuery rangeOfRegex:@"^(\\s*)" options:RKLNoOptions inRange:NSMakeRange(0, [theQuery length]) capture:1 error:&err].length;
-
- return NSMakeRange(position+offset+prevQueriesLength, [theQuery length] - offset);
+ int offset = [theQueryString rangeOfRegex:@"^(\\s*)"].length;
+ theQueryRange.location += offset;
+ theQueryRange.length -= offset;
+ return theQueryRange;
}
/*