From 67bebbe2f9e6222c0a33be77c2d04495026f2437 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 29 Jul 2010 00:57:11 +0000 Subject: - Add support for automatically converting \r and \r\n linebreaks in query syntax to \n. This addresses Issue #652. - Clean up SPSQLParser, and use a few more CFString methods to avoid obj-c messaging in loops - When importing SQL using autodetect, perform a manual SET NAMES if possible to cope with poorly-exported files. --- Source/SPCustomQuery.m | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'Source/SPCustomQuery.m') diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 520370d2..ec5f8347 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -72,11 +72,23 @@ queryParser = [[SPSQLParser alloc] initWithString:[textView string]]; [queryParser setDelimiterSupport:YES]; queries = [queryParser splitStringByCharacter:';']; + + // If carriage returns were found, normalise the queries + if ([queryParser containsCarriageReturns]) { + NSMutableArray *normalisedQueries = [NSMutableArray arrayWithCapacity:[queries count]]; + for (NSString *query in queries) { + [normalisedQueries addObject:[SPSQLParser normaliseQueryForExecution:query]]; + } + queries = normalisedQueries; + } + [queryParser release]; oldThreadedQueryRange = [textView selectedRange]; - // Unselect a selection if given to avoid interferring with error highlighting + + // Unselect a selection if given to avoid interfering with error highlighting [textView setSelectedRange:NSMakeRange(oldThreadedQueryRange.location, 0)]; + // Reset queryStartPosition queryStartPosition = 0; @@ -132,7 +144,7 @@ NSBeep(); return; } - queries = [NSArray arrayWithObject:query]; + queries = [NSArray arrayWithObject:[SPSQLParser normaliseQueryForExecution:query]]; // Remember query start position for error highlighting queryTextViewStartPosition = currentQueryRange.location; @@ -142,6 +154,16 @@ queryParser = [[SPSQLParser alloc] initWithString:[[textView string] substringWithRange:selectedRange]]; [queryParser setDelimiterSupport:YES]; queries = [queryParser splitStringByCharacter:';']; + + // If carriage returns were found, normalise the queries + if ([queryParser containsCarriageReturns]) { + NSMutableArray *normalisedQueries = [NSMutableArray arrayWithCapacity:[queries count]]; + for (NSString *query in queries) { + [normalisedQueries addObject:[SPSQLParser normaliseQueryForExecution:query]]; + } + queries = normalisedQueries; + } + [queryParser release]; // Remember query start position for error highlighting @@ -551,7 +573,7 @@ if (i > 0) { NSString *taskString = [NSString stringWithFormat:NSLocalizedString(@"Running query %ld of %lu...", @"Running multiple queries string"), (long)(i+1), (unsigned long)queryCount]; - [tableDocumentInstance setTaskDescription:taskString]; + [[tableDocumentInstance onMainThread] setTaskDescription:taskString]; [[errorText onMainThread] setStringValue:taskString]; } -- cgit v1.2.3