/** * test add column */ public function test_add_column() { //create it $this->adapter->execute_ddl("CREATE TABLE `users` ( name varchar(20) );"); $col = $this->adapter->column_info("users", "name"); $this->assertEquals("name", $col['field']); //add column $this->adapter->add_column("users", "fav_color", "string", array('limit' => 32)); $col = $this->adapter->column_info("users", "fav_color"); $this->assertEquals("fav_color", $col['field']); $this->assertEquals('varchar(32)', $col['type']); //add column $this->adapter->add_column("users", "latitude", "decimal", array('precision' => 10, 'scale' => 2)); $col = $this->adapter->column_info("users", "latitude"); $this->assertEquals("latitude", $col['field']); $this->assertEquals('decimal(10,2)', $col['type']); //add column with unsigned parameter $this->adapter->add_column("users", "age", "integer", array('unsigned' => true)); $col = $this->adapter->column_info("users", "age"); $this->assertEquals("age", $col['field']); $this->assertEquals('int(11) unsigned', $col['type']); //add column with biginteger datatype $this->adapter->add_column("users", "weight", "biginteger", array('limit' => 20)); $col = $this->adapter->column_info("users", "weight"); $this->assertEquals("weight", $col['field']); $this->assertEquals('bigint(20)', $col['type']); // Test that the collate option works $this->adapter->add_column('users', 'shortcode', 'string', array('collate' => 'utf8_bin')); $col = $this->adapter->column_info('users', 'shortcode'); $this->assertEquals('utf8_bin', $col['collation']); // Test that the character option works, default collation of latin1 is latin1_swedish_ci // http://dev.mysql.com/doc/refman/5.0/en/charset-mysql.html $this->adapter->add_column('users', 'highschool', 'string', array('character' => 'latin1')); $col = $this->adapter->column_info('users', 'highschool'); $this->assertEquals('latin1_swedish_ci', $col['collation']); $this->remove_table('users'); }
/** * Add a column * * @param string $table_name the name of the table * @param string $column_name the column name * @param string $type the column type * @param array|string $options * * @return boolean */ public function add_column($table_name, $column_name, $type, $options = array()) { return $this->_adapter->add_column($table_name, $column_name, $type, $options); }