Exemplo n.º 1
0
 /**
  * Get table
  *
  * @param  string $tableName
  * @param  string $schema
  * @return Object\TableObject
  */
 public function getTable($tableName, $schema = null)
 {
     if ($schema === null) {
         $schema = $this->defaultSchema;
     }
     $this->loadTableNameData($schema);
     if (!isset($this->data['table_names'][$schema][$tableName])) {
         throw new \Exception('Table "' . $tableName . '" does not exist');
     }
     $data = $this->data['table_names'][$schema][$tableName];
     switch ($data['table_type']) {
         case 'BASE TABLE':
             $table = new Object\TableObject($tableName);
             break;
         case 'VIEW':
             $table = new Object\ViewObject($tableName);
             $table->setViewDefinition($data['view_definition']);
             $table->setCheckOption($data['check_option']);
             $table->setIsUpdatable($data['is_updatable']);
             break;
         default:
             throw new \Exception('Table "' . $tableName . '" is of an unsupported type "' . $data['table_type'] . '"');
     }
     $table->setColumns($this->getColumns($tableName, $schema));
     $table->setConstraints($this->getConstraints($tableName, $schema));
     return $table;
 }