示例#1
0
 /**
  * {@inheritdoc}
  */
 public function getTableSchema($table)
 {
     $result = $this->db->rawQuery('PRAGMA table_info("' . $this->db->tableName($table) . '")');
     $schema = new SchemaBuilder($table);
     $primaryKey = array();
     while ($row = $result->fetchAssoc()) {
         $column = $row['name'];
         if (isset($row['pk']) and $row['pk'] == '1') {
             $primaryKey[] = $column;
         }
         $schema->addField($column, $this->toDataType($row));
     }
     $schema->setPrimaryKey($primaryKey);
     $result = $this->db->rawQuery('PRAGMA index_list("' . $this->db->tableName($table) . '")');
     while ($row = $result->fetchAssoc()) {
         $index = $row['name'];
         $unique = $row['unique'] == 1;
         $name = preg_replace('/^' . preg_quote($this->db->tableName($table) . '_', '/') . '/', '', $index, 1, $count);
         if ($count == 0) {
             continue;
         }
         $columnResult = $this->db->rawQuery('PRAGMA index_info("' . $index . '")');
         $columns = array();
         while ($row = $columnResult->fetchAssoc()) {
             $columns[] = $row['name'];
         }
         if ($unique) {
             $schema->addUnique($name, $columns);
         } else {
             $schema->addIndex($name, $columns);
         }
     }
     return $schema;
 }