Add IdentQuoteSlice
This commit is contained in:
parent
0008aa0495
commit
01124d9d0b
2 changed files with 27 additions and 1 deletions
|
@ -21,7 +21,7 @@ var (
|
||||||
|
|
||||||
// IdentQuote attempts to quote simple identifiers in SQL tatements
|
// IdentQuote attempts to quote simple identifiers in SQL tatements
|
||||||
func IdentQuote(s string) string {
|
func IdentQuote(s string) string {
|
||||||
if s == "null" {
|
if strings.ToLower(s) == "null" {
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,20 @@ func IdentQuote(s string) string {
|
||||||
return strings.Join(splits, ".")
|
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
|
// Identifier is a base conversion from Base 10 integers to Base 26
|
||||||
// integers that are represented by an alphabet from a-z
|
// integers that are represented by an alphabet from a-z
|
||||||
// See tests for example outputs.
|
// See tests for example outputs.
|
||||||
|
|
|
@ -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) {
|
func TestIDGen(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue