Merge pull request #511 from Andrei-hub11/fix/digit-schema-quote
fix: quote identifiers starting with numbers
This commit is contained in:
commit
d375d06267
2 changed files with 10 additions and 7 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
|
||||
|
|
@ -309,8 +310,8 @@ func shouldQuoteIdentifier(identifier string) bool {
|
|||
}
|
||||
|
||||
// check if contains non ascii characters
|
||||
for _, c := range identifier {
|
||||
if unicode.IsNumber(c) || c == '_' {
|
||||
for i, c := range identifier {
|
||||
if (unicode.IsNumber(c) && i > 0) || c == '_' {
|
||||
continue
|
||||
}
|
||||
if c > unicode.MaxASCII || !unicode.IsLetter(c) || unicode.IsUpper(c) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package jet
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestArgToString(t *testing.T) {
|
||||
|
|
@ -58,4 +59,5 @@ func TestShouldQuote(t *testing.T) {
|
|||
require.Equal(t, shouldQuoteIdentifier("abc_123"), false)
|
||||
require.Equal(t, shouldQuoteIdentifier("Abc_123"), true)
|
||||
require.Equal(t, shouldQuoteIdentifier("DŽƜĐǶ"), true)
|
||||
require.Equal(t, shouldQuoteIdentifier("1test"), true)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue