Exemplo n.º 1
0
 /**
  * Quote an identifier and an optional alias.
  *
  * @param string|array|JO_Db_Expr $ident The identifier or expression.
  * @param string $alias An optional alias.
  * @param boolean $auto If true, heed the AUTO_QUOTE_IDENTIFIERS config option.
  * @param string $as The string to add between the identifier/expression and the alias.
  * @return string The quoted identifier and alias.
  */
 protected function _quoteIdentifierAs($ident, $alias = null, $auto = false, $as = ' AS ')
 {
     if ($ident instanceof JO_Db_Expr) {
         $quoted = $ident->__toString();
     } elseif ($ident instanceof JO_Db_Select) {
         $quoted = '(' . $ident->assemble() . ')';
     } else {
         if (is_string($ident)) {
             $ident = explode('.', $ident);
         }
         if (is_array($ident)) {
             $segments = array();
             foreach ($ident as $segment) {
                 if ($segment instanceof JO_Db_Expr) {
                     $segments[] = $segment->__toString();
                 } else {
                     $segments[] = $this->_quoteIdentifier($segment, $auto);
                 }
             }
             if ($alias !== null && end($ident) == $alias) {
                 $alias = null;
             }
             $quoted = implode('.', $segments);
         } else {
             $quoted = $this->_quoteIdentifier($ident, $auto);
         }
     }
     if ($alias !== null) {
         $quoted .= $as . $this->_quoteIdentifier($alias, $auto);
     }
     return $quoted;
 }
Exemplo n.º 2
0
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|JO_Db_Expr|JO_Db_Table_Abstract $name The table name or an
                                                                  associative array relating
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|JO_Db_Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return JO_Db_Table_Select This JO_Db_Table_Select object.
 */
 public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
 {
     if ($name instanceof JO_Db_Table_Abstract) {
         $info = $name->info();
         $name = $info[JO_Db_Table_Abstract::NAME];
         if (isset($info[JO_Db_Table_Abstract::SCHEMA])) {
             $schema = $info[JO_Db_Table_Abstract::SCHEMA];
         }
     }
     return $this->joinInner($name, null, $cols, $schema);
 }