Skip to content

Commit d473400

Browse files
committed
fix bugs
1 parent 0485a5b commit d473400

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/Builder/BaseBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ public function query(string $sql, array $params = [])
794794
*/
795795
public function result(int|string $type = PDO::FETCH_OBJ): array
796796
{
797-
return $this->execute()->result($type);
797+
return $this->execute()->get($type);
798798
}
799799

800800
/**

src/Connection/BaseConnection.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,11 @@ public function escapeIdentifiers(mixed $item): mixed
595595
*/
596596
protected function escapeIdentifier(string $item): string
597597
{
598-
return $this->escapeChar . str_replace($this->escapeChar, $this->escapeChar . $this->escapeChar, $item) . $this->escapeChar;
598+
if ($this->isEscapedIdentifier($item)) {
599+
return $item;
600+
}
601+
602+
return $this->escapeChar . $item . $this->escapeChar;
599603
}
600604

601605
/**
@@ -606,6 +610,22 @@ protected function isReserved(string $item): bool
606610
return in_array($item, ['*'], true);
607611
}
608612

613+
/**
614+
* Determine si une chaine est échappée comme un identifiant SQL
615+
*/
616+
public function isEscapedIdentifier(string $value): bool
617+
{
618+
if ($value === '') {
619+
return false;
620+
}
621+
622+
$value = trim($value);
623+
624+
return str_starts_with($value, $this->escapeChar)
625+
// && str_contains($value, '.')
626+
&& str_ends_with($value, $this->escapeChar);
627+
}
628+
609629
/**
610630
* Crée le nom de la table avec son alias et le prefix des table de la base de données
611631
*/

src/Query/Result.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,11 @@ public function get(int|string $type = PDO::FETCH_OBJ): array
206206

207207
public function result(int $mode = PDO::FETCH_OBJ, ?string $className = null): array
208208
{
209-
$this->statement->setFetchMode($mode, $className);
209+
if ($mode === PDO::FETCH_CLASS) {
210+
$this->statement->setFetchMode($mode, $className);
211+
} else {
212+
$this->statement->setFetchMode($mode);
213+
}
210214

211215
$data = $this->statement->fetchAll();
212216

0 commit comments

Comments
 (0)