コード例 #1
0
 /**
  * Returns metadata for all indexes in a table.
  * @param  string
  * @return array
  */
 public function getIndexes($table)
 {
     $this->driver->query("PRAGMA index_list([{$table}])");
     $res = array();
     while ($row = $this->driver->fetch(TRUE)) {
         $res[$row['name']]['name'] = $row['name'];
         $res[$row['name']]['unique'] = (bool) $row['unique'];
     }
     $this->driver->free();
     foreach ($res as $index => $values) {
         $this->driver->query("PRAGMA index_info([{$index}])");
         while ($row = $this->driver->fetch(TRUE)) {
             $res[$index]['columns'][$row['seqno']] = $row['name'];
         }
     }
     $this->driver->free();
     $columns = $this->driver->getColumns($table);
     foreach ($res as $index => $values) {
         $column = $res[$index]['columns'][0];
         $primary = FALSE;
         foreach ($columns as $info) {
             if ($column == $info['name']) {
                 $primary = $info['vendor']['pk'];
                 break;
             }
         }
         $res[$index]['primary'] = (bool) $primary;
     }
     if (!$res) {
         // @see http://www.sqlite.org/lang_createtable.html#rowid
         foreach ($columns as $column) {
             if ($column['vendor']['pk']) {
                 $res[] = array('name' => 'ROWID', 'unique' => TRUE, 'primary' => TRUE, 'columns' => array($column['name']));
                 break;
             }
         }
     }
     return array_values($res);
 }
コード例 #2
0
ファイル: DibiDatabaseInfo.php プロジェクト: romcok/treeview
 /**
  * @return void
  */
 protected function initColumns()
 {
     if ($this->columns === NULL) {
         $this->columns = array();
         foreach ($this->driver->getColumns($this->name) as $info) {
             $this->columns[strtolower($info['name'])] = new DibiColumnInfo($this->driver, $info);
         }
     }
 }