class SQL::QueryMaker
Constants
- FNOP
Attributes
as_sql[RW]
bind[RW]
column[RW]
Public Class Methods
_compile_builder(expr)
click to toggle source
# File lib/sql/query_maker.rb, line 171 def _compile_builder(expr) # substitute the column character expr = "@ #{expr}" if expr !~ /@/ num_args = expr.count('?') exprs = expr.split(/@/, -1) builder = Proc.new {|quoted_column| exprs.join(quoted_column) } return [num_args, builder] end
_sql_op(fn, builder, column, bind)
click to toggle source
# File lib/sql/query_maker.rb, line 157 def _sql_op(fn, builder, column, bind) return SQL::QueryMaker.new(column, Proc.new {|column, quote_cb| croak("no column binding for fn(bind...)") unless column term = builder.call(quote_cb.call(column)) }, bind) end
new(column, as_sql, bind)
click to toggle source
# File lib/sql/query_maker.rb, line 184 def initialize(column, as_sql, bind) bind = bind.nil? ? [] : array_wrap(bind) bind.each do |b| croak("cannot bind an array or an hash") if b.is_a?(Array) or b.is_a?(Hash) end @column = column @as_sql = as_sql @bind = bind end
sql_op(*args)
click to toggle source
sql_op
(‘IN (SELECT foo_id FROM bar WHERE t=?)’, [44]) sql_op
(‘foo’,‘IN (SELECT foo_id FROM bar WHERE t=?)’, [44])
# File lib/sql/query_maker.rb, line 150 def sql_op(*args) column, expr, bind = (args.size >= 3 ? args : [nil] + args) (num_bind, builder) = _compile_builder(expr) croak("the operator expects num_bind but got #{bind.size}") if num_bind != bind.size return _sql_op("sql_op", builder, column, bind) end
Public Instance Methods
bind_column(column = nil)
click to toggle source
# File lib/sql/query_maker.rb, line 194 def bind_column(column = nil) if column croak('cannot rebind column for \`' + self.column + "` to: `column`") if self.column end @column = column end
quote_identifier(label)
click to toggle source
# File lib/sql/query_maker.rb, line 207 def quote_identifier(label) label.to_s.split(/\./).map {|e| "`#{e}`"}.join('.') end