module ActiveRecord::QueryLogs

def call(sql) # :nodoc:

:nodoc:
def call(sql) # :nodoc:
  if prepend_comment
    "#{self.comment} #{sql}"
  else
    "#{sql} #{self.comment}"
  end.strip
end

def clear_cache # :nodoc:

:nodoc:
def clear_cache # :nodoc:
  self.cached_comment = nil
end

def comment

Sets and returns a cached comment if cache_query_log_tags is +true+.
Returns an SQL comment +String+ containing the query log tags.
def comment
  if cache_query_log_tags
    self.cached_comment ||= uncached_comment
  else
    uncached_comment
  end
end

def escape_sql_comment(content)

def escape_sql_comment(content)
  # Sanitize a string to appear within a SQL comment
  # For compatibility, this also surrounding "/*+", "/*", and "*/"
  # charcacters, possibly with single surrounding space.
  # Then follows that by replacing any internal "*/" or "/ *" with
  # "* /" or "/ *"
  comment = content.to_s.dup
  comment.gsub!(%r{\A\s*/\*\+?\s?|\s?\*/\s*\Z}, "")
  comment.gsub!("*/", "* /")
  comment.gsub!("/*", "/ *")
  comment
end

def tag_content

def tag_content
  context = ActiveSupport::ExecutionContext.to_h
  tags.flat_map { |i| [*i] }.filter_map do |tag|
    key, handler = tag
    handler ||= taggings[key]
    val = if handler.nil?
      context[key]
    elsif handler.respond_to?(:call)
      if handler.arity == 0
        handler.call
      else
        handler.call(context)
      end
    else
      handler
    end
    "#{key}:#{val}" unless val.nil?
  end.join(",")
end

def uncached_comment

def uncached_comment
  content = tag_content
  if content.present?
    "/*#{escape_sql_comment(content)}*/"
  end
end