refactored/moved into dialect_oracommon.go
This commit is contained in:
parent
545a171442
commit
dea5ee724a
@ -1,49 +0,0 @@
|
||||
package oci8
|
||||
|
||||
/*
|
||||
|
||||
Understanding Oracle
|
||||
|
||||
It's a bit different than the other RDBMS databases and I'll just try to
|
||||
hightlight a few of the important ones the dialect has to deal with:
|
||||
|
||||
1. Oracle upper cases all non-quoted identifiers. That means the dialect
|
||||
has to decide what to do:
|
||||
1. quote all identifiers which would require developers to quote every
|
||||
identifer they passed in a string to gorm.
|
||||
2. only quote identifers that conflict with reserved words and leave all
|
||||
other identifiers unquoted, which means Oracle will automatically
|
||||
upper case them. This would allow developers to pass unquoted
|
||||
identifiers in strings they passed to gorm and make the experience
|
||||
align better with the other dialects.
|
||||
We chose option #2.
|
||||
|
||||
This design decision has the following side affects:
|
||||
a. you must be case insensitive when matching column names, like in
|
||||
the Scope.scan function
|
||||
b. Devs will have to escape reserved words when they reference them
|
||||
in things like: First(&CreditCard{}, `"number" = ?`)
|
||||
|
||||
|
||||
2. Oracle handles last inserted id a bit differently, and requires a sql.Out
|
||||
parameter to return the value in the oci8 driver. Since Oracle parameters
|
||||
are positional, you need to know how many other bind variables there are before
|
||||
adding the returning clause. We've implemented the
|
||||
OraDialect.CreateWithReturningInto(*Scope) to handle this.
|
||||
|
||||
3. Oracle doesn't let you specify "AS <tablename> " when selecting a count
|
||||
from a dynamic table, so you just omit it. (see Scope.count() )
|
||||
|
||||
4. Oracle handles foreign keys a bit differently:
|
||||
A. REFERENCES is implicit
|
||||
B. ON UPDATE is not supported
|
||||
(see scope.addForeignKey() )
|
||||
|
||||
5. Searching a blob requires using a function from the dbms_lob package like
|
||||
instr() and specifying the offset and number of matches.
|
||||
(see oci8.SearchBlob() )
|
||||
|
||||
6 Trailing semicolons are not allowed at the end of Oracle sql statements
|
||||
(so they were removed in the unit tests)
|
||||
|
||||
*/
|
@ -1,166 +0,0 @@
|
||||
package oci8
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
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`
|
Loading…
x
Reference in New Issue
Block a user