Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'];
}
}
21 changes: 18 additions & 3 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1136,4 +1146,9 @@ public function getInternalIndexesKeys(): array
{
return [];
}

protected function processException(PDOException $e): \Exception
{
return $e;
}
}