Class: Ronin::Code::SQL::InjectionExpr Private

Inherits:
Object
  • Object
show all
Includes:
Emittable, Fields, Functions, Literals, Statements
Defined in:
lib/ronin/code/sql/injection_expr.rb

Overview

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

Since:

  • 1.1.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Emittable

#emitter, #inspect, #to_s

Methods included from Statements

#delete, #drop_table, #insert, #select, #statement, #update

Methods included from Functions

#abs, #acos, #ascii, #asin, #atan, #atan2, #avg, #bin, #bit_and, #bit_count, #bit_length, #bit_or, #ceil, #ceiling, #char, #char_length, #character_length, #concat, #concat_ws, #conv, #cos, #cot, #count, #degrees, #elt, #exp, #export_set, #field, #find_in_set, #floor, #format, #glob, #greatest, #hex, #insert, #instr, #interval, #lcase, #least, #left, #length, #like, #load_file, #locate, #log, #log10, #lower, #lpad, #ltrim, #make_set, #max, #mid, #min, #mod, #oct, #octet_length, #ord, #pi, #position, #pow, #power, #quote, #radians, #rand, #random, #repeat, #replace, #reverse, #right, #round, #rpad, #rtrim, #sign, #sin, #sleep, #soundex, #space, #sqrt, #std, #stddev, #strcmp, #substring, #substring_index, #sum, #tan, #trim, #truncate, #ucase, #unhex, #upper

Methods included from Fields

#method_missing, #respond_to_missing?, #to_ary

Methods included from Literals

#float, #int, #null, #string

Constructor Details

#initialize(initial_value) ⇒ InjectionExpr

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.

Initializes the new expression to inject.

Parameters:

  • initial_value (String, Integer, Float, Array, Symbol)

    The initial value for the expression.

Since:

  • 1.1.0



53
54
55
# File 'lib/ronin/code/sql/injection_expr.rb', line 53

def initialize(initial_value)
  @expression = initial_value
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ronin::Code::SQL::Fields

Instance Attribute Details

#expressionObject (readonly)

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.

The expression that will be injected

Since:

  • 1.1.0



45
46
47
# File 'lib/ronin/code/sql/injection_expr.rb', line 45

def expression
  @expression
end

Instance Method Details

#and {|(self)| ... } ⇒ self

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.

Appends an AND expression to the injection.

Yields:

  • ((self))

    The return value of the block will be used as the right-hand side operand. If the block accepts an argument, it will be called with the injection expression.

Returns:

  • (self)

Since:

  • 1.1.0



67
68
69
70
71
72
73
74
75
# File 'lib/ronin/code/sql/injection_expr.rb', line 67

def and(&block)
  value = case block.arity
          when 0 then instance_eval(&block)
          else        block.call(self)
          end

  @expression = BinaryExpr.new(@expression,:AND,value)
  return self
end

#or {|(self)| ... } ⇒ self

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.

Appends an OR expression to the injection.

Yields:

  • ((self))

    The return value of the block will be used as the right-hand side operand. If the block accepts an argument, it will be called with the injection expression.

Returns:

  • (self)

Since:

  • 1.1.0



87
88
89
90
91
92
93
94
95
# File 'lib/ronin/code/sql/injection_expr.rb', line 87

def or(&block)
  value = case block.arity
          when 0 then instance_eval(&block)
          else        block.call(self)
          end

  @expression = BinaryExpr.new(@expression,:OR,value)
  return self
end

#to_sql(**kwargs) ⇒ String

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.

Emits the injection expression.

Parameters:

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for Emitter#initialize.

Returns:

  • (String)

    The raw SQL.

Since:

  • 1.1.0



106
107
108
# File 'lib/ronin/code/sql/injection_expr.rb', line 106

def to_sql(**kwargs)
  emitter(**kwargs).emit(@expression)
end