public function getSql(Column $column, $table)
 {
     if (!$table instanceof Table) {
         $table = new Identifier($table);
     }
     $sql = array();
     $normalized = $column->getType()->getNormalizedPostGISColumnOptions($column->getCustomSchemaOptions());
     $srid = $normalized['srid'];
     // PostGIS 1.5 uses -1 for undefined SRID's
     if ($srid <= 0) {
         $srid = -1;
     }
     $type = strtoupper($normalized['geometry_type']);
     if ('ZM' === substr($type, -2)) {
         $dimension = 4;
         $type = substr($type, 0, -2);
     } elseif ('M' === substr($type, -1)) {
         $dimension = 3;
     } elseif ('Z' === substr($type, -1)) {
         $dimension = 3;
         $type = substr($type, 0, -1);
     } else {
         $dimension = 2;
     }
     // Geometry columns are created by the AddGeometryColumn stored procedure
     $sql[] = sprintf("SELECT AddGeometryColumn('%s', '%s', %d, '%s', %d)", $table->getName(), $column->getName(), $srid, $type, $dimension);
     if ($column->getNotnull()) {
         // Add a NOT NULL constraint to the field
         $sql[] = sprintf('ALTER TABLE %s ALTER %s SET NOT NULL', $table->getQuotedName($this->platform), $column->getQuotedName($this->platform));
     }
     return $sql;
 }
 /**
  * @param string $table
  * @param string $classAlias
  * @param string $namespaceAlias
  *
  * @return string
  */
 private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n')
 {
     $whereClause = $namespaceAlias . ".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND ";
     if (strpos($table, ".") !== false) {
         list($schema, $table) = explode(".", $table);
         $schema = "'" . $schema . "'";
     } else {
         $schema = "ANY(string_to_array((select replace(replace(setting,'\"\$user\"',user),' ','') from pg_catalog.pg_settings where name = 'search_path'),','))";
     }
     $table = new Identifier($table);
     $whereClause .= "{$classAlias}.relname = '" . $table->getName() . "' AND {$namespaceAlias}.nspname = {$schema}";
     return $whereClause;
 }
 /**
  * Returns a hash value for a given identifier.
  *
  * @param string $identifier Identifier to generate a hash value for.
  *
  * @return string
  */
 private function generateIdentifierName($identifier)
 {
     // Always generate name for unquoted identifiers to ensure consistency.
     $identifier = new Identifier($identifier);
     return strtoupper(dechex(crc32($identifier->getName())));
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  */
 public function getIdentitySequenceName($tableName, $columnName)
 {
     $table = new Identifier($tableName);
     // No usage of column name to preserve BC compatibility with <2.5
     $identitySequenceName = $table->getName() . '_SEQ';
     if ($table->isQuoted()) {
         $identitySequenceName = '"' . $identitySequenceName . '"';
     }
     $identitySequenceIdentifier = $this->normalizeIdentifier($identitySequenceName);
     return $identitySequenceIdentifier->getQuotedName($this);
 }
 /**
  * Returns the non-schema qualified foreign table name.
  *
  * @return string
  */
 public function getUnqualifiedForeignTableName()
 {
     $parts = explode(".", $this->_foreignTableName->getName());
     return strtolower(end($parts));
 }
 /**
  * Returns the SQL statement for stopping a running database.
  *
  * In SQL Anywhere you can start and stop databases on a
  * database server instance.
  * This is a required statement before dropping an existing database
  * as it has to be explicitly stopped before it can be dropped.
  *
  * @param string $database Name of the database to stop.
  *
  * @return string
  */
 public function getStopDatabaseSQL($database)
 {
     $database = new Identifier($database);
     return 'STOP DATABASE "' . $database->getName() . '" UNCONDITIONALLY';
 }
 public function onSchemaAlterTableChangeColumn(SchemaAlterTableChangeColumnEventArgs $args)
 {
     $columnDiff = $args->getColumnDiff();
     $column = $columnDiff->column;
     if (!$this->isSpatialColumnType($column)) {
         return;
     }
     $diff = $args->getTableDiff();
     $table = new Identifier(false !== $diff->newName ? $diff->newName : $diff->name);
     if ($columnDiff->hasChanged('type')) {
         throw new \RuntimeException('The type of a spatial column cannot be changed (Requested changing type from "' . $columnDiff->fromColumn->getType()->getName() . '" to "' . $column->getType()->getName() . '" for column "' . $column->getName() . '" in table "' . $table->getName() . '")');
     }
     if ($columnDiff->hasChanged('geometry_type')) {
         throw new \RuntimeException('The geometry_type of a spatial column cannot be changed (Requested changing type from "' . strtoupper($columnDiff->fromColumn->getCustomSchemaOption('geometry_type')) . '" to "' . strtoupper($column->getCustomSchemaOption('geometry_type')) . '" for column "' . $column->getName() . '" in table "' . $table->getName() . '")');
     }
     if ($columnDiff->hasChanged('srid')) {
         $args->addSql(sprintf("SELECT UpdateGeometrySRID('%s', '%s', %d)", $table->getName(), $column->getName(), $column->getCustomSchemaOption('srid')));
     }
 }