Module: Ronin::Code::SQL::Clauses

Included in:
Injection, Statement
Defined in:
lib/ronin/code/sql/clauses.rb

Overview

Methods for creating common SQL Clauses.

Instance Method Summary collapse

Instance Method Details

#clause(keyword, argument = nil) {|(clause)| ... } ⇒ self

Appends an arbitrary clause.

Parameters:

  • keyword (Symbol)

    The name of the clause.

  • argument (Object) (defaults to: nil)

    Additional argument for the clause.

Yields:

  • ((clause))

    If a block is given, the return value will be used as the argument.

Yield Parameters:

  • clause (Clause)

    If the block accepts an argument, it will be passed the new clause. Otherwise the block will be evaluated within the clause.

Returns:

  • (self)


58
59
60
61
# File 'lib/ronin/code/sql/clauses.rb', line 58

def clause(keyword,argument=nil,&block)
  clauses << Clause.new(keyword,argument,&block)
  return self
end

#clausesArray<Clause>

The defined clauses of the statement.

Returns:

  • (Array<Clause>)

    The clauses defined thus far.



36
37
38
# File 'lib/ronin/code/sql/clauses.rb', line 36

def clauses
  @clauses ||= []
end

#default_valuesself

Appends a DEFAULT VALUES clause.

Returns:

  • (self)


273
274
275
# File 'lib/ronin/code/sql/clauses.rb', line 273

def default_values
  clause([:DEFAULT, :VALUES])
end

#from(table = nil, &block) ⇒ self

Appends a FROM clause.

Parameters:

  • table (Field, Symbol) (defaults to: nil)

    The table to select from.

Returns:

  • (self)


71
72
73
# File 'lib/ronin/code/sql/clauses.rb', line 71

def from(table=nil,&block)
  clause(:FROM,table,&block)
end

#full_join(table = nil, &block) ⇒ self

Appends a FULL JOIN clause.

Parameters:

  • table (Field, Symbol) (defaults to: nil)

    The table to join.

Returns:

  • (self)


152
153
154
# File 'lib/ronin/code/sql/clauses.rb', line 152

def full_join(table=nil,&block)
  clause([:FULL, :JOIN],table,&block)
end

#group_by(*columns, &block) ⇒ self

Appends a GROUP BY clause.

Parameters:

  • columns (Array<Field, Symbol>)

    The columns for GROUP BY.

Returns:

  • (self)


193
194
195
# File 'lib/ronin/code/sql/clauses.rb', line 193

def group_by(*columns,&block)
  clause([:GROUP, :BY],columns,&block)
end

#having(&block) ⇒ self

Appends a HAVING clause.

Returns:

  • (self)


216
217
218
# File 'lib/ronin/code/sql/clauses.rb', line 216

def having(&block)
  clause(:HAVING,&block)
end

#indexed_by(name, &block) ⇒ self

Appends a INDEXED BY clause.

Parameters:

  • name (Field, Symbol)

    The name of the index.

Returns:

  • (self)


297
298
299
# File 'lib/ronin/code/sql/clauses.rb', line 297

def indexed_by(name,&block)
  clause([:INDEXED, :BY],name,&block)
end

#inner_join(table = nil, &block) ⇒ self

Appends a INNER JOIN clause.

Parameters:

  • table (Field, Symbol) (defaults to: nil)

    The table to join.

Returns:

  • (self)


116
117
118
# File 'lib/ronin/code/sql/clauses.rb', line 116

def inner_join(table=nil,&block)
  clause([:INNER, :JOIN],table,&block)
end

#into(table = nil, &block) ⇒ self

Appends an INTO clause.

Parameters:

  • table (Field, Symbol, nil) (defaults to: nil)

    The table to insert into.

Returns:

  • (self)


83
84
85
# File 'lib/ronin/code/sql/clauses.rb', line 83

def into(table=nil,&block)
  clause(:INTO,table,&block)
end

#join(table = nil, &block) ⇒ self

Appends a JOIN clause.

Parameters:

  • table (Field, Symbol) (defaults to: nil)

    The table to join.

Returns:

  • (self)


104
105
106
# File 'lib/ronin/code/sql/clauses.rb', line 104

def join(table=nil,&block)
  clause(:JOIN,table,&block)
end

#left_join(table = nil, &block) ⇒ self

Appends a LEFT JOIN clause.

Parameters:

  • table (Field, Symbol) (defaults to: nil)

    The table to join.

Returns:

  • (self)


128
129
130
# File 'lib/ronin/code/sql/clauses.rb', line 128

def left_join(table=nil,&block)
  clause([:LEFT, :JOIN],table,&block)
end

#limit(value, &block) ⇒ self

Appends a LIMIT clause.

Parameters:

  • value (Integer)

    The maximum number of rows to select.

Returns:

  • (self)


228
229
230
# File 'lib/ronin/code/sql/clauses.rb', line 228

def limit(value,&block)
  clause(:LIMIT,value,&block)
end

#not_indexedself

Appends a NOT INDEXED clause.

Returns:

  • (self)


306
307
308
# File 'lib/ronin/code/sql/clauses.rb', line 306

def not_indexed
  clause([:NOT, :INDEXED])
end

#offset(value, &block) ⇒ self

Appends a OFFSET clause.

Parameters:

  • value (Integer)

    The index to start selecting at within the result set.

Returns:

  • (self)


240
241
242
# File 'lib/ronin/code/sql/clauses.rb', line 240

def offset(value,&block)
  clause(:OFFSET,value,&block)
end

#on(&block) ⇒ self

Appends a ON clause.

Returns:

  • (self)


161
162
163
# File 'lib/ronin/code/sql/clauses.rb', line 161

def on(&block)
  clause(:ON,&block)
end

#order_by(*columns, &block) ⇒ self

Appends a ORDER BY clause.

Parameters:

  • columns (Array<Field, Symbol>)

    The columns for ORDER BY.

Returns:

  • (self)

Since:

  • 2.1.0



207
208
209
# File 'lib/ronin/code/sql/clauses.rb', line 207

def order_by(*columns,&block)
  clause([:ORDER, :BY],columns,&block)
end

#right_join(table = nil, &block) ⇒ self

Appends a RIGHT JOIN clause.

Parameters:

  • table (Field, Symbol) (defaults to: nil)

    The table to join.

Returns:

  • (self)


140
141
142
# File 'lib/ronin/code/sql/clauses.rb', line 140

def right_join(table=nil,&block)
  clause([:RIGHT, :JOIN],table,&block)
end

#set(values = {}) ⇒ self

Appends a SET clause.

Parameters:

  • values (Hash{Field,Symbol => Object}) (defaults to: {})

    The columns and values to update.

Returns:

  • (self)


285
286
287
# File 'lib/ronin/code/sql/clauses.rb', line 285

def set(values={})
  clause(:SET,values)
end

#top(value, &block) ⇒ self

Appends a TOP clause.

Parameters:

  • value (Integer)

    The number of top rows to select.

Returns:

  • (self)


252
253
254
# File 'lib/ronin/code/sql/clauses.rb', line 252

def top(value,&block)
  clause(:TOP,value,&block)
end

#union(&block) ⇒ self

Appends a UNION clause.

Returns:

  • (self)


170
171
172
# File 'lib/ronin/code/sql/clauses.rb', line 170

def union(&block)
  clause(:UNION,&block)
end

#union_all(&block) ⇒ self

Appends a UNION ALL clause.

Returns:

  • (self)

Since:

  • 1.1.0



181
182
183
# File 'lib/ronin/code/sql/clauses.rb', line 181

def union_all(&block)
  clause([:UNION, :ALL],&block)
end

#values(*values) ⇒ self

Appends a VALUES clause.

Parameters:

  • values (Array)

    The values to insert.

Returns:

  • (self)


264
265
266
# File 'lib/ronin/code/sql/clauses.rb', line 264

def values(*values)
  clause(:VALUES,values)
end

#where(&block) ⇒ self

Appends a WHERE clause.

Returns:

  • (self)


92
93
94
# File 'lib/ronin/code/sql/clauses.rb', line 92

def where(&block)
  clause(:WHERE,&block)
end