Skip to content

Commit

Permalink
fix doctrine/dbal 3.x compatibility (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik authored Apr 4, 2022
1 parent 1eaebea commit ac0adea
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"require-dev": {
"dibi/dibi": "~3.0 | ~4.0",
"doctrine/cache": "~1.5",
"doctrine/dbal": "~2.5",
"doctrine/dbal": "~2.5 | ~3.0",
"doctrine/orm": "~2.5",
"mockery/mockery": "~0.9 | ~1.0",
"nette/database": "~2.2",
Expand Down
16 changes: 10 additions & 6 deletions src/Bridges/DoctrineDbal/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,41 @@ public function __construct(Doctrine\DBAL\Connection $conn)

public function query($sql)
{
return $this->conn->fetchAll($sql);
return method_exists($this->conn, 'fetchAllAssociative')
? $this->conn->fetchAllAssociative($sql)
: $this->conn->fetchAll($sql);
}


public function exec($sql)
{
return $this->conn->exec($sql);
return method_exists($this->conn, 'executeStatement')
? $this->conn->executeStatement($sql)
: $this->conn->exec($sql);
}


public function escapeString($value)
{
return $this->conn->quote($value, Doctrine\DBAL\Types\Type::STRING);
return $this->conn->quote($value, 'string');
}


public function escapeInt($value)
{
return $this->conn->quote($value, Doctrine\DBAL\Types\Type::INTEGER);
return $this->conn->quote($value, 'integer');
}


public function escapeBool($value)
{
return $this->conn->quote($value, Doctrine\DBAL\Types\Type::BOOLEAN);
return $this->conn->quote($value, 'boolean');
}


public function escapeDateTime(DateTime $value)
{
return $this->conn->quote($value, Doctrine\DBAL\Types\Type::DATETIME);
return $this->conn->quote($value, 'datetime');
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ migrations:
diffGenerator: doctrine

services:
- Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration([%doctrineDir%], true)
- Doctrine\ORM\Tools\Setup::createXMLMetadataConfiguration([%doctrineDir%], true)
- Doctrine\DBAL\DriverManager::getConnection(%doctrineConfig%, @Doctrine\ORM\Configuration)
- Doctrine\ORM\EntityManager::create(@Doctrine\DBAL\Connection, @Doctrine\ORM\Configuration)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ migrations:
driver: mysql

services:
- Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration([%doctrineDir%], true)
- Doctrine\ORM\Tools\Setup::createXMLMetadataConfiguration([%doctrineDir%], true)
- Doctrine\DBAL\DriverManager::getConnection(%doctrineConfig%, @Doctrine\ORM\Configuration)
- Doctrine\ORM\EntityManager::create(@Doctrine\DBAL\Connection, @Doctrine\ORM\Configuration)
6 changes: 6 additions & 0 deletions tests/matrix/dbal/doctrine-3.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
PHP_VERSION_MIN="70300"
PHP_VERSION_MAX="80099"
COMPOSER_REQUIRE="$COMPOSER_REQUIRE doctrine/dbal:~3.0"
COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/tester:~2.3"
DBAL="doctrine"

0 comments on commit ac0adea

Please sign in to comment.