Class: Ronin::Code::SQL::InjectedStatement

Inherits:
Statement show all
Defined in:
lib/ronin/code/sql/injected_statement.rb

Instance Attribute Summary collapse

Attributes inherited from Statement

#clauses

Instance Method Summary collapse

Methods inherited from Statement

clause_order, clauses, #get_clause, #has_clause?, has_clause?

Methods inherited from Expr

#===, #in?, #not_in?

Constructor Details

#initialize(dialect, &block) ⇒ InjectedStatement

Returns a new instance of InjectedStatement.



32
33
34
35
36
# File 'lib/ronin/code/sql/injected_statement.rb', line 32

def initialize(dialect,&block)
  @expressions = []

  super(dialect,&block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object (protected)



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

def method_missing(name,*arguments,&block)
  if (@dialect.has_clause?(name) && block.nil?)
    return @dialect.clause(name,*arguments)
  end

  return super(name,*arguments,&block)
end

Instance Attribute Details

#expressionsObject (readonly)

Injected expressions



30
31
32
# File 'lib/ronin/code/sql/injected_statement.rb', line 30

def expressions
  @expressions
end

Instance Method Details

#all_rows(value = 1) ⇒ Object



48
49
50
# File 'lib/ronin/code/sql/injected_statement.rb', line 48

def all_rows(value=1)
  inject_or(BinaryExpr.new('=',value,value))
end

#emitObject



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

def emit
  emit_values(@expressions) + super
end

#exact_rows(value = 1) ⇒ Object



52
53
54
# File 'lib/ronin/code/sql/injected_statement.rb', line 52

def exact_rows(value=1)
  inject_and(BinaryExpr.new('=',value,value))
end

#has_column?(name) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/ronin/code/sql/injected_statement.rb', line 60

def has_column?(name)
  inject_or(field(name).is_not?(null))
end

#has_table?(table) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/ronin/code/sql/injected_statement.rb', line 64

def has_table?(table)
  inject_and(select(:from => table,:fields => count(all)) == 1)
end

#inject_and(expr) ⇒ Object



38
39
40
41
# File 'lib/ronin/code/sql/injected_statement.rb', line 38

def inject_and(expr)
  @expressions += [Token.new('AND'), expr]
  return self
end

#inject_or(expr) ⇒ Object



43
44
45
46
# File 'lib/ronin/code/sql/injected_statement.rb', line 43

def inject_or(expr)
  @expressions += [Token.new('OR'), expr]
  return self
end

#no_rowsObject



56
57
58
# File 'lib/ronin/code/sql/injected_statement.rb', line 56

def no_rows
  inject_and(BinaryExpr.new('=',1,0))
end

#uses_column?(name) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
72
73
# File 'lib/ronin/code/sql/injected_statement.rb', line 68

def uses_column?(name)
  group_by(name)

  having(BinaryExpr.new('=',1,1))
  return self
end

#uses_table?(table) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/ronin/code/sql/injected_statement.rb', line 75

def uses_table?(table)
  inject_or(table.is_not?(null))
end