Sha256: 301afd0942dd628b8149ee393b7c890aa62bb0784b6498cba5f7cfcb0b526bc7

Contents?: true

Size: 1.76 KB

Versions: 35

Compression:

Stored size: 1.76 KB

Contents

# frozen_string_literal: true

module ActiveRecord
  module ConnectionAdapters
    module MySQL
      module Quoting # :nodoc:
        def quote_column_name(name)
          self.class.quoted_column_names[name] ||= "`#{super.gsub('`', '``')}`"
        end

        def quote_table_name(name)
          self.class.quoted_table_names[name] ||= super.gsub(".", "`.`").freeze
        end

        def unquoted_true
          1
        end

        def unquoted_false
          0
        end

        def quoted_date(value)
          if supports_datetime_with_precision?
            super
          else
            super.sub(/\.\d{6}\z/, "")
          end
        end

        def quoted_binary(value)
          "x'#{value.hex}'"
        end

        def column_name_matcher
          COLUMN_NAME
        end

        def column_name_with_order_matcher
          COLUMN_NAME_WITH_ORDER
        end

        COLUMN_NAME = /
          \A
          (
            (?:
              # `table_name`.`column_name` | function(one or no argument)
              ((?:\w+\.|`\w+`\.)?(?:\w+|`\w+`)) | \w+\((?:|\g<2>)\)
            )
            (?:\s+AS\s+(?:\w+|`\w+`))?
          )
          (?:\s*,\s*\g<1>)*
          \z
        /ix

        COLUMN_NAME_WITH_ORDER = /
          \A
          (
            (?:
              # `table_name`.`column_name` | function(one or no argument)
              ((?:\w+\.|`\w+`\.)?(?:\w+|`\w+`)) | \w+\((?:|\g<2>)\)
            )
            (?:\s+ASC|\s+DESC)?
          )
          (?:\s*,\s*\g<1>)*
          \z
        /ix

        private_constant :COLUMN_NAME, :COLUMN_NAME_WITH_ORDER

        private
          def _type_cast(value)
            case value
            when Date, Time then value
            else super
            end
          end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 4 rubygems

Version Path
activerecord-6.0.6.1 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.6 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.5.1 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.5 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4.8 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4.7 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4.6 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4.5 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4.4 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4.3 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4.2 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4.1 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.4 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.3.7 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.3.6 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.3.5 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.3.4 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.3.3 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.3.2 lib/active_record/connection_adapters/mysql/quoting.rb
activerecord-6.0.3.1 lib/active_record/connection_adapters/mysql/quoting.rb