-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: boolean parameter escape in SQLiteDriver (#9400)
* fix: sqlite boolean parameter escape sqlite does not support boolean parameters. Even though sqlite is able to transform true to 1 and false to 0 there might be some limitations with other implementations that build up on this. Fixes: #1981 (again) * fix: remove obsolete where boolean value transformation 3cbbe90 already handles the boolean value transformation so it is not necessary to have additional code in the query runner for handling this * test: add test cases for sqlite query parameter escape * fix typo
- Loading branch information
1 parent
6eb674b
commit 4a36d0e
Showing
3 changed files
with
85 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
test/functional/driver/abstract-sqlite/abstract-sqlite-escape-query-parameters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { DataSource } from "../../../../src" | ||
import { | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
closeTestingConnections, | ||
} from "../../../utils/test-utils" | ||
|
||
describe("escape sqlite query parameters", () => { | ||
let connections: DataSource[] | ||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["sqlite", "better-sqlite3"], | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should transform boolean parameters with value `true` into `1`", () => | ||
Promise.all( | ||
connections.map((connection) => { | ||
const [_, parameters] = | ||
connection.driver.escapeQueryWithParameters( | ||
"SELECT nothing FROM irrelevant WHERE a = :param1", | ||
{ param1: true }, | ||
{}, | ||
) | ||
|
||
parameters.should.eql([1]) | ||
}), | ||
)) | ||
|
||
it("should transform boolean parameters with value `false` into `0`", () => | ||
Promise.all( | ||
connections.map((connection) => { | ||
const [_, parameters] = | ||
connection.driver.escapeQueryWithParameters( | ||
"SELECT nothing FROM irrelevant WHERE a = :param1", | ||
{ param1: false }, | ||
{}, | ||
) | ||
|
||
parameters.should.eql([0]) | ||
}), | ||
)) | ||
|
||
it("should transform boolean nativeParameters with value `true` into `1`", () => | ||
Promise.all( | ||
connections.map((connection) => { | ||
const [_, parameters] = | ||
connection.driver.escapeQueryWithParameters( | ||
"SELECT nothing FROM irrelevant", | ||
{}, | ||
{ nativeParam1: true }, | ||
) | ||
|
||
parameters.should.eql([1]) | ||
}), | ||
)) | ||
|
||
it("should transform boolean nativeParameters with value `false` into 0", () => | ||
Promise.all( | ||
connections.map((connection) => { | ||
const [_, parameters] = | ||
connection.driver.escapeQueryWithParameters( | ||
"SELECT nothing FROM irrelevant", | ||
{}, | ||
{ nativeParam1: false }, | ||
) | ||
|
||
parameters.should.eql([0]) | ||
}), | ||
)) | ||
}) |