Skip to content

Commit

Permalink
Skip SET LOCAL (#366)
Browse files Browse the repository at this point in the history
Co-authored-by: Montana Low <[email protected]>
  • Loading branch information
mlarraz and montanalow authored Jun 23, 2023
1 parent ee22087 commit 9e79605
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def custom_error_message?(connection, message)
SQL_PRIMARY_MATCHERS = [/\A\s*select.+for update\Z/i, /select.+lock in share mode\Z/i, /\A\s*select.+(nextval|currval|lastval|get_lock|release_lock|pg_advisory_lock|pg_advisory_unlock)\(/i].map(&:freeze).freeze
SQL_REPLICA_MATCHERS = [/\A\s*(select|with.+\)\s*select)\s/i].map(&:freeze).freeze
SQL_ALL_MATCHERS = [/\A\s*set\s/i].map(&:freeze).freeze
SQL_SKIP_ALL_MATCHERS = [/\A\s*set\s+local\s/i].map(&:freeze).freeze
SQL_SKIP_STICKINESS_MATCHERS = [/\A\s*show\s([\w]+\s)?(field|table|database|schema|view|index)(es|s)?/i, /\A\s*(set|describe|explain|pragma)\s/i].map(&:freeze).freeze

SQL_MASTER_MATCHERS = SQL_PRIMARY_MATCHERS
Expand Down Expand Up @@ -128,6 +129,10 @@ def sql_all_matchers
SQL_ALL_MATCHERS
end

def sql_skip_all_matchers
SQL_SKIP_ALL_MATCHERS
end

def sql_skip_stickiness_matchers
SQL_SKIP_STICKINESS_MATCHERS
end
Expand Down Expand Up @@ -163,6 +168,7 @@ def should_stick?(method_name, args)

def needed_by_all?(_method_name, args)
sql = coerce_query_to_sql_string(args.first)
return false if sql_skip_all_matchers.any? { |m| sql =~ m }
return true if sql_all_matchers.any? { |m| sql =~ m }

false
Expand Down

0 comments on commit 9e79605

Please sign in to comment.