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

Remove values between single quotes to pass SQL validation #21

Closed
wants to merge 3 commits into from

Conversation

lawsontyler
Copy link

First, I'd like to apologize if this is an abomination...I don't write Python often ;)

I was running into issues with simple-db-migrate when inserting values where the TEXT column had truncated the user's input. The statement looked like this:

INSERT INTO myTable (id, text) VALUES (1, 'Really long text that gets truncated (you know the type');

This is a perfectly valid SQL statement, but MySQL._parse_sql_statements() thought it wasn't due do the extra opening bracket. My change removes all values between single quotes from a string so that when doing Utils.count_occurrences(), all it sees is:

INSERT INTO myTable (id, text) VALUES (1, );

The extra bracket (as well as any other crud between quotes) is removed and the query passes the smell test.

I've also added a test to catch this case - although I'm not sure if passing without an exception or assert of any kind is correct.

Thanks for taking a look. I've only included MySQL, as I don't know the rules in other SQL flavours.

Tyler Lawson added 3 commits December 12, 2013 09:49
…deciding if a query is correct. Before, if there wasn't a matching pair of brackets or quotes within a value, it would raise an invalid syntax exception. Add a test to catch this case.
@wandenberg wandenberg closed this Jan 14, 2017
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.

None yet

2 participants