Skip to content

Commit

Permalink
Merge pull request #15446 from Zanzofily/fix/query-builder-text-const…
Browse files Browse the repository at this point in the history
…raints-pgsql

Fix: QueryBuilder's TextConstraint for Postgres
  • Loading branch information
danharrin authored Jan 31, 2025
2 parents ebfe69b + 4660d73 commit 9141746
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ public function apply(Builder $query, string $qualifiedColumn): Builder

$isPostgres = $databaseConnection->getDriverName() === 'pgsql';

if ((Str::lower($qualifiedColumn) !== $qualifiedColumn) && $isPostgres) {
$qualifiedColumn = (string) str($qualifiedColumn)->wrap('"');
}

if ($isPostgres) {
$qualifiedColumn = new Expression("lower({$qualifiedColumn}::text)");
[$table, $column] = explode('.', $qualifiedColumn);

if (Str::lower($table) !== $table) {
$table = (string) str($table)->wrap('"');
}

if (Str::lower($column) !== $column) {
$column = (string) str($column)->wrap('"');
}

$qualifiedColumn = new Expression("lower({$table}.{$column}::text)");
$text = Str::lower($text);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ public function apply(Builder $query, string $qualifiedColumn): Builder

$isPostgres = $databaseConnection->getDriverName() === 'pgsql';

if ((Str::lower($qualifiedColumn) !== $qualifiedColumn) && $isPostgres) {
$qualifiedColumn = (string) str($qualifiedColumn)->wrap('"');
}

if ($isPostgres) {
$qualifiedColumn = new Expression("lower({$qualifiedColumn}::text)");
[$table, $column] = explode('.', $qualifiedColumn);

if (Str::lower($table) !== $table) {
$table = (string) str($table)->wrap('"');
}

if (Str::lower($column) !== $column) {
$column = (string) str($column)->wrap('"');
}

$qualifiedColumn = new Expression("lower({$table}.{$column}::text)");
$text = Str::lower($text);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ public function apply(Builder $query, string $qualifiedColumn): Builder

$isPostgres = $databaseConnection->getDriverName() === 'pgsql';

if ((Str::lower($qualifiedColumn) !== $qualifiedColumn) && $isPostgres) {
$qualifiedColumn = (string) str($qualifiedColumn)->wrap('"');
}

if ($isPostgres) {
$qualifiedColumn = new Expression("lower({$qualifiedColumn}::text)");
[$table, $column] = explode('.', $qualifiedColumn);

if (Str::lower($table) !== $table) {
$table = (string) str($table)->wrap('"');
}

if (Str::lower($column) !== $column) {
$column = (string) str($column)->wrap('"');
}

$qualifiedColumn = new Expression("lower({$table}.{$column}::text)");
$text = Str::lower($text);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ public function apply(Builder $query, string $qualifiedColumn): Builder

$isPostgres = $databaseConnection->getDriverName() === 'pgsql';

if ((Str::lower($qualifiedColumn) !== $qualifiedColumn) && $isPostgres) {
$qualifiedColumn = (string) str($qualifiedColumn)->wrap('"');
}

if ($isPostgres) {
$qualifiedColumn = new Expression("lower({$qualifiedColumn}::text)");
[$table, $column] = explode('.', $qualifiedColumn);

if (Str::lower($table) !== $table) {
$table = (string) str($table)->wrap('"');
}

if (Str::lower($column) !== $column) {
$column = (string) str($column)->wrap('"');
}

$qualifiedColumn = new Expression("lower({$table}.{$column}::text)");
$text = Str::lower($text);
}

Expand Down

0 comments on commit 9141746

Please sign in to comment.