Class: SQLConstructor::BasicJoin_mysql
- Inherits:
-
BasicJoin
- Object
- SQLObject
- GenericQuery
- BasicJoin
- SQLConstructor::BasicJoin_mysql
- Defined in:
- lib/dialects/mysql-constructor.rb
Overview
MySQL dialect descendant of BasicJoin class
Constant Summary collapse
- VALID_JOINS =
[ "join", "inner_join", "cross_join", "left_join", "right_join", "left_outer_join", "right_outer_join", "natural_join", "natural_left_join", "natural_right_join", "natural_left_outer_join", "natural_right_outer_join" ]
Constants inherited from BasicJoin
SQLConstructor::BasicJoin::METHODS
Instance Attribute Summary
Attributes inherited from BasicJoin
#join_on, #join_sources, #join_using
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
-
#_addIndexes(type, *list) ⇒ Object
Adds a USE/FORCE/IGNORE INDEX clause for the last objects in for_vals argument.
-
#initialize(_caller, type, *sources) ⇒ BasicJoin_mysql
constructor
Class contructor.
-
#method_missing(method, *args) ⇒ Object
Handles INDEX hints or sends the call to the parent.
-
#to_s ⇒ Object
Export to string with index hints included.
Methods inherited from BasicJoin
Methods inherited from GenericQuery
Methods inherited from SQLObject
#_name, #_string, #_string=, get
Constructor Details
#initialize(_caller, type, *sources) ⇒ BasicJoin_mysql
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
181 182 183 184 185 186 187 |
# File 'lib/dialects/mysql-constructor.rb', line 181 def initialize ( _caller, type, *sources ) type = type.to_s if ! VALID_JOINS.include? type raise NoMethodError, ERR_UNKNOWN_METHOD + ": " + type end super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Handles INDEX hints or sends the call to the parent
218 219 220 221 222 |
# File 'lib/dialects/mysql-constructor.rb', line 218 def method_missing ( method, *args ) # Handle all valid *_index/*_key calls: return _addIndexes( method, *args ) if VALID_INDEX_HINTS.include? method super end |
Instance Method Details
#_addIndexes(type, *list) ⇒ Object
Adds a USE/FORCE/IGNORE INDEX clause for the last objects in for_vals
argument.
193 194 195 196 197 198 199 200 201 202 |
# File 'lib/dialects/mysql-constructor.rb', line 193 def _addIndexes ( type, *list ) type = type.to_s type.upcase!.gsub! /_/, ' ' @attr_index_hints ||= [ ] # set the attr_index_hints for the last object in for_vals last_ind = @join_sources.length - 1 @attr_index_hints[last_ind] = { :type => type, :list => SQLObject.get( list ) } @string = nil return self end |
#to_s ⇒ Object
Export to string with index hints included
207 208 209 210 211 212 213 |
# File 'lib/dialects/mysql-constructor.rb', line 207 def to_s return @string if @string result = @type + " " + to_sWithAliasesIndexes( @join_sources ) result += @exporter.separator result += "ON " + @join_on.val.to_s if @join_on @string = result end |