/** * {@inheritdoc} * * @param bool $quoted Quote name. */ public function getName($quoted = false) { if (!$quoted) { return parent::getName(); } return $this->driver->identifier(parent::getName()); }
/** * Query query identifier, if identified stated as table - table prefix must be added. * * @param string $key Identifier can include simple column operations and functions, * having "." in it will automatically force table prefix to first * value. * @param bool $table Set to true to let quote method know that identified is related * to table name. * @param bool $forceTable In some cases we have to force prefix. * @return mixed|string */ public function quote($key, $table = false, $forceTable = false) { if ($key instanceof SQLExpression) { return $key->sqlStatement($this); } elseif ($key instanceof SQLFragmentInterface) { return $key->sqlStatement(); } if (preg_match('/ as /i', $key, $matches)) { list($key, $alias) = explode($matches[0], $key); /** * We can't do looped aliases, so let's force table prefix for identifier if we aliasing * table name at this moment. */ $quoted = $this->quote($key, $table, $table) . $matches[0] . $this->driver->identifier($alias); if ($table && strpos($key, '.') === false) { //We have to apply operation post factum to prevent self aliasing (name AS name //when db has prefix, expected: prefix_name as name) $this->aliases[$alias] = $key; } return $quoted; } if (strpos($key, '(') || strpos($key, ' ')) { return preg_replace_callback('/([a-z][0-9_a-z\\.]*\\(?)/i', function ($identifier) use(&$table) { $identifier = $identifier[1]; if (substr($identifier, -1) == '(') { //Function name return $identifier; } if ($table) { $table = false; //Only first table has to be escaped return $this->quote($identifier, true); } return $this->quote($identifier); }, $key); } if (strpos($key, '.') === false) { if ($table && !isset($this->aliases[$key]) || $forceTable) { if (!isset($this->aliases[$this->tablePrefix . $key])) { $this->aliases[$this->tablePrefix . $key] = $key; } $key = $this->tablePrefix . $key; } return $this->driver->identifier($key); } $key = explode('.', $key); //Expecting first element be table name if (!isset($this->aliases[$key[0]])) { $key[0] = $this->tablePrefix . $key[0]; } //No aliases can be collected there $key = array_map([$this->driver, 'identifier'], $key); return join('.', $key); }
/** * Drop column constraint using it's name. * * @param string $constraint */ protected function doConstraintDrop($constraint) { $this->driver->statement("ALTER TABLE {$this->getName(true)} DROP CONSTRAINT " . $this->driver->identifier($constraint)); }
/** * Quote identifier. * * @param string $identifier * @return string */ protected function quote($identifier) { return $this->driver->identifier($identifier); }