Module: Ronin::Code::SQL::Emittable

Included in:
BinaryExpr, Clause, Field, Function, InjectionExpr, Literal, Statement, StatementList, UnaryExpr
Defined in:
lib/ronin/code/sql/emittable.rb

Overview

Allows an object to be converted to raw SQL.

Instance Method Summary collapse

Instance Method Details

#emitter(**kwargs) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Creates a new emitter.

Parameters:



40
41
42
# File 'lib/ronin/code/sql/emittable.rb', line 40

def emitter(**kwargs)
  Emitter.new(**kwargs)
end

#inspect ⇒ String

Inspects the object.

Returns:

  • (String) —

    The inspected object.



89
90
91
# File 'lib/ronin/code/sql/emittable.rb', line 89

def inspect
  "#<#{self.class}: #{to_sql}>"
end

#to_s ⇒ Object

See Also:



79
80
81
# File 'lib/ronin/code/sql/emittable.rb', line 79

def to_s
  to_sql
end

#to_sql(**kwargs) ⇒ String

The default to_sql method.

Parameters:

Options Hash (**kwargs):

  • :case (:lower, :upper, :random, nil) —

    Case for keywords.

  • :space (String) — default: ' ' —

    String to use for white-space.

  • :quotes (:single, :double) — default: :single —

    Type of quotes to use for Strings.

  • :syntax (nil, :mysql, :postgres, :oracle, :mssql) —

    Specific SQL syntax to use.

  • :comment (nil, String) —

    Optional String to use as the SQL comment when terminating injection string

Returns:

  • (String) —

    The raw SQL.

Raises:

  • (ArgumentError) —

    Could not emit an unknown SQL object.



72
73
74
# File 'lib/ronin/code/sql/emittable.rb', line 72

def to_sql(**kwargs)
  emitter(**kwargs).emit(self)
end