Add IdentQuoteSlice

This commit is contained in:
Aaron L 2016-08-03 21:46:58 -07:00
parent 0008aa0495
commit 01124d9d0b
2 changed files with 27 additions and 1 deletions

View file

@ -21,7 +21,7 @@ var (
// IdentQuote attempts to quote simple identifiers in SQL tatements
func IdentQuote(s string) string {
if s == "null" {
if strings.ToLower(s) == "null" {
return s
}
@ -41,6 +41,20 @@ func IdentQuote(s string) string {
return strings.Join(splits, ".")
}
// IdentQuoteSlice applies IdentQuote to a slice.
func IdentQuoteSlice(s []string) []string {
if len(s) == 0 {
return s
}
strs := make([]string, len(s))
for i, str := range s {
strs[i] = IdentQuote(str)
}
return strs
}
// Identifier is a base conversion from Base 10 integers to Base 26
// integers that are represented by an alphabet from a-z
// See tests for example outputs.

View file

@ -35,6 +35,18 @@ func TestIdentQuote(t *testing.T) {
}
}
func TestIdentQuoteSlice(t *testing.T) {
t.Parallel()
ret := IdentQuoteSlice([]string{`thing`, `null`})
if ret[0] != `"thing"` {
t.Error(ret[0])
}
if ret[1] != `null` {
t.Error(ret[1])
}
}
func TestIDGen(t *testing.T) {
t.Parallel()