aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-01-28 17:04:04 +0000
committerBibiko <bibiko@eva.mpg.de>2010-01-28 17:04:04 +0000
commit862a431ebf1571f09890f43702e50fdc43b13415 (patch)
treee5784b265d1a92e0db4786b62bfa34e6b3d55675 /Source
parent70558850380b1ea9bb8e7410bc3e77a7cff64263 (diff)
downloadsequelpro-862a431ebf1571f09890f43702e50fdc43b13415.tar.gz
sequelpro-862a431ebf1571f09890f43702e50fdc43b13415.tar.bz2
sequelpro-862a431ebf1571f09890f43702e50fdc43b13415.zip
• for [CMTextView selectLineNumber:…] added safety-check for lineNumber < 1
• error message highlighting in CustomQuery - check for error ID 1064 before trying to select the erroneous line given as '… at line x' (this solves the issue that other error messages could end by a number) - improved regexp to get rid of localized error messages for parsing the erroneous line number (thanks to Jakob) - look the last number in a string - improved regexp to parse for the 'near message' for localized error messages
Diffstat (limited to 'Source')
-rw-r--r--Source/CMTextView.m3
-rw-r--r--Source/CustomQuery.m19
2 files changed, 14 insertions, 8 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index 1d75eb93..6bd6f315 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -760,9 +760,10 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
lineNumber++;
}
}
-
+
// Safety-check the line number
if (lineNumber > [lineRanges count]) lineNumber = [lineRanges count];
+ if (lineNumber < 1) lineNumber = 1;
// Grab the range to select
selRange = NSRangeFromString([lineRanges objectAtIndex:lineNumber-1]);
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 6f8afecf..45f177a3 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -691,9 +691,13 @@
if ( [mySQLConnection queryCancelled] || ([errors length] && !queryIsTableSorter)) {
// set the error text
[errorText setStringValue:errors];
- // select the line x of the first error if error message contains "at line x"
- NSRange errorLineNumberRange = [errors rangeOfRegex:@"(?<!key )([0-9]+)$" options:RKLNoOptions inRange:NSMakeRange(0, [errors length]) capture:1 error:nil];
- if(errorLineNumberRange.length) // if a line number was found
+
+ // try to select the line x of the first error if error message with ID 1064 contains "at line x"
+ // by capturing the last number of the error string
+ NSRange errorLineNumberRange = [errors rangeOfRegex:@"([0-9]+)[^0-9]*$" options:RKLNoOptions inRange:NSMakeRange(0, [errors length]) capture:1L error:nil];
+
+ // if error ID 1064 and a line number was found
+ if([mySQLConnection getLastErrorID] == 1064 && errorLineNumberRange.length)
{
// Get the line number
NSUInteger errorAtLine = [[errors substringWithRange:errorLineNumberRange] integerValue];
@@ -701,7 +705,7 @@
[textView selectLineNumber:errorAtLine+lineOffset ignoreLeadingNewLines:YES];
// Check for near message
- NSRange errorNearMessageRange = [errors rangeOfRegex:@" '(+*?)' " options:(RKLMultiline|RKLDotAll) inRange:NSMakeRange(0, [errors length]) capture:1 error:nil];
+ NSRange errorNearMessageRange = [errors rangeOfRegex:@"[( ]'(.+)'[ -]" options:(RKLMultiline|RKLDotAll) inRange:NSMakeRange(0, [errors length]) capture:1L error:nil];
if(errorNearMessageRange.length) // if a "near message" was found
{
// Build the range to search for nearMessage (beginning from queryStartPosition to try to avoid mismatching)
@@ -712,7 +716,6 @@
textNearMessageRange = NSMakeRange(textNearMessageRange.location+queryStartPosition, textNearMessageRange.length);
// Select the near message and scroll to it
[textView setSelectedRange:textNearMessageRange];
- [textView scrollRangeToVisible:textNearMessageRange];
}
} else { // Select first erroneous query entirely
@@ -727,8 +730,8 @@
// select the query for which the first error was detected
queryRange = [self queryTextRangeForQuery:firstErrorOccuredInQuery startPosition:queryStartPosition];
[textView setSelectedRange:queryRange];
+ [textView scrollRangeToVisible:queryRange];
}
-
}
} else if ( [errors length] && queryIsTableSorter ) {
@@ -1071,10 +1074,12 @@
[queries release];
- // Remove all leading white spaces
+ // Remove all leading and trailing white spaces
NSInteger offset = [theQueryString rangeOfRegex:@"^(\\s*)"].length;
theQueryRange.location += offset;
theQueryRange.length -= offset;
+ offset = [theQueryString rangeOfRegex:@"(\\s*)$"].length;
+ theQueryRange.length -= offset;
return theQueryRange;
}