/**
  * Quote an identifier and an optional alias.
  *
  * @param string|array|\libDb\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 \libDb\Expr) {
         $quoted = $ident->__toString();
     } elseif ($ident instanceof 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 \libDb\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;
 }
Esempio n. 2
0
 /**
 * Adds a FROM table and optional columns to the query.
 *
 * The table name can be expressed
 *
 * @param  array|string|\libDb\Expr|AbstractTable $name The table name or an
                                                                  associative array relating
                                                                  table name to correlation
                                                                  name.
 * @param  array|string|\libDb\Expr $cols The columns to select from this table.
 * @param  string $schema The schema name to specify, if any.
 * @return Select This  object.
 */
 public function from($name, $cols = self::SQL_WILDCARD, $schema = null)
 {
     if ($name instanceof AbstractTable) {
         $info = $name->info();
         $name = $info[AbstractTable::NAME];
         if (isset($info[AbstractTable::SCHEMA])) {
             $schema = $info[AbstractTable::SCHEMA];
         }
     }
     return $this->joinInner($name, null, $cols, $schema);
 }