Proposal: quote column names #14
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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?
Author: @fasterthanlime
Currently, builder never quotes anything:
Would you be open to making it escape columns and tables, so that instead of:
It would generate:
(I'm using builder with SQLite, but I believe at least MySQL & PostgreSQL both support escaping colum and table names with double quotes (
"
))As usual I can work on a PR as soon as I get your 👍
Author: @fasterthanlime
Mhh maybe builder is not the right place to do this. Maybe the ORM is the right place to do this. How does xorm handle this?
Author: @lunny
@fasterthanlime xorm will quote the columns generated by struct. I agree builder could have an optional to add quote to all columns. But to keep compatible, the default will not add quote automatically. And in fact you could add quote manually at present. For example:
Author: @fasterthanlime
That makes sense, I'll make my persistent layer do the same. Thanks for the input, let's keep builder simple!
Author: @hurisheng
if using xorm, column names in 'select' is quoted, but condition fields is not quoted. I found that in xorm source code, for example,
genGetSQL()
generates condition withbuilder.ToSQL(statement.cond)
which doesn't quote field name (https://github.com/go-xorm/xorm/blob/master/statement.go#L962). The rest part ofgenGetSQL()
generate select statement withQuote()
(https://github.com/go-xorm/xorm/blob/master/statement.go#L1030). So the final SQL would looks like (mysql):As
group
is reserved word in mysql, so the result is syntax error.Of course we can quote manually, but I think if xorm can quote the condition or builder supports quote is better way for consistency. Quoted is always better than not.
@lunny Could you please give some thoughts how to implement this, I would like to try create PR.
Author: @lunny
@hurisheng You have to add quote in your self builder conditions. Quote feature should be implemented in future builder version.