method

new

Importance_0
Ruby on Rails latest stable (v7.1.3.2) - 0 notes - Class: BoundSqlLiteral
  • 1.0.0
  • 1.1.6
  • 1.2.6
  • 2.0.3
  • 2.1.0
  • 2.2.1
  • 2.3.8
  • 3.0.0
  • 3.0.9
  • 3.1.0
  • 3.2.1
  • 3.2.8
  • 3.2.13
  • 4.0.2
  • 4.1.8
  • 4.2.1
  • 4.2.7
  • 4.2.9
  • 5.0.0.1
  • 5.1.7
  • 5.2.3
  • 6.0.0
  • 6.1.3.1
  • 6.1.7.7
  • 7.0.0
  • 7.1.3.2 (0)
  • 7.1.3.4 (0)
  • What's this?
new(sql_with_placeholders, positional_binds, named_binds) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/arel/nodes/bound_sql_literal.rb, line 8
      def initialize(sql_with_placeholders, positional_binds, named_binds)
        if !positional_binds.empty? && !named_binds.empty?
          raise BindError.new("cannot mix positional and named binds", sql_with_placeholders)
        elsif !positional_binds.empty?
          if positional_binds.size != (expected = sql_with_placeholders.count("?"))
            raise BindError.new("wrong number of bind variables (#{positional_binds.size} for #{expected})", sql_with_placeholders)
          end
        elsif !named_binds.empty?
          tokens_in_string = sql_with_placeholders.scan(/:(?<!::)([a-zA-Z]\w*)/).flatten.map(&:to_sym).uniq
          tokens_in_hash = named_binds.keys.map(&:to_sym).uniq

          if !(missing = (tokens_in_string - tokens_in_hash)).empty?
            if missing.size == 1
              raise BindError.new("missing value for #{missing.first.inspect}", sql_with_placeholders)
            else
              raise BindError.new("missing values for #{missing.inspect}", sql_with_placeholders)
            end
          end
        end

        @sql_with_placeholders = sql_with_placeholders
        if !positional_binds.empty?
          @positional_binds = positional_binds
          @named_binds = nil
        else
          @positional_binds = nil
          @named_binds = named_binds
        end
      end
Register or log in to add new notes.