addColumn() public méthode

Adds a new column to a table.
public addColumn ( string $tableName, string $columnName, string $type, array $options = [] )
$tableName string A table name.
$columnName string A column name.
$type string A data type.
$options array Column options. See Horde_Db_Adapter_Base_TableDefinition#column() for details.
Exemple #1
0
 /**
  * Adds a new column to a table.
  *
  * @param string $tableName   A table name.
  * @param string $columnName  A column name.
  * @param string $type        A data type.
  * @param array $options      Column options. See
  *                            Horde_Db_Adapter_Base_TableDefinition#column()
  *                            for details.
  */
 public function addColumn($tableName, $columnName, $type, $options = array())
 {
     if ($this->transactionStarted()) {
         throw new Horde_Db_Exception('Cannot add columns to a SQLite database while inside a transaction');
     }
     if ($type == 'autoincrementKey') {
         $this->_alterTable($tableName, array(), create_function('$definition', sprintf('$definition->column("%s", "%s", %s);', $columnName, $type, var_export($options, true))));
     } else {
         parent::addColumn($tableName, $columnName, $type, $options);
     }
     // See last paragraph on http://www.sqlite.org/lang_altertable.html
     $this->execute('VACUUM');
 }
Exemple #2
0
 /**
  * Adds a new column to a table.
  *
  * @param string $tableName   A table name.
  * @param string $columnName  A column name.
  * @param string $type        A data type.
  * @param array $options      Column options. See
  *                            Horde_Db_Adapter_Base_TableDefinition#column()
  *                            for details.
  */
 public function addColumn($tableName, $columnName, $type, $options = array())
 {
     /* Ignore ':autoincrement' - it is handled automatically by SQLite
      * for any 'INTEGER PRIMARY KEY' column. */
     if ($this->transactionStarted()) {
         throw new Horde_Db_Exception('Cannot add columns to a SQLite database while inside a transaction');
     }
     parent::addColumn($tableName, $columnName, $type, $options);
     // See last paragraph on http://www.sqlite.org/lang_altertable.html
     $this->execute('VACUUM');
 }