Beispiel #1
0
 /**
  * @param Entity $entity
  * @return bool
  */
 function delete(Entity $entity)
 {
     if (!$entity->getPK()) {
         throw new \LogicException("Cannot delete entity: PK is empty");
     }
     $sql = "DELETE FROM {$entity->getSourceName()} " . " WHERE {$entity->getPKName()} = :{$entity->getPKName()}";
     $stmt = $this->db->prepare($sql);
     $result = $stmt->execute([$entity->getPKName() => $entity->getPK()]);
     if (!$result) {
         throw new \RuntimeException("DELETE entity: DB query failed (PK: {$entity->getPK()})");
     }
     return (bool) $stmt->rowCount();
 }
Beispiel #2
0
 function testGroupRollback()
 {
     $txm = new \tinyorm\TxManager();
     $txm->registerConnection($this->connection)->registerConnection($this->connection2);
     try {
         $txm->atomic(function () {
             $this->connection->exec("INSERT INTO test (c_unique) VALUES ('val1')");
             $this->connection2->exec("INSERT INTO test (c_unique) VALUES ('val2')");
             throw new \Exception("TEST");
         });
         $this->fail("Expected exception throw");
     } catch (\Exception $e) {
         // 3: BEGIN; INSERT; ROLLBACK;
         $this->assertEquals(3, $this->connection->getQueryCount());
         $this->assertEquals(3, $this->connection2->getQueryCount());
         $this->assertRowCount("test", 0);
     }
 }
Beispiel #3
0
 protected function assertRowCount($table, $rowCount)
 {
     $count = $this->connection->query("SELECT COUNT(*) FROM {$table}")->fetchColumn();
     $this->assertEquals($rowCount, $count);
 }