Make identquote understand *
This commit is contained in:
parent
964f367700
commit
20fe91c398
2 changed files with 6 additions and 2 deletions
|
@ -16,7 +16,7 @@ import (
|
||||||
var (
|
var (
|
||||||
idAlphabet = []byte("abcdefghijklmnopqrstuvwxyz")
|
idAlphabet = []byte("abcdefghijklmnopqrstuvwxyz")
|
||||||
uppercaseWords = regexp.MustCompile(`^(?i)(id|uid|uuid|guid|ssn|tz)[0-9]*$`)
|
uppercaseWords = regexp.MustCompile(`^(?i)(id|uid|uuid|guid|ssn|tz)[0-9]*$`)
|
||||||
smartQuoteRgx = regexp.MustCompile(`^(?i)"?[a-z_][_a-z0-9]*"?(\."?[_a-z][_a-z0-9]*"?)*$`)
|
smartQuoteRgx = regexp.MustCompile(`^(?i)"?[a-z_][_a-z0-9]*"?(\."?[_a-z][_a-z0-9]*"?)*(\.\*)?$`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// IdentQuote attempts to quote simple identifiers in SQL tatements
|
// IdentQuote attempts to quote simple identifiers in SQL tatements
|
||||||
|
@ -31,7 +31,7 @@ func IdentQuote(s string) string {
|
||||||
|
|
||||||
splits := strings.Split(s, ".")
|
splits := strings.Split(s, ".")
|
||||||
for i, split := range splits {
|
for i, split := range splits {
|
||||||
if strings.HasPrefix(split, `"`) || strings.HasSuffix(split, `"`) {
|
if strings.HasPrefix(split, `"`) || strings.HasSuffix(split, `"`) || split == "*" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,10 @@ func TestIdentQuote(t *testing.T) {
|
||||||
{In: `thing.thing.thing.thing`, Out: `"thing"."thing"."thing"."thing"`},
|
{In: `thing.thing.thing.thing`, Out: `"thing"."thing"."thing"."thing"`},
|
||||||
{In: `thing."thing".thing."thing"`, Out: `"thing"."thing"."thing"."thing"`},
|
{In: `thing."thing".thing."thing"`, Out: `"thing"."thing"."thing"."thing"`},
|
||||||
{In: `count(*) as ab, thing as bd`, Out: `count(*) as ab, thing as bd`},
|
{In: `count(*) as ab, thing as bd`, Out: `count(*) as ab, thing as bd`},
|
||||||
|
{In: `hello.*`, Out: `"hello".*`},
|
||||||
|
{In: `hello.there.*`, Out: `"hello"."there".*`},
|
||||||
|
{In: `"hello".there.*`, Out: `"hello"."there".*`},
|
||||||
|
{In: `hello."there".*`, Out: `"hello"."there".*`},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in a new issue