Module: StackDeck::Frame::Postgres

Defined in:
lib/stackdeck/postgres.rb

Defined Under Namespace

Classes: Function

Class Method Summary collapse

Class Method Details

.extract(ex) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stackdeck/postgres.rb', line 41

def self.extract(ex)
  postgres_stack = []
  if ex.internal_query
    postgres_stack << Frame::SQL.from_char(ex.internal_query, ex.internal_position)
  end
  if ex.context
    postgres_stack.concat ex.context.split(/\n/).map {|s| parse(s) }
  end
  if ex.query
    postgres_stack << Frame::SQL.from_char(ex.query, ex.query_position)
  end
end

.parse(str, conn = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/stackdeck/postgres.rb', line 54

def self.parse(str, conn=nil)
  if str =~ /([^"]+) "(.*)"(?: line (\d+))?(?: (at [^"]+))?$/
    case $1
    when 'SQL statement'
      Frame::SQL.new($2)
    else
      f = $1.empty? ? nil : $1
      self::Function.new(conn, f, $2, $3.to_i, $4)
    end
  end
end