39c55c948e00fbdfddb7058780f275c81c321411
3 namespace pq\Gateway\Table
;
7 const ATTRIBUTES_SQL
= <<<SQL
12 ,atthasdef as hasdefault
13 ,not attnotnull as nullable
16 where attrelid = \$1::regclass
25 protected $columns = array();
28 * @param \pq\Gateway\Table $table
30 function __construct(Table
$table) {
31 $cache = $table->getMetadataCache();
32 if (!($this->columns
= $cache->get("$table#attributes"))) {
33 $table->getQueryExecutor()->execute(
34 new \pq\Query\
Writer(ATTRIBUTES_SQL
, array($table->getName())),
35 function($result) use($table, $cache) {
36 foreach ($result->fetchAll(\pq\Result
::FETCH_OBJECT
) as $c) {
37 $this->columns
[$c->index
] = $this->columns
[$c->name
] = $c;
39 $cache->set("$table#attributes", $this->columns
);
46 * @implements \Countable
50 return count($this->columns
);
57 function getColumns() {
58 return $this->columns
;
66 function getColumn($c) {
67 if (!isset($this->columns
[$c])) {
68 throw new \
OutOfBoundsException("Unknown column $c");
70 return $this->columns
[$c];