Detects when a MemberExpression returns null and adjusts it as a ConstantExpression #38

Merged
merged 2 commits into from Mar 6, 2014

Projects

None yet

2 participants

@arturosevilla

Neo4j doesn't consider null as valid values for PropertyBags
(relationships and nodes).

Neo4jClient could have a MemberExpression in a Where() construct and it
could detect it if was in reality a ConstantExpression, however it just
sends the value as parameter regardless if it's a null value.

This commit fixes that by having the same behavior that occurs in
VisitConstant(ConstantExpression) if it detects a null value.

@arturosevilla arturosevilla Detects when a MemberExpression returns null and adjusts it as a Cons…
…tantExpression

Neo4j doesn't consider null as valid values for PropertyBags
(relationships and nodes).
Neo4jClient could have a MemberExpression in a Where() construct and it
could detect it if was in reality a ConstantExpression, however it just
sends the value as parameter regardless if it's a null value.

This commit fixes that by having the same behavior that occurs in
VisitConstant(ConstantExpression) if it detects a null value.
38868f3
@tathamoddie tathamoddie commented on the diff Mar 6, 2014
Neo4jClient/Cypher/CypherWhereExpressionVisitor.cs
@@ -216,6 +216,45 @@ void VisitParameterMember(MemberExpression node)
void VisitConstantMember(MemberExpression node)
{
var value = GetConstantExpressionValue(node);
+
+ // if the value is null, sending a parameter would return something we don't want.
+ // A PropertyBag within the Neo4j server cannot have property with null value, that is, having a null
+ // property is the same as not having the property.
+ var text = TextOutput.ToString();
+ if (value == null && text.EndsWith(NotEqual))
+ {
+ TextOutput.Remove(TextOutput.ToString().LastIndexOf(NotEqual, StringComparison.Ordinal), NotEqual.Length);
+ if (capabilities.SupportsNullComparisonsWithIsOperator)
+ {
+ TextOutput.Append(" is not null");
+ }
+ else
+ {
+ TextOutput.Remove(TextOutput.ToString().LastIndexOf(lastWrittenMemberName, StringComparison.Ordinal), lastWrittenMemberName.Length);
@tathamoddie
tathamoddie Mar 6, 2014 Readify member

This logic branch isn't tested.

@tathamoddie tathamoddie commented on the diff Mar 6, 2014
Neo4jClient/Cypher/CypherWhereExpressionVisitor.cs
@@ -216,6 +216,45 @@ void VisitParameterMember(MemberExpression node)
void VisitConstantMember(MemberExpression node)
{
var value = GetConstantExpressionValue(node);
+
+ // if the value is null, sending a parameter would return something we don't want.
+ // A PropertyBag within the Neo4j server cannot have property with null value, that is, having a null
+ // property is the same as not having the property.
+ var text = TextOutput.ToString();
+ if (value == null && text.EndsWith(NotEqual))
+ {
+ TextOutput.Remove(TextOutput.ToString().LastIndexOf(NotEqual, StringComparison.Ordinal), NotEqual.Length);
+ if (capabilities.SupportsNullComparisonsWithIsOperator)
+ {
+ TextOutput.Append(" is not null");
@tathamoddie
tathamoddie Mar 6, 2014 Readify member

This logic branch isn't tested.

@tathamoddie tathamoddie commented on the diff Mar 6, 2014
Neo4jClient/Cypher/CypherWhereExpressionVisitor.cs
+ else
+ {
+ TextOutput.Remove(TextOutput.ToString().LastIndexOf(lastWrittenMemberName, StringComparison.Ordinal), lastWrittenMemberName.Length);
+ TextOutput.Append(string.Format("has({0})", lastWrittenMemberName));
+ }
+
+ // no further processing is required
+ return;
+ }
+
+ if (value == null && text.EndsWith(Equal))
+ {
+ TextOutput.Remove(TextOutput.ToString().LastIndexOf(Equal, StringComparison.Ordinal), Equal.Length);
+ if (capabilities.SupportsNullComparisonsWithIsOperator)
+ {
+ TextOutput.Append(" is null");
@tathamoddie
tathamoddie Mar 6, 2014 Readify member

This logic branch isn't tested.

@arturosevilla arturosevilla Added unit tests for CypherWhereExpressionVisitor.VisitConstantMember()
The unit tests from the last commit was moved from the
CypherFluentQueryWhereTests to CypherWhereExpressionBuilderTests and added
three more unit tests for all logic branches within this method.
1726e71
@arturosevilla

I added the missing unit tests.

@tathamoddie tathamoddie merged commit e8f7c19 into Readify:master Mar 6, 2014

1 check passed

Details default Finished TeamCity Build Neo4jClient :: Build : Tests passed: 761
@tathamoddie
Member

This will be automatically deployed to NuGet in about 60 seconds.

@arturosevilla arturosevilla deleted the arturosevilla:nullinmemberexpressionfix branch Mar 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment