Ruckusing_Adapter_PgSQL_Base::has_index PHP Method

has_index() public method

Check an index
public has_index ( string $table_name, string $column_name, array $options = [] ) : boolean
$table_name string the table name
$column_name string the column name
$options array index options
return boolean
    public function has_index($table_name, $column_name, $options = array())
    {
        if (empty($table_name)) {
            throw new Ruckusing_Exception("Missing table name parameter", Ruckusing_Exception::INVALID_ARGUMENT);
        }
        if (empty($column_name)) {
            throw new Ruckusing_Exception("Missing column name parameter", Ruckusing_Exception::INVALID_ARGUMENT);
        }
        //did the user specify an index name?
        if (is_array($options) && array_key_exists('name', $options)) {
            $index_name = $options['name'];
        } else {
            $index_name = Ruckusing_Util_Naming::index_name($table_name, $column_name);
        }
        $indexes = $this->indexes($table_name);
        foreach ($indexes as $idx) {
            if ($idx['name'] == $index_name) {
                return true;
            }
        }
        return false;
    }

Usage Example

コード例 #1
0
 /**
  * test remove index with custom index name
  */
 public function test_remove_index_with_custom_index_name()
 {
     //create it
     $table = $this->adapter->create_table('users');
     $table->column('name', 'string', array('limit' => 20));
     $table->column('age', 'integer');
     $table->finish();
     $this->adapter->add_index("users", "name", array('name' => 'my_special_index'));
     $this->assertEquals(true, $this->adapter->has_index("users", "name", array('name' => 'my_special_index')));
     //drop it
     $this->adapter->remove_index("users", "name", array('name' => 'my_special_index'));
     $this->assertEquals(false, $this->adapter->has_index("users", "name", array('name' => 'my_special_index')));
     $this->drop_table('users');
 }