From 0e9df92aef86421374ca1756ff3cbfa4c386c822 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 9 Oct 2009 10:13:42 +0000 Subject: =?UTF-8?q?=E2=80=A2=20fixed=20bug=20while=20parsing=20the=20CREAT?= =?UTF-8?q?E=20TABLE=20syntax=20if=20a=20column=20name=20contains=20a=20'#?= =?UTF-8?q?'=20or=20'/*'=20-=20this=20fixes=20issue=20431=20-=20furthermor?= =?UTF-8?q?e=20if=20the=20parsing=20process=20fails=20for=20some=20other?= =?UTF-8?q?=20reasons,=20i.e.=20a=20table=20name=20is=20NULL=20or=20empty?= =?UTF-8?q?=20SP=20alerts=20the=20user=20about=20it=20instead=20of=20stall?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/SPSQLParser.h | 3 ++- Source/SPSQLParser.m | 11 +++++++++++ Source/SPTableData.m | 14 ++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Source/SPSQLParser.h b/Source/SPSQLParser.h index 73dfe493..76105e27 100644 --- a/Source/SPSQLParser.h +++ b/Source/SPSQLParser.h @@ -68,6 +68,7 @@ int delimiterLength; BOOL charIsDelimiter; BOOL isDelimiterCommand; + BOOL ignoreCommentStrings; } @@ -77,7 +78,7 @@ typedef enum _SPCommentTypes { SPCStyleComment = 2 } SPCommentType; - +- (void) setIgnoringCommentStrings:(BOOL)ignoringCommentStrings; /* * Removes comments within the current string, trimming "#", "--[/s]", and "/* * /" style strings. diff --git a/Source/SPSQLParser.m b/Source/SPSQLParser.m index 0b968d0a..4484c4c2 100644 --- a/Source/SPSQLParser.m +++ b/Source/SPSQLParser.m @@ -42,6 +42,10 @@ TO_BUFFER_STATE to_scan_string (const char *); */ @implementation SPSQLParser : NSMutableString +- (void)setIgnoringCommentStrings:(BOOL)ignoringCommentStrings +{ + ignoreCommentStrings = ignoringCommentStrings; +} /* * Removes comments within the current string, trimming "#", "--[/s]", and "/* * /" style strings. @@ -554,11 +558,13 @@ TO_BUFFER_STATE to_scan_string (const char *); break; case '#': + if(ignoreCommentStrings) break; currentStringIndex = [self endIndexOfCommentOfType:SPHashComment startingAtIndex:currentStringIndex]; break; // For comments starting "/*", ensure the start syntax is valid before proceeding. case '/': + if(ignoreCommentStrings) break; if (stringLength < currentStringIndex + 1) break; if ((unichar)(long)(*charAtIndex)(self, @selector(charAtIndex:), currentStringIndex+1) != '*') break; currentStringIndex = [self endIndexOfCommentOfType:SPCStyleComment startingAtIndex:currentStringIndex]; @@ -642,11 +648,13 @@ TO_BUFFER_STATE to_scan_string (const char *); break; case '#': + if(ignoreCommentStrings) break; currentStringIndex = [self endIndexOfCommentOfType:SPHashComment startingAtIndex:currentStringIndex]; break; // For comments starting "/*", ensure the start syntax is valid before proceeding. case '/': + if(ignoreCommentStrings) break; if (stringLength < currentStringIndex + 1) break; if ((unichar)(long)(*charAtIndex)(self, @selector(charAtIndex:), currentStringIndex+1) != '*') break; currentStringIndex = [self endIndexOfCommentOfType:SPCStyleComment startingAtIndex:currentStringIndex]; @@ -849,12 +857,15 @@ TO_BUFFER_STATE to_scan_string (const char *); /* Required and primitive methods to allow subclassing class cluster */ #pragma mark - - (id) init { + if (self = [super init]) { string = [[NSMutableString string] retain]; } parsedToChar = '\0'; parsedToPosition = -1; charCacheEnd = -1; + ignoreCommentStrings = NO; + return self; } - (id) initWithBytes:(const void *)bytes length:(unsigned int)length encoding:(NSStringEncoding)encoding { diff --git a/Source/SPTableData.m b/Source/SPTableData.m index 66224529..ec02c301 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -380,11 +380,24 @@ quoteCharacter = [fieldsParser characterAtIndex:0]; // Capture the area between the two backticks as the name + // Set the parser to ignoreCommentStrings since a field name can contain # or /* + [fieldsParser setIgnoringCommentStrings:YES]; NSString *fieldName = [fieldsParser trimAndReturnStringFromCharacter: quoteCharacter toCharacter: quoteCharacter trimmingInclusively: YES returningInclusively: NO ignoringQuotedStrings: NO]; + if(fieldName == nil || [fieldName length] == 0) { + NSBeep(); + NSAlert *alert = [[NSAlert alloc] init]; + [alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button")]; + [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"“%@” couldn't be parsed. You can edit the column setup but the column will not be shown in the Content view; please report this issue to the Sequel Pro team using the Help menu item.", @"“%@” couldn't be parsed. You can edit the column setup but the column will not be shown in the Content view; please report this issue to the Sequel Pro team using the Help menu item."), fieldsParser]]; + [alert setMessageText:NSLocalizedString(@"Error while parsing CREATE TABLE syntax",@"error while parsing CREATE TABLE syntax")]; + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + [alert release]; + continue; + } //if the next character is again a backtick, we stumbled across an escaped backtick. we have to continue parsing. while ([fieldsParser characterAtIndex:0] == quoteCharacter) { fieldName = [fieldName stringByAppendingFormat: @"`%@", @@ -395,6 +408,7 @@ ignoringQuotedStrings: NO] ]; } + [fieldsParser setIgnoringCommentStrings:NO]; [tableColumn setObject:[NSNumber numberWithInt:[tableColumns count]] forKey:@"datacolumnindex"]; [tableColumn setObject:fieldName forKey:@"name"]; -- cgit v1.2.3