-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix handling of numeric values for SQLite in comparisons #207
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -624,10 +624,7 @@ public function walkNumComparisonConstraint(QOM\PropertyValueInterface $property | |
$alias = $this->getTableAlias($propertyOperand->getSelectorName() . '.' . $propertyOperand->getPropertyName()); | ||
$property = $propertyOperand->getPropertyName(); | ||
|
||
return | ||
$this->sqlXpathExtractNumValue($alias, $property) . " " . | ||
$operator . " " . | ||
$literalOperand->getLiteralValue(); | ||
return $this->sqlXpathCompareNumValue($alias, $property, $this->getLiteralValue($literalOperand), $operator); | ||
} | ||
|
||
/** | ||
|
@@ -803,13 +800,23 @@ private function sqlXpathExtractValue($alias, $property) | |
throw new NotImplementedException("Xpath evaluations cannot be executed with '" . $this->platform->getName() . "' yet."); | ||
} | ||
|
||
private function sqlXpathExtractNumValue($alias, $property) | ||
private function sqlXpathCompareNumValue($alias, $property, $value, $operator) | ||
{ | ||
if ($this->platform instanceof SqlitePlatform) { | ||
$expression = "EXTRACTVALUE($alias.props, 'count(//sv:property[@sv:name=\"" . $property . "\"]/sv:value[text()%s%s]) > 0')"; | ||
|
||
return sprintf($expression, $this->walkOperator($operator), Xpath::escape($value)); | ||
} | ||
|
||
if ($this->platform instanceof PostgreSqlPlatform) { | ||
return "(xpath('//sv:property[@sv:name=\"" . $property . "\"]/sv:value[1]/text()', CAST($alias.props AS xml), ".$this->sqlXpathPostgreSQLNamespaces()."))[1]::text::int"; | ||
$expression = "(xpath('//sv:property[@sv:name=\"" . $property . "\"]/sv:value[1]/text()', CAST($alias.props AS xml), ".$this->sqlXpathPostgreSQLNamespaces()."))[1]::text::int"; | ||
} elseif ($this->platform instanceof MySqlPlatform) { | ||
$expression = $this->sqlXpathExtractValue($alias, $property); | ||
} else { | ||
throw new NotImplementedException("Xpath evaluations cannot be executed with '" . $this->platform->getName() . "' yet."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this not more confusing than anything else to a user? he was not trying to do xpath, he was doing query builder or sql2 - its our implementation detail that we use xpath for what he is doing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah .. but imho we should clean that up in another PR as we do this in several places |
||
} | ||
|
||
return $this->sqlXpathExtractValue($alias, $property); | ||
return "$expression $operator $value"; | ||
} | ||
|
||
private function sqlXpathExtractValueAttribute($alias, $property, $attribute, $valueIndex = 1) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it make sense to have a method here when it only works for mysql? and it looks like the BC way would be to do this for all platforms we did not previously handle, not only msql. (not sure if users could sneak oracle or such in and if that previously worked)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't support Oracle yet .. I am sure we will need to do some explict code for each RDBMS we support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or in other words .. right now I rather have the code explicitly say which code path is for what RDBMS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed.