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

Handle leading spaces in the SQL #72

Merged
merged 2 commits into from
Feb 7, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def custom_error_message?(connection, message)
hijack_method :execute, :select_rows, :exec_query
send_to_all :connect, :disconnect!, :reconnect!, :verify!, :clear_cache!, :reset!

SQL_MASTER_MATCHERS = [/^select.+for update$/i, /select.+lock in share mode$/i].map(&:freeze).freeze
SQL_SLAVE_MATCHERS = [/^select\s/i].map(&:freeze).freeze
SQL_ALL_MATCHERS = [/^set\s/i].map(&:freeze).freeze
SQL_SKIP_STICKINESS_MATCHERS = [/^show\s([\w]+\s)?(field|table|database|schema|view|index)(es|s)?/i, /^(set|describe|explain|pragma)\s/i].map(&:freeze).freeze
SQL_MASTER_MATCHERS = [/^\s*select.+for update$/i, /select.+lock in share mode$/i].map(&:freeze).freeze
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a second regex here which should have the same matcher.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! One second...

SQL_SLAVE_MATCHERS = [/^\s*select\s/i].map(&:freeze).freeze
SQL_ALL_MATCHERS = [/^\s*set\s/i].map(&:freeze).freeze
SQL_SKIP_STICKINESS_MATCHERS = [/^\s*show\s([\w]+\s)?(field|table|database|schema|view|index)(es|s)?/i, /^(set|describe|explain|pragma)\s/i].map(&:freeze).freeze


def sql_master_matchers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
'set @@things' => true,
'commit' => true,
'select * from felines' => false,
' select * from felines' => false,
'select * from users for update' => true,
' select * from users for update' => true,
'select * from users lock in share mode' => true,
'select * from users where name = "for update"' => false,
'select * from users where name = "lock in share mode"' => false
Expand Down