Skip to content

Commit

Permalink
Binary: Don't reset properties when mysql adapter is used
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Apr 12, 2023
1 parent 3b7dca6 commit c47065f
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Behavior/Binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Binary extends PropertyBehavior implements QueryAwareBehavior, RewriteFilt
*/
protected $rewriteSubjects;

/** @var bool Whether the query is using a pgsql adapter */
protected $isPostgres = true;

public function fromDb($value, $key, $_)
{
if ($value !== null) {
Expand Down Expand Up @@ -79,12 +82,17 @@ public function setQuery(Query $query)

if (! $query->getDb()->getAdapter() instanceof Pgsql) {
// Only process properties if the adapter is PostgreSQL.
$this->properties = [];
$this->isPostgres = false;
}
}

public function rewriteCondition(Condition $condition, $relation = null)
{
if (! $this->isPostgres) {
// Only for PostgreSQL.
return;
}

/**
* TODO(lippserd): Duplicate code because {@see RewriteFilterBehavior}s come after {@see PropertyBehavior}s.
* {@see \ipl\Orm\Compat\FilterProcessor::requireAndResolveFilterColumns()}
Expand All @@ -93,19 +101,14 @@ public function rewriteCondition(Condition $condition, $relation = null)
if (isset($this->rewriteSubjects[$column])) {
$value = $condition->getValue();

if (empty($this->properties) && is_resource($value)) {
// Only for PostgreSQL.
throw new UnexpectedValueException(sprintf('Unexpected resource for %s', $column));
}

// ctype_xdigit expects strings.
$value = (string) $value;
/**
* Although this code path is also affected by the duplicate behavior evaluation stated in {@see toDb()},
* no further adjustments are needed as ctype_xdigit returns false for binary and bytea hex strings.
*/
if (ctype_xdigit($value)) {
if (empty($this->properties) && substr($value, 0, 2) !== '\\x') {
if (substr($value, 0, 2) !== '\\x') {
// Only for PostgreSQL.
$condition->setValue(sprintf('\\x%s', $value));
} else {
Expand Down

0 comments on commit c47065f

Please sign in to comment.