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

Parsing multiple statements #14

Open
dazinator opened this issue Jul 3, 2014 · 4 comments
Open

Parsing multiple statements #14

dazinator opened this issue Jul 3, 2014 · 4 comments

Comments

@dazinator
Copy link
Contributor

Hey - long time no speak :)

I was wondering if you have any thoughts around how to parse a SQL string that has multiple inidividual statements? For example - I would like to be able to parse:

UPDATE customer SET firstname = 'Dave' WHERE id = 1;
UPDATE customer SET firstname = 'Jo' WHERE id = 2;
DELETE FROM customer WERE id = 3

At the moment, the parser is expecting a single UPDATE, INSERT, SELECT statement etc and so if you try to parse this string, it falls over.

I am suspecting that me doing a string split on a semi colon prior to parsing may not be ideal?

@dazinator
Copy link
Contributor Author

I'm going to create a fork and investigate!

dazinator added a commit to dazinator/SQLGeneration that referenced this issue Jul 6, 2014
1. Created a unit test 'TestBatch_MultipleInserts' that tests whether we can parse sql text that has 2 seperate insert statements in, using semi colon as the line termnator.
2. Extended the SqlTokenRegistry class with support for LineTerminator.
3. Extended the SqlGrammar class, the defineStart() method was changed so that it expects an optional LineTerminator after every statement.

I'm now stuck.. I think I want the Parser Class to return a MatchResult that includes all the Statements, however at the moment it just returns the individual InsertStatement - although it does correctly detect the LineTerminator token..
@dazinator
Copy link
Contributor Author

I have had a go at this in my fork. I managed to extend the Grammar, and Line Terminator tokens are now correctly detected. However, I am stuck on the Parser class. Any chance of a pointer in this area?
I have put more detailed comments against the above check in.

@dazinator
Copy link
Contributor Author

Ahh nevermind - I have just made a break through on this. I can now see the way forward. Hopefully i should be able to submit a pull request to you pretty soon.

dazinator added a commit to dazinator/SQLGeneration that referenced this issue Jul 6, 2014
… contains many different sql commands with terminators in the same batch as opposed to just a single command. jehugaleahsa#14
@dazinator
Copy link
Contributor Author

Have submitted PR for this.

dazinator added a commit to dazinator/SQLGeneration that referenced this issue Oct 5, 2015
1. Created a unit test 'TestBatch_MultipleInserts' that tests whether we can parse sql text that has 2 seperate insert statements in, using semi colon as the line termnator.
2. Extended the SqlTokenRegistry class with support for LineTerminator.
3. Extended the SqlGrammar class, the defineStart() method was changed so that it expects an optional LineTerminator after every statement.

I'm now stuck.. I think I want the Parser Class to return a MatchResult that includes all the Statements, however at the moment it just returns the individual InsertStatement - although it does correctly detect the LineTerminator token..
dazinator added a commit to dazinator/SQLGeneration that referenced this issue Oct 5, 2015
… contains many different sql commands with terminators in the same batch as opposed to just a single command. jehugaleahsa#14
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

No branches or pull requests

1 participant