From 4a8430ecb5d07b5fb2f037ed845f9fe9052b6f86 Mon Sep 17 00:00:00 2001 From: zjohl Date: Tue, 10 Dec 2024 09:22:32 -0500 Subject: [PATCH] Simplify quoting logic for generic adapter --- .../adapters/null_odbc_adapter.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/odbc_adapter/adapters/null_odbc_adapter.rb b/lib/odbc_adapter/adapters/null_odbc_adapter.rb index 58971a1..b4f1694 100644 --- a/lib/odbc_adapter/adapters/null_odbc_adapter.rb +++ b/lib/odbc_adapter/adapters/null_odbc_adapter.rb @@ -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 @@ -12,7 +14,7 @@ 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] @@ -20,22 +22,13 @@ def self.quote_column_name(name) # 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