Module: Ronin::SQL::Clauses

Included in:
Injection, Statement
Defined in:
lib/ronin/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)


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

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.



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

def clauses
  @clauses ||= []
end

#default_valuesself

Appends a DEFAULT VALUES clause.

Returns:

  • (self)


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

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)


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

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)


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

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)


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

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

#having(&block) ⇒ self

Appends a HAVING clause.

Returns:

  • (self)


203
204
205
# File 'lib/ronin/sql/clauses.rb', line 203

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)


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

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)


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

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

#into(table) ⇒ self

Appends a INTO clause.

Parameters:

  • table (Field, Symbol)

    The table to insert/replace into.

Returns:

  • (self)


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

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)


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

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)


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

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)


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

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

#not_indexedself

Appends a NOT INDEXED clause.

Returns:

  • (self)


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

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)


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

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

#on(&block) ⇒ self

Appends a ON clause.

Returns:

  • (self)


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

def on(&block)
  clause(:ON,&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)


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

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)


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

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)


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

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

#union(&block) ⇒ self

Appends a UNION clause.

Returns:

  • (self)


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

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

#union_all(&block) ⇒ self

Appends a UNION ALL clause.

Returns:

  • (self)

Since:

  • 1.1.0



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

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)


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

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

#where(&block) ⇒ self

Appends a WHERE clause.

Returns:

  • (self)


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

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