fuel/fuel/core/classes/database/query/builder/join.php
public function compile($db = null)
	{
		if ( ! $db instanceof \Database_Connection)
		{
			// Get the database instance
			$db = \Database_Connection::instance($db);
		}

		if ($this->_type)
		{
			$sql = strtoupper($this->_type).' JOIN';
		}
		else
		{
			$sql = 'JOIN';
		}

		// Quote the table name that is being joined
		$sql .= ' '.$db->quote_table($this->_table);

		$conditions = array();

		foreach ($this->_on as $condition)
		{
			// Split the condition
			list($c1, $op, $c2, $chaining) = $condition;

			// Add chain type
			$conditions[] = ' '.$chaining.' ';

			if ($op)
			{
				// Make the operator uppercase and spaced
				$op = ' '.strtoupper($op);
			}

			// Quote each of the identifiers used for the condition
			$conditions[] = $db->quote_identifier($c1).$op.' '.(is_null($c2)?'NULL':$db->quote_identifier($c2));
		}

		// remove the first chain type
		array_shift($conditions);

		// if there are conditions, concat the conditions "... AND ..." and glue them on...
		empty($conditions) or $sql .= ' ON ('.implode('', $conditions).')';

		return $sql;
	}
public function compile($db = null)
	{
		if ( ! $db instanceof \Database_Connection)
		{
			// Get the database instance
			$db = \Database_Connection::instance($db);
		}

		if ($this->_type)
		{
			$sql = strtoupper($this->_type).' JOIN';
		}
		else
		{
			$sql = 'JOIN';
		}

		// Quote the table name that is being joined
		$sql .= ' '.$db->quote_table($this->_table);

		$conditions = array();

		foreach ($this->_on as $condition)
		{
			// Split the condition
			list($c1, $op, $c2, $chaining) = $condition;

			// Add chain type
			$conditions[] = ' '.$chaining.' ';

			if ($op)
			{
				// Make the operator uppercase and spaced
				$op = ' '.strtoupper($op);
			}

			// Quote each of the identifiers used for the condition
			$conditions[] = $db->quote_identifier($c1).$op.' '.(is_null($c2)?'NULL':$db->quote_identifier($c2));
		}

		// remove the first chain type
		array_shift($conditions);

		// if there are conditions, concat the conditions "... AND ..." and glue them on...
		empty($conditions) or $sql .= ' ON ('.implode('', $conditions).')';

		return $sql;
	}
public function compile ( $ db = null ) { if ( ! $ db instanceof \ Database_Connection ) { // Get the database instance $ db = \ Database_Connection :: instance ( $ db ) ; } if ( $ this -> _type ) { $ sql = strtoupper ( $ this -> _type ) . ' JOIN' ; } else { $ sql = 'JOIN' ; } // Quote the table name that is being joined $ sql .= ' ' . $ db -> quote_table ( $ this -> _table ) ; $ conditions = array ( ) ; foreach ( $ this -> _on as $ condition ) { // Split the condition list ( $ c1 , $ op , $ c2 , $ chaining ) = $ condition ; // Add chain type $ conditions [ ] = ' ' . $ chaining . ' ' ; if ( $ op ) { // Make the operator uppercase and spaced $ op = ' ' . strtoupper ( $ op ) ; } // Quote each of the identifiers used for the condition $ conditions [ ] = $ db -> quote_identifier ( $ c1 ) . $ op . ' ' . ( is_null ( $ c2 ) ? 'NULL' : $ db -> quote_identifier ( $ c2 ) ) ; } // remove the first chain type array_shift ( $ conditions ) ; // if there are conditions, concat the conditions "... AND ..." and glue them on... empty ( $ conditions ) or $ sql .= ' ON (' . implode ( '' , $ conditions ) . ')' ; return $ sql ; }
Compile the SQL partial for a JOIN statement and return it.

@param   mixed  $db  Database_Connection instance or instance name

@return  string
Compile the SQL partial for a JOIN statement and return it .