Skip to content

Commit

Permalink
fix nextras/dbal 5.x compatibility (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerin authored Jun 1, 2022
1 parent ac0adea commit f47a8f2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"nette/di": "~2.3.12 | ~2.4",
"nette/tester": "~1.7 | ~2.0",
"nette/utils": "~2.3",
"nextras/dbal": "~1.0 | ~2.0 | ~3.0 | ~4.0",
"nextras/dbal": "~1.0 | ~2.0 | ~3.0 | ~4.0 | ~5.0@dev",
"symfony/config": "~2.6 | ~3.0 | ~4.0",
"symfony/console": "~2.6 | ~3.0 | ~4.0",
"symfony/dependency-injection": "~2.6 | ~3.0 | ~4.0",
Expand Down
29 changes: 22 additions & 7 deletions src/Bridges/NextrasDbal/NextrasAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@ class NextrasAdapter implements IDbal
/** @var Connection */
private $conn;

/** @var bool */
private $oldDriver;
/** @var int */
private $version;


public function __construct(Connection $connection)
{
$this->conn = $connection;
$this->conn->connect();
$this->oldDriver = method_exists($connection->getDriver(), 'convertToSql');

if (method_exists($connection->getDriver(), 'convertToSql')) {
$this->version = 1;

} elseif (method_exists($connection->getDriver(), 'convertBoolToSql')) {
$this->version = 2;

} else {
$this->version = 5;
}
}


Expand All @@ -51,7 +60,7 @@ public function exec($sql)

public function escapeString($value)
{
if (!$this->oldDriver) {
if ($this->version >= 2) {
return $this->conn->getDriver()->convertStringToSql($value);
} else {
return $this->conn->getDriver()->convertToSql($value, IDriver::TYPE_STRING);
Expand All @@ -67,7 +76,9 @@ public function escapeInt($value)

public function escapeBool($value)
{
if (!$this->oldDriver) {
if ($this->version >= 5) {
return $this->conn->getPlatform()->formatBool($value);
} elseif ($this->version >= 2) {
return $this->conn->getDriver()->convertBoolToSql($value);
} else {
return $this->conn->getDriver()->convertToSql($value, IDriver::TYPE_BOOL);
Expand All @@ -77,7 +88,9 @@ public function escapeBool($value)

public function escapeDateTime(DateTime $value)
{
if (!$this->oldDriver) {
if ($this->version >= 5) {
return $this->conn->getPlatform()->formatDateTime($value);
} elseif ($this->version >= 2) {
return $this->conn->getDriver()->convertDateTimeToSql($value);
} else {
return $this->conn->getDriver()->convertToSql($value, IDriver::TYPE_DATETIME);
Expand All @@ -87,7 +100,9 @@ public function escapeDateTime(DateTime $value)

public function escapeIdentifier($value)
{
if (!$this->oldDriver) {
if ($this->version >= 5) {
return $this->conn->getPlatform()->formatIdentifier($value);
} elseif ($this->version >= 2) {
return $this->conn->getDriver()->convertIdentifierToSql($value);
} else {
return $this->conn->getDriver()->convertToSql($value, IDriver::TYPE_IDENTIFIER);
Expand Down
6 changes: 6 additions & 0 deletions tests/matrix/dbal/nextras-5.0-php-7.4-to-8.1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
PHP_VERSION_MIN="70400"
PHP_VERSION_MAX="80199"
COMPOSER_REQUIRE="$COMPOSER_REQUIRE nextras/dbal:~5.0@dev"
COMPOSER_REQUIRE="$COMPOSER_REQUIRE nette/tester:~2.3"
DBAL="nextras"

0 comments on commit f47a8f2

Please sign in to comment.