guilhermechapiewski/simple-db-migrate — pull request #21 by lawsontyler (2013-12-12 16:20:43+00:00)
Title: Remove values between single quotes to pass SQL validation

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.