Beispiel #1
0
 protected function setUp()
 {
     $this->conn = new \pq\Connection(PQ_TEST_DSN);
     $this->conn->exec(PQ_TEST_SETUP_SQL);
     Table::$defaultConnection = $this->conn;
     $this->table = new Table("test");
     $this->table->getQueryExecutor()->attach(new \QueryLogger());
 }
Beispiel #2
0
 function testOptimisticLockFail()
 {
     $this->table->attach(new Table\OptimisticLock("counter"));
     $row = $this->table->find(null, null, 1)->current();
     $row->data = "foo";
     executeInConcurrentTransaction($this->table->getQueryExecutor(), "UPDATE {$this->table->getName()} SET counter = 10 WHERE id=\$1", array($row->id->get()));
     $this->setExpectedException("\\UnexpectedValueException", "No row updated");
     $row->update();
 }
Beispiel #3
0
 /**
  * @param \pq\Gateway\Table $table
  */
 function __construct(Table $table)
 {
     $cache = $table->getMetadataCache();
     if (!($this->columns = $cache->get("{$table}:identity"))) {
         $table->getQueryExecutor()->execute(new \pq\Query\Writer(IDENTITY_SQL, array($table->getName())), function ($result) use($table, $cache) {
             $this->columns = array_map("current", $result->fetchAll(\pq\Result::FETCH_ARRAY));
             $cache->set("{$table}:identity", $this->columns);
         });
     }
 }
Beispiel #4
0
 /**
  * @param \pq\Gateway\Table $table
  */
 function __construct(Table $table)
 {
     $cache = $table->getMetadataCache();
     if (!($this->columns = $cache->get("{$table}:attributes"))) {
         $table->getQueryExecutor()->execute(new \pq\Query\Writer(ATTRIBUTES_SQL, array($table->getName())), function ($result) use($table, $cache) {
             foreach ($result->fetchAll(\pq\Result::FETCH_OBJECT) as $c) {
                 $this->columns[$c->index] = $this->columns[$c->name] = $c;
             }
             $cache->set("{$table}:attributes", $this->columns);
         });
     }
 }
Beispiel #5
0
 /**
  * @param \pq\Gateway\Table $table
  */
 function __construct(Table $table)
 {
     $cache = $table->getMetadataCache();
     if (!($this->references = $cache->get("{$table}:relations"))) {
         $table->getQueryExecutor()->execute(new \pq\Query\Writer(RELATION_SQL, array($table->getName())), function ($result) use($table, $cache) {
             $rel = $result->map([1, 2], null, \pq\Result::FETCH_ASSOC);
             foreach ($rel as $ref) {
                 foreach ($ref as $table => $key) {
                     $reference = new Reference($key);
                     $this->references[$table][$reference->name] = $reference;
                 }
             }
             $cache->set("{$table}:relations", $this->references);
         });
     }
 }