Class: SQLConstructor::BasicJoin

Inherits:
GenericQuery show all
Defined in:
lib/sqlconstructor.rb

Overview

Internal class which represents a basic JOIN statement.

Direct Known Subclasses

BasicJoin_mysql

Constant Summary collapse

METHODS =
{
    :on    => QAttr.new( :name => 'join_on',    :text => 'ON',    :val => SQLConditional ),
    :using => QAttr.new( :name => 'join_using', :text => 'USING', :val => SQLObject      ),
}

Instance Attribute Summary collapse

Attributes inherited from GenericQuery

#attr_index_hints, #caller, #child_caller, #dialect, #exporter, #string, #tidy, #type

Attributes inherited from SQLObject

#alias, #inline, #name, #separator

Instance Method Summary collapse

Methods inherited from GenericQuery

#_get, #_remove, #method_missing, #to_str

Methods inherited from SQLObject

#_name, #_string, #_string=, get

Constructor Details

#initialize(_caller, type, *sources) ⇒ BasicJoin

Class contructor. Takes a caller object as the first argument, JOIN

type as the second argument, and a list of sources for the JOIN clause


446
447
448
449
450
451
452
# File 'lib/sqlconstructor.rb', line 446

def initialize ( _caller, type, *sources )
    type = type.to_s
    type.upcase!.gsub! /_/, ' '
    super _caller
    @type = type
    @join_sources = SQLAliasedList.new *sources
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SQLConstructor::GenericQuery

Instance Attribute Details

#join_onObject

Returns the value of attribute join_on.



435
436
437
# File 'lib/sqlconstructor.rb', line 435

def join_on
  @join_on
end

#join_sourcesObject

Returns the value of attribute join_sources.



435
436
437
# File 'lib/sqlconstructor.rb', line 435

def join_sources
  @join_sources
end

#join_usingObject

Returns the value of attribute join_using.



435
436
437
# File 'lib/sqlconstructor.rb', line 435

def join_using
  @join_using
end

Instance Method Details

#join_more(*sources) ⇒ Object

Adds more sources to @join_sources list



457
458
459
# File 'lib/sqlconstructor.rb', line 457

def join_more ( *sources )
    @join_sources.push *sources
end

#to_sObject

Export to string with sources aliases



464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/sqlconstructor.rb', line 464

def to_s
    return @string  if @string
    result  = @type + " "
    arr = [ ]
    @join_sources.each do |src|
        _alias = src.alias ? " " + src.alias.to_s : ""
        str = src.to_s + _alias
        arr << str
    end
    result += arr.join ','
    result += @exporter.separator
    result += "ON " + @join_on.val.to_s  if @join_on
    @string = result
end