Skip to content

Commit 59a021c

Browse files
Fix casting.
1 parent 23b935c commit 59a021c

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

backend/src/Squidex.Data.EntityFramework/Providers/MySql/JsonFunction.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,12 @@ public static string Create(PropertyPath path, CompareOperator op, ClrValue valu
111111
return $"{fn}(`{path[0]}`, {path.JsonSubPath()})";
112112
}
113113

114+
var arg = formattedValue;
114115
if (value.IsList)
115116
{
116-
return $"{fn}(`{path[0]}`, {path.JsonSubPath()}, JSON_ARRAY({formattedValue}))";
117+
arg = $"JSON_ARRAY({formattedValue})";
117118
}
118119

119-
return $"{fn}(`{path[0]}`, {path.JsonSubPath()}, {formattedValue})";
120+
return $"{fn}(`{path[0]}`, {path.JsonSubPath()}, {arg})";
120121
}
121122
}

backend/src/Squidex.Data.EntityFramework/Providers/Postgres/JsonFunction.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,20 @@ public static string Create(PropertyPath path, CompareOperator op, ClrValue valu
101101
return $"{fn}({path.JsonPath(false)})";
102102
}
103103

104-
if (value.IsList)
104+
var arg = formattedValue;
105+
if (value.IsList && type == TypeNumber)
105106
{
106-
return $"{fn}({path.JsonPath(false)}, ARRAY[{formattedValue}])";
107+
arg = $"ARRAY[{formattedValue}]::numeric[]";
108+
}
109+
else if (value.IsList)
110+
{
111+
arg = $"ARRAY[{formattedValue}]";
112+
}
113+
else if (type == TypeNumber)
114+
{
115+
arg = $"{formattedValue}::numeric";
107116
}
108117

109-
return $"{fn}({path.JsonPath(false)}, {formattedValue})";
118+
return $"{fn}({path.JsonPath(false)}, {arg})";
110119
}
111120
}

backend/src/Squidex.Data.EntityFramework/Squidex.Data.EntityFramework.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<DebugSymbols>True</DebugSymbols>
1212
</PropertyGroup>
1313
<ItemGroup>
14-
<None Remove="Providers\Postgres\json_function.sql" />
1514
<None Remove="Providers\SqlServer\json_function.sql" />
1615
</ItemGroup>
1716
<ItemGroup>

backend/tests/Squidex.Data.Tests/EntityFramework/Infrastructure/Queries/EFQueryTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,17 @@ public async Task Should_filter_by_number_equal()
384384
Assert.Equal([7], actual.Order().ToArray());
385385
}
386386

387+
[Fact]
388+
public async Task Should_filter_by_number_equal_with_double()
389+
{
390+
var actual = await QueryAsync(new ClrQuery
391+
{
392+
Filter = ClrFilter.Eq("Number", 7.0),
393+
});
394+
395+
Assert.Equal([7], actual.Order().ToArray());
396+
}
397+
387398
[Fact]
388399
public async Task Should_filter_by_number_not_equal()
389400
{

0 commit comments

Comments
 (0)