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

semicolons are invalid characters #3

Closed
AdamFerguson opened this issue Apr 16, 2015 · 2 comments
Closed

semicolons are invalid characters #3

AdamFerguson opened this issue Apr 16, 2015 · 2 comments

Comments

@AdamFerguson
Copy link

Cool idea for a library! Seems like the parser breaks if the sql statement contains ; characters currently. I'm working on a use case right now where I'm trying to send lots of transactions as one statement to execute like this:

BEGIN;
UPDATE .... ;
COMMIT;
BEGIN;
UPDATE .... ;
COMMIT;

Would be nice if it could parse this without throwing an error. Is there a reason semi-colons are considered not kosher?

@twada
Copy link
Owner

twada commented Apr 17, 2015

@AdamFerguson First, thank you for using twowaysql! And thank you for your suggestion.

Hmm... in general terms, accepting semicolons and running multiple statements in a single sql string is not a good idea for security reasons (increases SQL Injection risk), and turned off by many DB drivers by default.

So even if twowaysql accepts multiple statements, database driver will not allow you to execute statements unless turning on flags like MULTI_STATEMENTS explicitly.

My opinion is to split file into statements and let ORMs handle transactions.

content = File.new('multiple_statements.sql').read
content.split(/\;\s*\n/).each do |statement|
  DB.transaction do # BEGIN
    DB["UPDATE .... "]
  end # COMMIT
end

@AdamFerguson
Copy link
Author

Great, thanks for the info on the security concerns with running multiple statements @twada and thanks again for the library.

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

2 participants