Skip to content

Commit

Permalink
Fixed issue phalcon#11036
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeyklay authored and pantaovay committed Nov 12, 2015
1 parent 7f264a7 commit aaf3f55
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions phalcon/db/adapter/pdo/mysql.zep
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace Phalcon\Db\Adapter\Pdo;

use Phalcon\Db;
use Phalcon\Db\Column;
use Phalcon\Db\Index;
use Phalcon\Db\IndexInterface;
use Phalcon\Db\AdapterInterface;
use Phalcon\Db\Adapter\Pdo as PdoAdapter;

Expand Down Expand Up @@ -336,4 +338,53 @@ class Mysql extends PdoAdapter implements AdapterInterface

return columns;
}

/**
* Lists table indexes
*
* <code>
* print_r($connection->describeIndexes('robots_parts'));
* </code>
*
* @param string table
* @param string schema
* @return \Phalcon\Db\IndexInterface[]
*/
public function describeIndexes(string! table, schema = null) -> <IndexInterface[]>
{
var indexes, index, keyName, indexObjects, columns, name;

let indexes = [];
for index in this->fetchAll(this->_dialect->describeIndexes(table, schema), Db::FETCH_ASSOC) {
let keyName = index["Key_name"];

if !isset indexes[keyName] {
let indexes[keyName] = [];
}

if !isset indexes[keyName]["columns"] {
let columns = [];
} else {
let columns = indexes[keyName]["columns"];
}

let columns[] = index["Column_name"];
let indexes[keyName]["columns"] = columns;

if keyName == "PRIMARY" {
let indexes[keyName]["type"] = "PRIMARY";
} elseif index["Non_unique"] == 0 {
let indexes[keyName]["type"] = "UNIQUE";
} else {
let indexes[keyName]["type"] = null;
}
}

let indexObjects = [];
for name, index in indexes {
let indexObjects[name] = new Index(name, index["columns"], index["type"]);
}

return indexObjects;
}
}

0 comments on commit aaf3f55

Please sign in to comment.