refactor to use isOra()

This commit is contained in:
Jim Lambert 2020-02-15 16:12:09 -05:00
parent 81b1478ecf
commit 582cc3cc49
4 changed files with 11 additions and 11 deletions

View File

@ -50,7 +50,7 @@ func (*PersonAddress) Delete(handler gorm.JoinTableHandlerInterface, db *gorm.DB
func (pa *PersonAddress) JoinWith(handler gorm.JoinTableHandlerInterface, db *gorm.DB, source interface{}) *gorm.DB {
table := pa.Table(db)
where := fmt.Sprintf("%v.deleted_at IS NULL OR %v.deleted_at <= ", table, table)
if isOracle(db) {
if isOra(db) {
where = where + "DATE '0001-01-02'"
} else {
where = where + "'0001-01-02'"

View File

@ -574,7 +574,7 @@ func TestTransactionReadonly(t *testing.T) {
if dialect == "" {
dialect = "sqlite"
}
if isOracle(DB) {
if isOra(DB) {
dialect = "oracle"
}
switch dialect {
@ -1352,7 +1352,7 @@ func TestQueryHint1(t *testing.T) {
db := DB.New()
q := "select 1"
if isOracle(db) {
if isOra(db) {
q = q + " from dual"
}
_, err := db.Model(User{}).Raw(q).Rows()
@ -1462,8 +1462,8 @@ func parseTime(str string) *time.Time {
return &t
}
// isOracle gives tests an easy way to determine if the dialect uses Oracle for its RMDBS, since oracle could have multiple dialects for different drivers.
// and since tests run in their own namespace
func isOracle(db *gorm.DB) bool {
return db.Dialect().GetName() == "oci8"
// isOra gives tests an easy way to determine if the dialect uses Oracle for its RMDBS, since oracle could have multiple dialects for different drivers.
func isOra(db *gorm.DB) bool {
_, ok := db.Dialect().(gorm.OraDialect)
return ok
}

View File

@ -185,7 +185,7 @@ func TestSearchWithPlainSQL(t *testing.T) {
}
param := "?"
if isOracle(scopedb) {
if isOra(scopedb) {
param = "to_date(?, 'YYYY-MM-DD')"
}
scopedb.Where("birthday > "+param, "2002-10-10").Find(&users)
@ -773,7 +773,7 @@ func TestSelectWithEscapedFieldName(t *testing.T) {
DB.Save(&user1).Save(&user2).Save(&user3)
colName := "name"
if isOracle(DB) {
if isOra(DB) {
colName = "NAME" // oracle upper cases all identifiers that aren't explicitly escaped when the table is created
}
var names []string
@ -794,7 +794,7 @@ func TestSelectWithVariables(t *testing.T) {
} else {
columns, _ := rows.Columns()
colName := "fake"
if isOracle(DB) {
if isOra(DB) {
colName = "FAKE" // oracle upper cases all identifiers that aren't explicitly escaped when the table is created
}
if !reflect.DeepEqual(columns, []string{colName}) {

View File

@ -65,7 +65,7 @@ func TestValuer(t *testing.T) {
var user2 User
if isOracle(DB) {
if isOra(DB) {
where := fmt.Sprintf("name = ? AND %s AND %s", oracle.SearchBlob("password_hash"), oracle.SearchBlob("password"))
if err := DB.Where(where, name, "abc", "***pass1").First(&user2).Error; err != nil {