Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch Splitter: Handle trailing comments with single quotes. #108

Merged
merged 2 commits into from
Mar 23, 2013

Conversation

mpareja
Copy link
Member

@mpareja mpareja commented Mar 23, 2013

There was a nasty bug in the SQL Server batch splitting regex which caused batches to be split incorrectly. Consider the following contrived example SQL:

select first_name, last_name -- don't bother with middle name
from person
GO
select first_name + ' ' + last_name

The statement splitter would not detect the GO statement because it incorrectly considered the single quote in the trailing comment as a string.

I tightened up the regex and made it a bit more legible for future readers.

+ If a trailing comment contains a single quote and the following SQL batch contains a single quote, roundhouse was not recognizing them as separate batches.
+ Split the regex up to make it easier for the next person looking at it to understand.
@mpareja mpareja merged commit 4156cff into master Mar 23, 2013
@mpareja mpareja deleted the splitter branch March 23, 2013 03:32
@ferventcoder
Copy link
Member

Looks good. I just pulled that code in to simplify the original regex, which was failing on some code I had. Thought it was good (leaning on tests, but guess I didn't have enough). Thanks for finding this. Wonder how it works when you have -- inside of the single quote marks. Someone had this...

@mpareja
Copy link
Member Author

mpareja commented Mar 23, 2013

I believe his issue has been around since a297dd4. I ran into it a while back but we were running a custom build of Roundhouse and I hadn't had time to look at it, so we hadn't updated due to it. It's been on my conscience for a while, so it was definitely something high on my to-do list! I expected it should handle that fine, but better safe than sorry, so I ran it against the original issue in https://code.google.com/p/roundhouse/issues/detail?id=71 and it came out as expected:

INSERT [dbo].[Foo] ([Bar]) VALUES (N'hello--world.
Thanks!')
INSERT [dbo].[Foo] ([Bar]) VALUES (N'Go speed racer, go speed racer, go speed racer go!!!!! ')

@ferventcoder
Copy link
Member

That commit definitely caused an issue. But I did take in a pull request around a month ago that may have brought new items. I was hoping it fixed some of the other issues but hadn't had a chance yet to look around. https://groups.google.com/forum/?hl=en&fromgroups=#!searchin/chucknorrisframework/hangs$20regex/chucknorrisframework/wOdQOMXxmNM/HtsXYiJ_EjYJ

It appears I may have have it backwards. The --comments then the ' mark.

@ferventcoder
Copy link
Member

The stuff in 71 was definitely fixed then, but it cropped up this issue: --don't forget to do something and messing up on that.

@ferventcoder
Copy link
Member

And you've now fixed that. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants