refactored genSelectSql

This commit is contained in:
evalphobia 2015-08-30 20:23:46 +09:00
parent 693501fd60
commit 65f413ecf3
1 changed files with 7 additions and 6 deletions

View File

@ -1192,6 +1192,7 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) {
distinct = "DISTINCT "
}
var dialect core.Dialect = statement.Engine.Dialect()
var top string
var mssqlCondi string
/*var orderBy string
@ -1203,7 +1204,7 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) {
if statement.WhereStr != "" {
whereStr = fmt.Sprintf(" WHERE %v", statement.WhereStr)
if statement.ConditionStr != "" {
whereStr = fmt.Sprintf("%v %s %v", whereStr, statement.Engine.Dialect().AndStr(),
whereStr = fmt.Sprintf("%v %s %v", whereStr, dialect.AndStr(),
statement.ConditionStr)
}
} else if statement.ConditionStr != "" {
@ -1211,7 +1212,7 @@ 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 {
if dialect.DBType() == core.ORACLE {
fromStr += " " + statement.Engine.Quote(statement.TableAlias)
} else {
fromStr += " AS " + statement.Engine.Quote(statement.TableAlias)
@ -1221,7 +1222,7 @@ func (statement *Statement) genSelectSql(columnStr string) (a string) {
fromStr = fmt.Sprintf("%v %v", fromStr, statement.JoinStr)
}
if statement.Engine.dialect.DBType() == core.MSSQL {
if dialect.DBType() == core.MSSQL {
if statement.LimitN > 0 {
top = fmt.Sprintf(" TOP %d ", statement.LimitN)
}
@ -1271,19 +1272,19 @@ 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 && statement.Engine.dialect.DBType() != core.ORACLE {
if dialect.DBType() != core.MSSQL && 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 {
} else if 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)
}
}
if statement.IsForUpdate {
a = statement.Engine.dialect.ForUpdateSql(a)
a = dialect.ForUpdateSql(a)
}
return