Class: ScoutApm::Utils::SqlSanitizer

Inherits:
Object
  • Object
show all
Includes:
SqlRegex
Defined in:
lib/scout_apm/utils/sql_sanitizer.rb

Constant Summary

Constants included from SqlRegex

ScoutApm::Utils::SqlRegex::MULTIPLE_QUESTIONS, ScoutApm::Utils::SqlRegex::MULTIPLE_SPACES, ScoutApm::Utils::SqlRegex::MYSQL_IN_CLAUSE, ScoutApm::Utils::SqlRegex::MYSQL_REMOVE_DOUBLE_QUOTE_STRINGS, ScoutApm::Utils::SqlRegex::MYSQL_REMOVE_INTEGERS, ScoutApm::Utils::SqlRegex::MYSQL_REMOVE_SINGLE_QUOTE_STRINGS, ScoutApm::Utils::SqlRegex::MYSQL_VAR_INTERPOLATION, ScoutApm::Utils::SqlRegex::PSQL_AFTER_SET, ScoutApm::Utils::SqlRegex::PSQL_AFTER_WHERE, ScoutApm::Utils::SqlRegex::PSQL_IN_CLAUSE, ScoutApm::Utils::SqlRegex::PSQL_PLACEHOLDER, ScoutApm::Utils::SqlRegex::PSQL_REMOVE_INTEGERS, ScoutApm::Utils::SqlRegex::PSQL_REMOVE_STRINGS, ScoutApm::Utils::SqlRegex::PSQL_VAR_INTERPOLATION, ScoutApm::Utils::SqlRegex::SQLITE_REMOVE_INTEGERS, ScoutApm::Utils::SqlRegex::SQLITE_REMOVE_STRINGS, ScoutApm::Utils::SqlRegex::SQLITE_VAR_INTERPOLATION, ScoutApm::Utils::SqlRegex::SQLSERVER_EXECUTESQL, ScoutApm::Utils::SqlRegex::SQLSERVER_IN_CLAUSE, ScoutApm::Utils::SqlRegex::SQLSERVER_REMOVE_INTEGERS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sql) ⇒ SqlSanitizer

Returns a new instance of SqlSanitizer.



17
18
19
20
21
# File 'lib/scout_apm/utils/sql_sanitizer.rb', line 17

def initialize(sql)
  @raw_sql = sql
  @database_engine = ScoutApm::Agent.instance.context.environment.database_engine
  @sanitized = false # only sanitize once.
end

Instance Attribute Details

#database_engineObject

Returns the value of attribute database_engine.



15
16
17
# File 'lib/scout_apm/utils/sql_sanitizer.rb', line 15

def database_engine
  @database_engine
end

Instance Method Details

#sqlObject



23
24
25
# File 'lib/scout_apm/utils/sql_sanitizer.rb', line 23

def sql
  @sql ||= scrubbed(@raw_sql.dup) # don't do this in initialize as it is extra work that isn't needed unless we have a slow transaction.
end

#to_sObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/scout_apm/utils/sql_sanitizer.rb', line 27

def to_s
  if @sanitized
    sql
  else
    @sanitized = true
  end
  case database_engine
  when :postgres then to_s_postgres
  when :mysql    then to_s_mysql
  when :sqlite   then to_s_sqlite
  when :sqlserver then to_s_sqlserver
  end
end