for oracle support

modify base on lastest version of xorm
This commit is contained in:
ilisin 2015-03-05 09:56:15 +08:00
parent ede84cde60
commit 7acdf292bf
3 changed files with 20 additions and 2 deletions

View File

@ -1404,6 +1404,9 @@ func (engine *Engine) NowTime2(sqlTypeName string) (interface{}, time.Time) {
}
func (engine *Engine) FormatTime(sqlTypeName string, t time.Time) (v interface{}) {
if engine.dialect.DBType() == core.ORACLE {
return t
}
switch sqlTypeName {
case core.Time:
s := engine.TZTime(t).Format("2006-01-02 15:04:05") //time.RFC3339

View File

@ -448,6 +448,13 @@ func (session *Session) exec(sqlStr string, args ...interface{}) (sql.Result, er
return session.Engine.LogSQLExecutionTime(sqlStr, args, func() (sql.Result, error) {
if session.IsAutoCommit {
//oci8 can not auto commit (github.com/mattn/go-oci8)
if session.Engine.dialect.DBType() == core.ORACLE {
session.Begin()
r, err := session.Tx.Exec(sqlStr, args...)
session.Commit()
return r, err
}
return session.innerExec(sqlStr, args...)
}
return session.Tx.Exec(sqlStr, args...)

View File

@ -1221,8 +1221,12 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) {
}
var fromStr string = " FROM " + statement.Engine.Quote(statement.TableName())
if statement.TableAlias != "" {
if statement.Engine.dialect.DBType() == core.ORACLE {
fromStr += " " + statement.Engine.Quote(statement.TableAlias)
} else {
fromStr += " AS " + statement.Engine.Quote(statement.TableAlias)
}
}
if statement.JoinStr != "" {
fromStr = fmt.Sprintf("%v %v", fromStr, statement.JoinStr)
}
@ -1277,12 +1281,16 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) {
if statement.OrderStr != "" {
a = fmt.Sprintf("%v ORDER BY %v", a, statement.OrderStr)
}
if statement.Engine.dialect.DBType() != core.MSSQL {
if statement.Engine.dialect.DBType() != core.MSSQL && statement.Engine.dialect.DBType() != core.ORACLE {
if statement.Start > 0 {
a = fmt.Sprintf("%v LIMIT %v OFFSET %v", a, statement.LimitN, statement.Start)
} else if statement.LimitN > 0 {
a = fmt.Sprintf("%v LIMIT %v", a, statement.LimitN)
}
} else if statement.Engine.dialect.DBType() == core.ORACLE {
if statement.Start != 0 || statement.LimitN != 0 {
a = fmt.Sprintf("SELECT %v FROM (SELECT %v,ROWNUM RN FROM (%v) at WHERE ROWNUM <= %d) aat WHERE RN > %d", columnStr, columnStr, a, statement.Start+statement.LimitN, statement.Start)
}
}
return