Class: SQLConstructor::BasicSelect

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

Overview

Internal class which represents a basic SELECT statement.

Direct Known Subclasses

BasicSelect_example, BasicSelect_mysql

Constant Summary collapse

METHODS =

Hash - list of available class meta-methods, which would be processed by .method_missing() to set the appropriate object’s attributes (as defined in the METHODS hash itself). The keys of the hash are the methods names (symbols), the values are instances of the QAttr class.

{
    :where => QAttr.new( :name => 'attr_where', :text => 'WHERE', :val => SQLConditional ),
    :from  => QAttr.new( :name => 'attr_from',  :text => 'FROM',  :val => SQLAliasedList ),
    :all         => QAttr.new( :name => 'attr_distinction', :text => 'ALL'         ),
    :distinct    => QAttr.new( :name => 'attr_distinction', :text => 'DISTINCT'    ),
    :distinctrow => QAttr.new( :name => 'attr_distinction', :text => 'DISTINCTROW' ),
    :having => QAttr.new( :name => 'attr_having', :text => 'HAVING', :val => SQLConditional ),
    :group_by => QAttr.new( :name => 'attr_group_by', :text => 'GROUP BY', :val => SQLObject),
    :group_by_asc   => QAttr.new( :name => 'attr_group_by_order', :text => 'ASC'  ),
    :group_by_desc  => QAttr.new( :name => 'attr_group_by_order', :text => 'DESC' ),
    :union          => QAttr.new( 
                        :name     => 'attr_unions',   
                        :text     => 'UNION',
                        :val_type => 'list',
                        :no_commas => true,
                        :val      => SQLConstructor::BasicUnion
                       ),
    :union_all      => QAttr.new(
                        :name     => 'attr_unions',
                        :text     => 'UNION_ALL',
                        :val_type => 'list',
                        :no_commas => true,
                        :val      => SQLConstructor::BasicUnion
                       ),
    :union_distinct => QAttr.new(
                        :name     => 'attr_unions',   
                        :text     => 'UNION_DISTINCT', 
                        :val_type => 'list',
                        :no_commas => true,
                        :val      => SQLConstructor::BasicUnion
                       ),
    :join => SQLConstructor::QAttr.new( :name => "attr_joins", :text => "JOIN", 
                                        :val => SQLConstructor::BasicJoin, 
                                        :val_type => 'list' ),
    :first    => QAttr.new( :name => 'attr_first', :text => 'FIRST', :val => SQLObject ),
    :skip     => QAttr.new( :name => 'attr_skip',  :text => 'SKIP',  :val => SQLObject ),
    :order_by => QAttr.new( :name => 'attr_order_by', :text => 'ORDER BY', :val => SQLObject ),
    :order_by_asc  => QAttr.new( :name => 'attr_order_by_order', :text => 'ASC' ),
    :order_by_desc => QAttr.new( :name => 'attr_order_by_order', :text => 'DESC' )
}

Instance Attribute Summary collapse

Attributes inherited from GenericQuery

#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_s, #to_str

Methods inherited from SQLObject

#_name, #_string, #_string=, get, #to_s

Constructor Details

#initialize(_caller, *list) ⇒ BasicSelect

Class constructor.

_caller     - the caller object
*list       - list of sources for the FROM clause


587
588
589
590
591
592
593
594
# File 'lib/sqlconstructor.rb', line 587

def initialize ( _caller, *list )
    super _caller
    @attr_expression = QAttr.new(
                        :name => 'attr_expression',
                        :text => '',
                        :val  => SQLAliasedList.new( *list )
                      )
end

Dynamic Method Handling

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

Instance Attribute Details

#attr_distinctionObject

Returns the value of attribute attr_distinction.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_distinction
  @attr_distinction
end

#attr_expressionObject

Returns the value of attribute attr_expression.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_expression
  @attr_expression
end

#attr_firstObject

Returns the value of attribute attr_first.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_first
  @attr_first
end

#attr_fromObject

Returns the value of attribute attr_from.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_from
  @attr_from
end

#attr_group_byObject

Returns the value of attribute attr_group_by.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_group_by
  @attr_group_by
end

#attr_group_by_orderObject

Returns the value of attribute attr_group_by_order.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_group_by_order
  @attr_group_by_order
end

#attr_havingObject

Returns the value of attribute attr_having.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_having
  @attr_having
end

#attr_index_hintsObject

Returns the value of attribute attr_index_hints.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_index_hints
  @attr_index_hints
end

#attr_joinsObject

Returns the value of attribute attr_joins.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_joins
  @attr_joins
end

#attr_order_byObject

Returns the value of attribute attr_order_by.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_order_by
  @attr_order_by
end

#attr_order_by_orderObject

Returns the value of attribute attr_order_by_order.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_order_by_order
  @attr_order_by_order
end

#attr_skipObject

Returns the value of attribute attr_skip.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_skip
  @attr_skip
end

#attr_unionsObject

Returns the value of attribute attr_unions.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_unions
  @attr_unions
end

#attr_whereObject

Returns the value of attribute attr_where.



533
534
535
# File 'lib/sqlconstructor.rb', line 533

def attr_where
  @attr_where
end

Instance Method Details

#select_more(*list) ⇒ Object

Add more objects to SELECT expression list ( @attr_expression )



599
600
601
# File 'lib/sqlconstructor.rb', line 599

def select_more ( *list )
    @attr_expression.val.push *list
end