diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 90ea0ae8c..b616247ab 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -2379,6 +2379,20 @@ public function setTimeout(int $milliseconds, string $event = Database::EVENT_AL }); } + /** + * @return string + */ + public function getConnectionId(): string + { + $stmt = $this->getPDO()->query("SELECT CONNECTION_ID();"); + return $stmt->fetchColumn(); + } + + public function getInternalIndexesKeys(): array + { + return ['primary', '_created_at', '_updated_at', '_tenant_id']; + } + protected function processException(PDOException $e): \Exception { // Timeout @@ -2412,22 +2426,11 @@ protected function processException(PDOException $e): \Exception return new TruncateException('Resize would result in data truncation', $e->getCode(), $e); } - + // Unknown database + if ($e->getCode() === '42000' && isset($e->errorInfo[1]) && $e->errorInfo[1] === 1049) { + return new NotFoundException($e->getMessage(), $e->getCode(), $e); + } return $e; } - - /** - * @return string - */ - public function getConnectionId(): string - { - $stmt = $this->getPDO()->query("SELECT CONNECTION_ID();"); - return $stmt->fetchColumn(); - } - - public function getInternalIndexesKeys(): array - { - return ['primary', '_created_at', '_updated_at', '_tenant_id']; - } } diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index 7e649919d..a0b6a3c6a 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -9,6 +9,7 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception as DatabaseException; +use Utopia\Database\Exception\NotFound as NotFoundException; use Utopia\Database\Exception\Transaction as TransactionException; use Utopia\Database\Query; @@ -163,10 +164,19 @@ public function exists(string $database, ?string $collection = null): bool $stmt->bindValue(':schema', $database, PDO::PARAM_STR); } - $stmt->execute(); + try { + $stmt->execute(); + $document = $stmt->fetchAll(); + $stmt->closeCursor(); + } catch (PDOException $e) { + $e = $this->processException($e); - $document = $stmt->fetchAll(); - $stmt->closeCursor(); + if ($e instanceof NotFoundException) { + return false; + } + + throw $e; + } if (empty($document)) { return false; @@ -1136,4 +1146,9 @@ public function getInternalIndexesKeys(): array { return []; } + + protected function processException(PDOException $e): \Exception + { + return $e; + } }