Class: Prick::Build::SqlBatch

Inherits:
BuildBatch show all
Defined in:
lib/prick/builder/batch.rb

Direct Known Subclasses

PSqlBatch

Instance Attribute Summary

Attributes inherited from BuildBatch

#builder, #nodes

Instance Method Summary collapse

Methods inherited from BuildBatch

#dump, #initialize, #kind

Methods included from Timer

file, file=, new, off!, off?, on!, on?, scale, scale=, #time, time, unit, unit=

Constructor Details

This class inherits a constructor from Prick::Build::BuildBatch

Instance Method Details

#executeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/prick/builder/batch.rb', line 35

def execute
#       puts "#execute"
  super {
    file = nil
    node = nil

    begin
      # A SQL batch allows the first node to be an evaluated or executed node
      if nodes.first.is_a?(ExecutableNode)
        node = nodes.shift
        conn.execute [node.source], silent: true
      end
    rescue PG::Error => ex
      error, line, char = conn.err
      raise PostgresError.new("Error from #{node.to_s} at #{line}:#{char} - #{error}")
    end

    begin
      execute_nodes
    rescue PG::Error => ex
      error, line, char = conn.err
      file = nil
      if line
        # Locate error node and make line number relative
        if line < nodes.first.lines
          node = nodes.first
        else
          line -= nodes.first.lines
          node = nodes[1..-1].find { |node|
            line -= 1
            if line < node.lines
              line -= 2
              true
            else
              line -= node.lines
              false
            end
          }
        end
#             file = node.path
      end

      if node.is_a?(SqlNode)
        message = ["#{error} in #{node.path}", line, char].compact.join(":")
      elsif node
        message = "#{error} from #{node.path}"
      else
        message = "Error in #{nodes.first.path}: #{conn.errmsg}"
      end
      raise PostgresError.new(message, file, line, char)
    end
  }
end