Method: PgQuery::ParserResult#param_refs

Defined in:
lib/pg_query/param_refs.rb

#param_refsObject

rubocop:disable Metrics/CyclomaticComplexity



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pg_query/param_refs.rb', line 3

def param_refs # rubocop:disable Metrics/CyclomaticComplexity
  results = []

  treewalker! @tree do |_, _, node, location|
    case node
    when PgQuery::ParamRef
      # Ignore param refs inside type casts, as these are already handled
      next if location[-3..-1] == i[type_cast arg param_ref]

      results << { 'location' => node.location,
                   'length' => param_ref_length(node) }
    when PgQuery::TypeCast
      next unless node.arg && node.type_name

      p = node.arg.param_ref
      t = node.type_name
      next unless p && t

      location = p.location
      typeloc  = t.location
      length   = param_ref_length(p)

      if location == -1
        location = typeloc
      elsif typeloc < location
        length += location - typeloc
        location = typeloc
      end

      results << { 'location' => location, 'length' => length, 'typename' => t.names.map { |n| n.string.sval } }
    end
  end

  results.sort_by! { |r| r['location'] }
  results
end