support quoting reserved words
This commit is contained in:
parent
0d32fc82d8
commit
1ca41cc8b5
@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/mattn/go-oci8"
|
||||
)
|
||||
@ -38,6 +39,9 @@ func (oracle) BindVar(i int) string {
|
||||
}
|
||||
|
||||
func (oracle) Quote(key string) string {
|
||||
if isReserved(key) {
|
||||
return fmt.Sprintf(`"%s"`, key)
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
|
167
dialects/oracle/reserved.go
Normal file
167
dialects/oracle/reserved.go
Normal file
@ -0,0 +1,167 @@
|
||||
package oracle
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
const reserved = `AGGREGATE
|
||||
AGGREGATES
|
||||
ALL
|
||||
ALLOW
|
||||
ANALYZE
|
||||
ANCESTOR
|
||||
AND
|
||||
ANY
|
||||
AS
|
||||
ASC
|
||||
AT
|
||||
AVG
|
||||
BETWEEN
|
||||
BINARY_DOUBLE
|
||||
BINARY_FLOAT
|
||||
BLOB
|
||||
BRANCH
|
||||
BUILD
|
||||
BY
|
||||
BYTE
|
||||
CASE
|
||||
CAST
|
||||
CHAR
|
||||
CHILD
|
||||
CLEAR
|
||||
CLOB
|
||||
COMMIT
|
||||
COMPILE
|
||||
CONSIDER
|
||||
COUNT
|
||||
DATATYPE
|
||||
DATE
|
||||
DATE_MEASURE
|
||||
DAY
|
||||
DECIMAL
|
||||
DELETE
|
||||
DESC
|
||||
DESCENDANT
|
||||
DIMENSION
|
||||
DISALLOW
|
||||
DIVISION
|
||||
DML
|
||||
ELSE
|
||||
END
|
||||
ESCAPE
|
||||
EXECUTE
|
||||
FIRST
|
||||
FLOAT
|
||||
FOR
|
||||
FROM
|
||||
HIERARCHIES
|
||||
HIERARCHY
|
||||
HOUR
|
||||
IGNORE
|
||||
IN
|
||||
INFINITE
|
||||
INSERT
|
||||
INTEGER
|
||||
INTERVAL
|
||||
INTO
|
||||
IS
|
||||
LAST
|
||||
LEAF_DESCENDANT
|
||||
LEAVES
|
||||
LEVEL
|
||||
LEVELS
|
||||
LIKE
|
||||
LIKEC
|
||||
LIKE2
|
||||
LIKE4
|
||||
LOAD
|
||||
LOCAL
|
||||
LOG_SPEC
|
||||
LONG
|
||||
MAINTAIN
|
||||
MAX
|
||||
MEASURE
|
||||
MEASURES
|
||||
MEMBER
|
||||
MEMBERS
|
||||
MERGE
|
||||
MLSLABEL
|
||||
MIN
|
||||
MINUTE
|
||||
MODEL
|
||||
MONTH
|
||||
NAN
|
||||
NCHAR
|
||||
NCLOB
|
||||
NO
|
||||
NONE
|
||||
NOT
|
||||
NULL
|
||||
NULLS
|
||||
NUMBER
|
||||
NVARCHAR2
|
||||
OF
|
||||
OLAP
|
||||
OLAP_DML_EXPRESSION
|
||||
ON
|
||||
ONLY
|
||||
OPERATOR
|
||||
OR
|
||||
ORDER
|
||||
OVER
|
||||
OVERFLOW
|
||||
PARALLEL
|
||||
PARENT
|
||||
PLSQL
|
||||
PRUNE
|
||||
RAW
|
||||
RELATIVE
|
||||
ROOT_ANCESTOR
|
||||
ROWID
|
||||
SCN
|
||||
SECOND
|
||||
SELF
|
||||
SERIAL
|
||||
SET
|
||||
SOLVE
|
||||
SOME
|
||||
SORT
|
||||
SPEC
|
||||
SUM
|
||||
SYNCH
|
||||
TEXT_MEASURE
|
||||
THEN
|
||||
TIME
|
||||
TIMESTAMP
|
||||
TO
|
||||
UNBRANCH
|
||||
UPDATE
|
||||
USING
|
||||
VALIDATE
|
||||
VALUES
|
||||
VARCHAR2
|
||||
WHEN
|
||||
WHERE
|
||||
WITHIN
|
||||
WITH
|
||||
YEAR
|
||||
ZERO
|
||||
ZONE`
|
||||
|
||||
var setupReserved sync.Once
|
||||
var reservedWords map[string]struct{}
|
||||
|
||||
func isReserved(w string) bool {
|
||||
setupReserved.Do(
|
||||
func() {
|
||||
words := strings.Split(reserved, "\n")
|
||||
reservedWords = make(map[string]struct{}, len(words))
|
||||
for _, s := range words {
|
||||
reservedWords[s] = struct{}{}
|
||||
}
|
||||
},
|
||||
)
|
||||
_, ok := reservedWords[strings.ToUpper(w)]
|
||||
return ok
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user