Skip to content

Commit fcaddc1

Browse files
author
Christian Forgács
committed
fixup! fix: unhandled find operator with array value for mssql (#11466)
1 parent 4dce269 commit fcaddc1

File tree

4 files changed

+76
-134
lines changed

4 files changed

+76
-134
lines changed

src/driver/sqlserver/SqlServerDriver.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,13 +974,24 @@ export class SqlServerDriver implements Driver {
974974
return new MssqlParameter(value, normalizedType as any)
975975
}
976976

977+
/**
978+
* Recursively wraps values (including those inside FindOperators) into MssqlParameter instances,
979+
* ensuring correct type metadata is passed to the SQL Server driver.
980+
*
981+
* - If the value is a FindOperator containing an array, all elements are individually parametrized.
982+
* - If the value is a non-raw FindOperator, a transformation is applied to its internal value.
983+
* - Otherwise, the value is passed directly to parametrizeValue for wrapping.
984+
*
985+
* This ensures SQL Server receives properly typed parameters for queries involving operators like
986+
* In, MoreThan, Between, etc.
987+
*/
977988
parametrizeValues(column: ColumnMetadata, value: any) {
978989
if (value instanceof FindOperator) {
979990
if (Array.isArray(value.value)) {
980-
for (let parameterValueChild of value.value) {
981-
parameterValueChild = this.parametrizeValues(
991+
for (let i = 0; i < value.value.length; i++) {
992+
value.value[i] = this.parametrizeValues(
982993
column,
983-
parameterValueChild,
994+
value.value[i],
984995
)
985996
}
986997
} else if (value.type !== "raw") {

test/functional/find-options/basic-usage/find-options-where.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import "reflect-metadata"
22
import "../../../utils/test-setup"
3-
import { DataSource, LessThan, MoreThan } from "../../../../src"
3+
import {
4+
And,
5+
DataSource,
6+
In,
7+
IsNull,
8+
LessThan,
9+
MoreThan,
10+
Not,
11+
Or,
12+
} from "../../../../src"
413
import {
514
closeTestingConnections,
615
createTestingConnections,
@@ -468,6 +477,58 @@ describe("find options > where", () => {
468477
}),
469478
))
470479

480+
it("where with or + and find operator", () =>
481+
Promise.all(
482+
connections.map(async (connection) => {
483+
await prepareData(connection.manager)
484+
485+
const posts = await connection
486+
.createQueryBuilder(Post, "post")
487+
.setFindOptions({
488+
where: {
489+
counters: {
490+
likedUsers: {
491+
firstName: And(
492+
In(["Gyro", "Timber"]),
493+
Not(Or(IsNull(), In(["Foo", "Bar"]))),
494+
),
495+
},
496+
},
497+
},
498+
order: {
499+
id: "asc",
500+
},
501+
})
502+
.getMany()
503+
posts.should.be.eql([
504+
{
505+
id: 1,
506+
title: "Post #1",
507+
text: "About post #1",
508+
counters: { likes: 1 },
509+
},
510+
{
511+
id: 2,
512+
title: "Post #2",
513+
text: "About post #2",
514+
counters: { likes: 2 },
515+
},
516+
{
517+
id: 3,
518+
title: "Post #3",
519+
text: "About post #3",
520+
counters: { likes: 1 },
521+
},
522+
{
523+
id: 4,
524+
title: "Post #4",
525+
text: "About post #4",
526+
counters: { likes: 1 },
527+
},
528+
])
529+
}),
530+
))
531+
471532
it("where relations with operators", () =>
472533
Promise.all(
473534
connections.map(async (connection) => {

test/github-issues/11466/entity/user.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/github-issues/11466/issue-11466.ts

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)