);
public $fields;
+ public $indexes;
function __construct($name,$opt=array()) {
*
*/
public function indexes() {
- $sql = str_replace('<NAME>',$this->name,$this->db()->type('table.sql.index'));
- if (is_array($sql)) list($sql,$fct) = count($sql)==1 ? [$sql[0],null] : $sql;
- if (!$sql) return [];
+ if (!isset($this->indexes)) {
+ $sql = str_replace('<NAME>',$this->name,$this->db()->type('table.sql.index'));
+ if (is_array($sql)) list($sql,$fct) = count($sql)==1 ? [$sql[0],null] : $sql;
+ if (!$sql) return [];
- $st = $this->db()->conn->prepare($sql);
- $st->execute();
- $return = [];
- while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
+ $st = $this->db()->conn->prepare($sql);
+ $st->execute();
+ $this->indexes = [];
+ while ($row = $st->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT)) {
- if (!$fct) $return[] = $row;
- elseif ($r = $fct($row)) $return[] = $r;
+ if (!$fct) $this->indexes[] = $row;
+ elseif ($r = $fct($row)) $this->indexes[] = $r;
+ }
}
- return $return;
+ return $this->indexes;
}
/*
$rows = $this->db()->conn->query($conf['sql']);
$rows->setFetchMode(PDO::FETCH_ASSOC);
+ // Get other indexes
+ $indexes = [];
+ foreach ($this->indexes() as $i) {
+ if (empty($i['unique'])) $indexes[$i['field']] = 1;
+ }
+
foreach ($rows as $row) {
$row = array_change_key_case($row,CASE_LOWER);
'name' => $row['name'],
'type' => strtolower($row['type']),
'key' => (preg_match('/^(f.*|no|0)?\s*$/i',$row['key']) ? 0 : 1),
+ 'index' => (empty($indexes[$row['name']]) ? 0 : $indexes[$row['name']]),
'null' => (preg_match('/^(f.*|no|0)?\s*$/i',$row['null']) ? 0 : 1),
'extra' => (isset($row['extra']) ? $row['extra'] : null), # !!! nothing todo with array $extra, this info from the sql server
'autoincrement' => (isset($row['autoincrement']) ? $row['autoincrement'] : 0),