public static function load(PDO $connection) { $name = $connection->getAttribute(PDO::ATTR_DRIVER_NAME); switch ($name) { case 'mysql': return MySql::loadPDO($connection); case 'pgsql': return PostGreSql::loadPDO($connection); case 'sqlite': return Sqlite::loadPDO($connection); default: throw SqlException::forUnknownPDO($name); } }
/** * @covers Cradle\Sql\AbstractSql::transaction * @covers Cradle\Sql\Search::getTotal */ public function testTransaction() { $test = $this; $triggered = false; $total = $this->object->search('address')->getTotal(); $this->object->transaction(function () use($test, &$triggered) { $triggered = true; $test->assertInstanceOf('Cradle\\Sql\\MySql', $this); $this->insertRow('address', array('address_label' => 'Foo Bar', 'address_street' => 'foobar', 'address_city' => 'foobar', 'address_country' => 'foobar', 'address_postal' => 'foobar', 'address_created' => date('Y-m-d H:i:s'), 'address_updated' => date('Y-m-d H:i:s'))); }); $this->assertTrue($triggered); $this->assertEquals($total + 1, $this->object->search('address')->getTotal()); $triggered = false; $this->object->transaction(function () use($test, &$triggered) { $triggered = true; $test->assertInstanceOf('Cradle\\Sql\\MySql', $this); $this->insertRow('address', array('address_label' => 'Foo Bar', 'address_street' => 'foobar', 'address_city' => 'foobar', 'address_country' => 'foobar', 'address_postal' => 'foobar', 'address_created' => date('Y-m-d H:i:s'), 'address_updated' => date('Y-m-d H:i:s'))); return false; }); $this->assertTrue($triggered); $this->assertEquals($total + 1, $this->object->search('address')->getTotal()); }