8000 fix: join clause literal value is treated as Double quotation mark in Postgres Database by YongSeok-Choi51 · Pull Request #6130 · knex/knex · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: join clause literal value is treated as Double quotation mark in Postgres Database #6130

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

YongSeok-Choi51
8000 Copy link
@YongSeok-Choi51 YongSeok-Choi51 commented Sep 22, 2024

Related Issue

[Literal Value treated as Column name in Where Clause (Postgres Database)]

Issue Detail

db // Knex instance

// Basic query that includes a join with literal join value
const qb = db('table_a').innerJoin('table_b', join => {
  join.onVal('table_b.id', '123')
})

// Executing select on this query results in proper formatting of literal value
// SQL: select "table_a"."id" from "table_a" inner join "table_b" on "table_b"."id" = '123' 👈👈 (This Allows in Postgres!)
console.log(qb.select('table_a.id').toQuery())

// Executing delete on this query results in literal value being formatted as if it were a column name
// SQL: delete from "table_a" using "table_b" where "table_b"."id" = "123"  👈👈 (This is Not Allowed in Postgres. 123 must be single quoted like '123')
console.log(qb.delete().toQuery())

Description (Solution)

i fixed this issue by using builder._queryContext that cannot be shared to string format method (wrapIdentifierImpl)

@@ -74,7 +78,9 @@ class Client_PG extends Client {
arrayAccessor = arrayAccessorMatch[2];
}

return `"${value.replace(/"/g, '""')}"${arrayAccessor}`;
return isLiteralValue()
? `'${value.replace(/"/g, '""')}'${arrayAccessor}`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapIdentifierImpl method is implemented in each DBVender Class(ex. oracle, mysql, mssql)

berows are other DB Class Implementations

mssql - wrapIdentifierImpl

mysql - wrapIdentifierImpl

sqlite3 - wrapIdentifierImpl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0