Module: TingYun::Instrumentation::Support::Database

Extended by:
Database
Included in:
Database
Defined in:
lib/ting_yun/instrumentation/support/database.rb

Constant Summary collapse

KNOWN_OPERATIONS =
[
    'SELECT',
    'UPDATE',
    'DELETE',
    'INSERT',
    'SHOW',
    'CALL',
    'PRAGMA'
]
SQL_COMMENT_REGEX =
Regexp.new('/\*.*?\*/', Regexp::MULTILINE).freeze
EMPTY_STRING =
''.freeze

Instance Method Summary collapse

Instance Method Details

#parse_operation_from_query(sql) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ting_yun/instrumentation/support/database.rb', line 24

def parse_operation_from_query(sql)
  sql =TingYun::Helper.correctly_encoded(sql).gsub(SQL_COMMENT_REGEX, EMPTY_STRING)
  if sql =~ /(\w+)/
    op = $1.upcase
    if KNOWN_OPERATIONS.include?(op)
      return op
    else
      return "CALL"
    end
  end
end