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

ResourceDatabasePopulator should ignore MySQL single-line comments in SQL scripts [SPR-16594] #21135

Open
spring-projects-issues opened this issue Mar 14, 2018 · 5 comments
Labels
for: team-attention in: data type: enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 14, 2018

Urs Wiss opened SPR-16594 and commented

In MySQL, starting a line with a hash key is a valid comment (see https://dev.mysql.com/doc/refman/5.7/en/comments.html)

Currently, ResourceDatabasePopulator doesn't recognize lines starting with a hash key as comments. See the example https://github.com/urswiss/spring-jdbc-comment, it's based on h2 but it nonetheless illustrates the point I think.


No further details from SPR-16594

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 15, 2018

Juergen Hoeller commented

The comment prefix is configurable already. Are you specifically asking for "#" to be considered as a comment prefix by default, next to "--"?

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 16, 2018

Urs Wiss commented

yes.
Let me give you some background of how we discovered this issue. I had to add some new testdata to an existing sql. Since we are using MySQL, I had the script connected to the database in IntelliJ. I used the IntelliJ Shortcut for adding a comment (CMD + /), which resulted in a comment that started with a '#'. I ran the script against the database from the IDE and everything worked fine. When I ran the script from inside the testcase however, I got a strange 'invalid constraint' exception. After investigating for a while we discovered that the statement on the line below the comment was not executed, since it also had been commented out.
So yes it would have saved me (and possibly others) time if the "#" had been considered as a comment prefix in addition to "--".
Note that there are also comments embedded between /* and */, but that seems to work fine.

@spring-projects-issues spring-projects-issues added in: data type: enhancement labels Jan 11, 2019
@prateekkapoor
Copy link

@prateekkapoor prateekkapoor commented May 20, 2020

Can I pick this up?

@prateekkapoor
Copy link

@prateekkapoor prateekkapoor commented May 26, 2020

I was facing this issue with spring for prepopulating data in database. After analyzing sprring code I figured out that it can be fixed by adding "#" to DEFAULT_COMMENT_PREFIXES in ScriptUtils class.

Let me know if this correct approach and I can take this up.

@sbrannen sbrannen changed the title ResourceDatabasePopulator should ignore MySQL comments in sql files too [SPR-16594] ResourceDatabasePopulator should ignore MySQL single-line comments in SQL scripts [SPR-16594] May 26, 2020
@sbrannen sbrannen added the for: team-attention label May 26, 2020
@sbrannen
Copy link
Member

@sbrannen sbrannen commented May 26, 2020

After analyzing spring code I figured out that it can be fixed by adding "#" to DEFAULT_COMMENT_PREFIXES in ScriptUtils class.

Let me know if this correct approach and I can take this up.

Yes, that would be the correct approach; however, doing so may be a breaking change for users whose SQL scripts utilize # for a different purpose.

So please hold off on submitting a PR until the team has decided if we want to make this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: team-attention in: data type: enhancement
Projects
None yet
Development

No branches or pull requests

3 participants