Rewrite Engine.QuoteTo() to accept multi-part identifiers #1476
No reviewers
Labels
No Label
backport/done
backport/v1
blocked
db
oracle
db
sqlserver
duplicate
feature
cache
frontport/done
frontport/main
invalid
kind
breaking
kind
bug
kind
build
kind
dependencies
kind
docs
kind
driver
kind
enhancement
kind
feature
kind
performance
kind
proposal
kind
question
kind
refactor
kind
testing
need
feedback
need
test
proposal:accepted
RaspBerry Pi
regression
skip-changelog
upstream
wip
wontfix
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: xorm/xorm#1476
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch ":fix-quotes-schema"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR rewrites
Engine.QuoteTo()
so the following cases are handled properly:mytable
"mytable"
"mytable"
"mytable"
'mytable'
"mytable"
myschema.mytable
"myschema"."mytable"
"myschema".mytable
"myschema"."mytable"
myschema."mytable"
"myschema"."mytable"
"myschema"."mytable"
"myschema"."mytable"
'myschema'.mytable
"myschema"."mytable"
myschema.'mytable'
"myschema"."mytable"
'myschema'.'mytable'
"myschema"."mytable"
NOTE: I'm using
'
instead of backticks because I can't escape inline backticks in the text.Background
When
engine.SetSchema()
is used, a new part of the table identifier is added. For example, if we had tableissue
, now the identifier becomesschema.issue
. However, the problem comes when identifiers are quoted. For example in:The generated query looks like this:
As one can see,
user
is not properly quoted in theFROM
part of the statement. This is becauseEngine.tbNameWithSchema()
adds the schema, and thenQuoteTo()
receivesschema.'user'
as the table name (with backticks).@lunny with this PR I've been able to make go-gitea/gitea#8819 work in all my tests (complex queries, exec, table
user
, etc.)Mmmm..... CI fails. I'll have to work more on this.
@ -0,0 +1,41 @@
// Copyright 2018 The Xorm Authors. All rights reserved.
2019
@lunny done.
How can CI be restarted?
Oh, I see, CI was waiting for a comment from me (or it was you who restarted it?) 😄
@lunny tests passing. 😄
else
is unnecessary.Otherwise LGTM
Indeed. Fixed.