Make identquote understand *

This commit is contained in:
Aaron L 2016-08-03 19:17:29 -07:00
parent 964f367700
commit 20fe91c398
2 changed files with 6 additions and 2 deletions

View file

@ -16,7 +16,7 @@ import (
var (
idAlphabet = []byte("abcdefghijklmnopqrstuvwxyz")
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
@ -31,7 +31,7 @@ func IdentQuote(s string) string {
splits := strings.Split(s, ".")
for i, split := range splits {
if strings.HasPrefix(split, `"`) || strings.HasSuffix(split, `"`) {
if strings.HasPrefix(split, `"`) || strings.HasSuffix(split, `"`) || split == "*" {
continue
}

View file

@ -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: `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 {