Welcome Guest, Not a member yet? Register   Sign In
DB_forge/mysql_forge
#1

[eluser]North2Alaska[/eluser]
Looking at how to create a unique column (or a table with a unique key on a column), I found it necessary to modify the mysql_forge library as this may be specific to MySQL and as you can not extend database classes (at least, according to the docs). I have modified mysql_forge to include the following:

Code:
if (array_key_exists('AUTO_INCREMENT', $attributes) && $attributes['AUTO_INCREMENT'] === TRUE)
    {
     $sql .= ' AUTO_INCREMENT';
    }
    
/**
*  Added the UNIQUE keyword to creating a column.  This will add a UNIQUE KEY to the table based on this column.
*/
    
    if (array_key_exists('UNIQUE', $attributes) && $attributes['UNIQUE'] === TRUE)
    {
     $sql .= ' UNIQUE';
    }

It would be nice if you could have done this from the $this->dbforge->add_key(column, key_type) but it doesn't support it and unique keys may not be consistant across database, so I felt it better suited in mysql_forge.

Your thoughts?




Theme © iAndrew 2016 - Forum software by © MyBB