Skip to content

Fix Oracle Dialect #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions db.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (m *DbMap) createIndexImpl(dialect reflect.Type,
if dname := dialect.Name(); dname == "MySQLDialect" && index.IndexType != "" {
s.WriteString(fmt.Sprintf(" %s %s", m.Dialect.CreateIndexSuffix(), index.IndexType))
}
s.WriteString(";")
s.WriteString(m.Dialect.QuerySuffix())
_, err := m.Exec(s.String())
return err
}
Expand All @@ -197,7 +197,7 @@ func (t *TableMap) DropIndex(name string) error {
if dname := dialect.Name(); dname == "MySQLDialect" {
s.WriteString(fmt.Sprintf(" %s %s", t.dbmap.Dialect.DropIndexSuffix(), t.TableName))
}
s.WriteString(";")
s.WriteString(t.dbmap.Dialect.QuerySuffix())
_, e := t.dbmap.Exec(s.String())
if e != nil {
err = e
Expand Down Expand Up @@ -531,7 +531,7 @@ func (m *DbMap) dropTableImpl(table *TableMap, ifExists bool) (err error) {
if ifExists {
tableDrop = m.Dialect.IfTableExists(tableDrop, table.SchemaName, table.TableName)
}
_, err = m.Exec(fmt.Sprintf("%s %s;", tableDrop, m.Dialect.QuotedTableForQuery(table.SchemaName, table.TableName)))
_, err = m.Exec(fmt.Sprintf("%s %s%s", tableDrop, m.Dialect.QuotedTableForQuery(table.SchemaName, table.TableName), m.Dialect.QuerySuffix()))
return err
}

Expand All @@ -543,14 +543,16 @@ func (m *DbMap) TruncateTables() error {
var err error
for i := range m.tables {
table := m.tables[i]
_, e := m.Exec(fmt.Sprintf("%s %s;", m.Dialect.TruncateClause(), m.Dialect.QuotedTableForQuery(table.SchemaName, table.TableName)))
println(m.Dialect.QuerySuffix())
_, e := m.Exec(fmt.Sprintf("%s %s%s", m.Dialect.TruncateClause(), m.Dialect.QuotedTableForQuery(table.SchemaName, table.TableName), m.Dialect.QuerySuffix()))
if e != nil {
err = e
}
}

for _, table := range m.dynamicTableMap() {
_, e := m.Exec(fmt.Sprintf("%s %s;", m.Dialect.TruncateClause(), m.Dialect.QuotedTableForQuery(table.SchemaName, table.TableName)))
println(m.Dialect.QuerySuffix())
_, e := m.Exec(fmt.Sprintf("%s %s%s", m.Dialect.TruncateClause(), m.Dialect.QuotedTableForQuery(table.SchemaName, table.TableName), m.Dialect.QuerySuffix()))
if e != nil {
err = e
}
Expand Down Expand Up @@ -744,7 +746,7 @@ func (m *DbMap) SelectOne(holder interface{}, query string, args ...interface{})
func (m *DbMap) Begin() (*Transaction, error) {
if m.logger != nil {
now := time.Now()
defer m.trace(now, "begin;")
defer m.trace(now, "begin"+m.Dialect.QuerySuffix())
}
tx, err := begin(m)
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions dialect_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (d OracleDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool)
case reflect.Ptr:
return d.ToSqlType(val.Elem(), maxsize, isAutoIncr)
case reflect.Bool:
return "boolean"
return "number(1, 0)"
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32:
if isAutoIncr {
return "serial"
Expand All @@ -41,11 +41,11 @@ func (d OracleDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool)
if isAutoIncr {
return "bigserial"
}
return "bigint"
return "number(19, 0)"
case reflect.Float64:
return "double precision"
return "float(24)"
case reflect.Float32:
return "real"
return "float(24)"
case reflect.Slice:
if val.Elem().Kind() == reflect.Uint8 {
return "bytea"
Expand All @@ -54,17 +54,17 @@ func (d OracleDialect) ToSqlType(val reflect.Type, maxsize int, isAutoIncr bool)

switch val.Name() {
case "NullInt64":
return "bigint"
return "number(19, 0)"
case "NullFloat64":
return "double precision"
return "float(24)"
case "NullBool":
return "boolean"
return "number(1, 0)"
case "NullTime", "Time":
return "timestamp with time zone"
return "date"
}

if maxsize > 0 {
return fmt.Sprintf("varchar(%d)", maxsize)
return fmt.Sprintf("varchar2(%d)", maxsize)
} else {
return "text"
}
Expand All @@ -90,7 +90,7 @@ func (d OracleDialect) CreateTableSuffix() string {
}

func (d OracleDialect) TruncateClause() string {
return "truncate"
return "truncate table"
}

// Returns "$(i+1)"
Expand Down