public function truncateTableSql(Table $table)
 {
     $tableName = $table->name();
     if ($this->_driver->autoQuoting()) {
         $tableName = $this->_driver->quoteIdentifier($tableName);
     }
     return [sprintf("TRUNCATE TABLE %s", $tableName)];
 }
Beispiel #2
0
 /**
  * Generate the SQL to drop a table.
  *
  * @param \Cake\Database\Schema\Table $table Table instance
  * @return array SQL statements to drop a table.
  */
 public function dropTableSql(Table $table)
 {
     $sql = sprintf('DROP TABLE %s CASCADE', $this->_driver->quoteIdentifier($table->name()));
     return [$sql];
 }
Beispiel #3
0
 /**
  * {@inheritDoc}
  */
 public function truncateTableSql(Table $table)
 {
     $name = $table->name();
     $sql = [];
     if ($this->hasSequences()) {
         $sql[] = sprintf('DELETE FROM sqlite_sequence WHERE name="%s"', $name);
     }
     $sql[] = sprintf('DELETE FROM "%s"', $name);
     return $sql;
 }
 /**
  * Returns an array of column data for a single column
  *
  * @param \Cake\Database\Schema\Table $tableSchema Name of the table to retrieve columns for
  * @param string $column A column to retrieve data for
  * @return array
  */
 public function column($tableSchema, $column)
 {
     return ['columnType' => $tableSchema->columnType($column), 'options' => $this->attributes($tableSchema->name(), $column)];
 }
Beispiel #5
0
 /**
  * {@inheritDoc}
  */
 public function createTableSql(Table $table, $columns, $constraints, $indexes)
 {
     $content = implode(",\n", array_merge($columns, $constraints, $indexes));
     $temporary = $table->temporary() ? ' TEMPORARY ' : ' ';
     $content = sprintf("CREATE%sTABLE `%s` (\n%s\n)", $temporary, $table->name(), $content);
     $options = $table->options();
     if (isset($options['engine'])) {
         $content .= sprintf(' ENGINE=%s', $options['engine']);
     }
     if (isset($options['charset'])) {
         $content .= sprintf(' DEFAULT CHARSET=%s', $options['charset']);
     }
     if (isset($options['collate'])) {
         $content .= sprintf(' COLLATE=%s', $options['collate']);
     }
     return [$content];
 }
Beispiel #6
0
 /**
  * {@inheritDoc}
  */
 public function dropConstraintSql(Table $table)
 {
     $sqlPattern = 'ALTER TABLE %s DROP FOREIGN KEY %s;';
     $sql = [];
     foreach ($table->constraints() as $name) {
         $constraint = $table->constraint($name);
         if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) {
             $tableName = $this->_driver->quoteIdentifier($table->name());
             $constraintName = $this->_driver->quoteIdentifier($name);
             $sql[] = sprintf($sqlPattern, $tableName, $constraintName);
         }
     }
     return $sql;
 }
 /**
  * {@inheritDoc}
  */
 public function truncateTableSql(Table $table)
 {
     $name = $this->_driver->quoteIdentifier($table->name());
     return [sprintf('TRUNCATE TABLE %s', $name)];
 }
 /**
  * {@inheritDoc}
  */
 public function truncateTableSql(Table $table)
 {
     $name = $this->_driver->quoteIdentifier($table->name());
     $queries = [sprintf('DELETE FROM %s', $name)];
     // Restart identity sequences
     $pk = $table->primaryKey();
     if (count($pk) === 1) {
         $column = $table->column($pk[0]);
         if (in_array($column['type'], ['integer', 'biginteger'])) {
             $queries[] = sprintf('DBCC CHECKIDENT(%s, RESEED, 0)', $name);
         }
     }
     return $queries;
 }
 /**
  * Generate the SQL to drop a table.
  *
  * @param \Cake\Database\Schema\Table $table Table instance
  * @return array SQL statements to drop a table.
  */
 public function dropTableSql(Table $table)
 {
     $sql = sprintf('DROP TABLE %s CASCADE CONSTRAINTS', $this->_driver->quoteIfAutoQuote($table->name()));
     return [$sql];
 }
 /**
  * Generates SQL statements dropping foreign keys for the table.
  *
  * @param \Cake\Database\Connection $db Connection to run the SQL queries on.
  * @param  \Cake\Database\Schema\Table $table Drop foreign keys for this table.
  * @return array List of SQL statements dropping foreign keys.
  */
 protected function _generateDropForeignKeys($db, Schema $table)
 {
     $type = 'other';
     if ($db->driver() instanceof Mysql) {
         $type = 'mysql';
     }
     $queries = [];
     foreach ($table->constraints() as $constraintName) {
         $constraint = $table->constraint($constraintName);
         if ($constraint['type'] === Schema::CONSTRAINT_FOREIGN) {
             // TODO: Move this into the driver
             if ($type === 'mysql') {
                 $template = 'ALTER TABLE %s DROP FOREIGN KEY %s';
             } else {
                 $template = 'ALTER TABLE %s DROP CONSTRAINT %s';
             }
             $queries[] = sprintf($template, $table->name(), $constraintName);
         }
     }
     return $queries;
 }