Skip to content

Commit

Permalink
Update DoctrineAdapter.php
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnkersloot committed Dec 3, 2020
1 parent b37db0e commit a1ef3d9
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/ARC2/Store/Adapter/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Exception;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;

/**
* Doctrine Adapter - Handles database operations using Doctrine Connections.
Expand Down Expand Up @@ -88,7 +89,7 @@ public function fetchList($sql)

$stmt = $this->connection->prepare($sql);
$result = $stmt->execute();
$rows = $result->fetchAllAssociative();
$rows = $stmt->fetchAllAssociative();

return $rows;
}
Expand All @@ -104,7 +105,7 @@ public function fetchRow($sql)
$row = false;
$stmt = $this->connection->prepare($sql);
$result = $stmt->execute();
$rows = $result->fetchAllAssociative();
$rows = $stmt->fetchAllAssociative();
if (0 < \count($rows)) {
$row = \array_values($rows)[0];
}
Expand Down Expand Up @@ -140,9 +141,30 @@ public function getDBSName()

public function getServerInfo()
{
$connection = $this->connection->getWrappedConnection();

// Automatic platform version detection.
if ($connection instanceof ServerInfoAwareConnection && ! $connection->requiresQueryForServerVersion()) {
return $connection->getServerVersion();
}

// Unable to detect platform version.
return null;
}

public function getServerVersion()
{
$res = \preg_match(
"/([0-9]+)\.([0-9]+)\.([0-9]+)/",
$this->getServerInfo(),
$matches
);

return 1 == $res
? \sprintf('%02d-%02d-%02d', $matches[1], $matches[2], $matches[3])
: '00-00-00';
}

public function getErrorCode()
{
return $this->connection->errorCode();
Expand All @@ -169,7 +191,7 @@ public function getNumberOfRows($sql)
try {
$stmt = $this->connection->prepare($sql);
$result = $stmt->execute();
$rowCount = \count($result->fetchAllAssociative());
$rowCount = \count($stmt->fetchAllAssociative());
return $rowCount;
} catch (\Doctrine\DBAL\Exception $e) {
$this->errors[] = $e->getMessage();
Expand Down

0 comments on commit a1ef3d9

Please sign in to comment.