Skip to content

Commit

Permalink
Simplify quoting logic for generic adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
zjohl committed Dec 10, 2024
1 parent e60f5d3 commit 4a8430e
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions lib/odbc_adapter/adapters/null_odbc_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Adapters
# registry. This allows for minimal support for DBMSs for which we don't
# have an explicit adapter.
class NullODBCAdapter < ActiveRecord::ConnectionAdapters::ODBCAdapter
IDENTIFIER_QUOTE_CHAR = "\"".freeze

# Using the generic ToSql visitor (to attempt to get as much coverage as possible for
# DBMSs we don't support).
def arel_visitor
Expand All @@ -12,30 +14,21 @@ def arel_visitor

def self.quote_column_name(name)
name = name.to_s
quote_char = identifier_quote_char.to_s.strip
quote_char = IDENTIFIER_QUOTE_CHAR.to_s.strip

return name if quote_char.length.zero?
quote_char = quote_char[0]

# Avoid quoting any already quoted name
return name if name[0] == quote_char && name[-1] == quote_char

# If upcase identifiers, only quote mixed case names.
if upcase_identifiers?
return name unless name =~ /([A-Z]+[a-z])|([a-z]+[A-Z])/
end
# Only quote mixed case names since identifiers are upcase.
# This may cause issues with DBs that don't use upcase identifiers
return name unless name =~ /([A-Z]+[a-z])|([a-z]+[A-Z])/

"#{quote_char.chr}#{name}#{quote_char.chr}"
end

def self.identifier_quote_char
"\""
end

def self.upcase_identifiers?
true
end

# Explicitly turning off prepared_statements in the null adapter because
# there isn't really a standard on which substitution character to use.
def prepared_statements
Expand Down

0 comments on commit 4a8430e

Please sign in to comment.