fix: quote identifiers starting with numbers
This commit is contained in:
parent
8667bca8fc
commit
b6fa663315
2 changed files with 18 additions and 5 deletions
|
|
@ -4,15 +4,16 @@ import (
|
|||
"bytes"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"github.com/go-jet/jet/v2/internal/3rdparty/pq"
|
||||
"github.com/go-jet/jet/v2/internal/utils/is"
|
||||
"github.com/google/uuid"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/go-jet/jet/v2/internal/3rdparty/pq"
|
||||
"github.com/go-jet/jet/v2/internal/utils/is"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
// SQLBuilder generates output SQL
|
||||
|
|
@ -302,12 +303,21 @@ func integerTypesToString(value interface{}) string {
|
|||
}
|
||||
|
||||
func shouldQuoteIdentifier(identifier string) bool {
|
||||
if len(identifier) == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
_, err := strconv.ParseInt(identifier, 10, 64)
|
||||
|
||||
if err == nil { // if it is a number we should quote it
|
||||
return true
|
||||
}
|
||||
|
||||
firstChar := rune(identifier[0])
|
||||
if unicode.IsNumber(firstChar) {
|
||||
return true
|
||||
}
|
||||
|
||||
// check if contains non ascii characters
|
||||
for _, c := range identifier {
|
||||
if unicode.IsNumber(c) || c == '_' {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue