parent
4ce90f9a62
commit
1eee8a367e
|
@ -177,6 +177,14 @@ func (engine *Engine) QuoteStr() string {
|
||||||
return engine.dialect.QuoteStr()
|
return engine.dialect.QuoteStr()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (engine *Engine) quoteColumns(columnStr string) string {
|
||||||
|
columns := strings.Split(columnStr, ",")
|
||||||
|
for i := 0; i < len(columns); i++ {
|
||||||
|
columns[i] = engine.Quote(strings.TrimSpace(columns[i]))
|
||||||
|
}
|
||||||
|
return strings.Join(columns, ",")
|
||||||
|
}
|
||||||
|
|
||||||
// Quote Use QuoteStr quote the string sql
|
// Quote Use QuoteStr quote the string sql
|
||||||
func (engine *Engine) Quote(value string) string {
|
func (engine *Engine) Quote(value string) string {
|
||||||
value = strings.TrimSpace(value)
|
value = strings.TrimSpace(value)
|
||||||
|
|
|
@ -135,7 +135,7 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{})
|
||||||
if session.statement.JoinStr == "" {
|
if session.statement.JoinStr == "" {
|
||||||
if columnStr == "" {
|
if columnStr == "" {
|
||||||
if session.statement.GroupByStr != "" {
|
if session.statement.GroupByStr != "" {
|
||||||
columnStr = session.statement.Engine.Quote(strings.Replace(session.statement.GroupByStr, ",", session.engine.Quote(","), -1))
|
columnStr = session.engine.quoteColumns(session.statement.GroupByStr)
|
||||||
} else {
|
} else {
|
||||||
columnStr = session.statement.genColumnStr()
|
columnStr = session.statement.genColumnStr()
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ func (session *Session) find(rowsSlicePtr interface{}, condiBean ...interface{})
|
||||||
} else {
|
} else {
|
||||||
if columnStr == "" {
|
if columnStr == "" {
|
||||||
if session.statement.GroupByStr != "" {
|
if session.statement.GroupByStr != "" {
|
||||||
columnStr = session.statement.Engine.Quote(strings.Replace(session.statement.GroupByStr, ",", session.engine.Quote(","), -1))
|
columnStr = session.engine.quoteColumns(session.statement.GroupByStr)
|
||||||
} else {
|
} else {
|
||||||
columnStr = "*"
|
columnStr = "*"
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,6 +268,15 @@ func TestOrder(t *testing.T) {
|
||||||
fmt.Println(users2)
|
fmt.Println(users2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGroupBy(t *testing.T) {
|
||||||
|
assert.NoError(t, prepareEngine())
|
||||||
|
assertSync(t, new(Userinfo))
|
||||||
|
|
||||||
|
users := make([]Userinfo, 0)
|
||||||
|
err := testEngine.GroupBy("id, username").Find(&users)
|
||||||
|
assert.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
func TestHaving(t *testing.T) {
|
func TestHaving(t *testing.T) {
|
||||||
assert.NoError(t, prepareEngine())
|
assert.NoError(t, prepareEngine())
|
||||||
assertSync(t, new(Userinfo))
|
assertSync(t, new(Userinfo))
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (session *Session) genQuerySQL(sqlorArgs ...interface{}) (string, []interfa
|
||||||
if session.statement.JoinStr == "" {
|
if session.statement.JoinStr == "" {
|
||||||
if columnStr == "" {
|
if columnStr == "" {
|
||||||
if session.statement.GroupByStr != "" {
|
if session.statement.GroupByStr != "" {
|
||||||
columnStr = session.statement.Engine.Quote(strings.Replace(session.statement.GroupByStr, ",", session.engine.Quote(","), -1))
|
columnStr = session.engine.quoteColumns(session.statement.GroupByStr)
|
||||||
} else {
|
} else {
|
||||||
columnStr = session.statement.genColumnStr()
|
columnStr = session.statement.genColumnStr()
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ func (session *Session) genQuerySQL(sqlorArgs ...interface{}) (string, []interfa
|
||||||
} else {
|
} else {
|
||||||
if columnStr == "" {
|
if columnStr == "" {
|
||||||
if session.statement.GroupByStr != "" {
|
if session.statement.GroupByStr != "" {
|
||||||
columnStr = session.statement.Engine.Quote(strings.Replace(session.statement.GroupByStr, ",", session.engine.Quote(","), -1))
|
columnStr = session.engine.quoteColumns(session.statement.GroupByStr)
|
||||||
} else {
|
} else {
|
||||||
columnStr = "*"
|
columnStr = "*"
|
||||||
}
|
}
|
||||||
|
|
|
@ -933,7 +933,7 @@ func (statement *Statement) genGetSQL(bean interface{}) (string, []interface{},
|
||||||
if len(statement.JoinStr) == 0 {
|
if len(statement.JoinStr) == 0 {
|
||||||
if len(columnStr) == 0 {
|
if len(columnStr) == 0 {
|
||||||
if len(statement.GroupByStr) > 0 {
|
if len(statement.GroupByStr) > 0 {
|
||||||
columnStr = statement.Engine.Quote(strings.Replace(statement.GroupByStr, ",", statement.Engine.Quote(","), -1))
|
columnStr = statement.Engine.quoteColumns(statement.GroupByStr)
|
||||||
} else {
|
} else {
|
||||||
columnStr = statement.genColumnStr()
|
columnStr = statement.genColumnStr()
|
||||||
}
|
}
|
||||||
|
@ -941,7 +941,7 @@ func (statement *Statement) genGetSQL(bean interface{}) (string, []interface{},
|
||||||
} else {
|
} else {
|
||||||
if len(columnStr) == 0 {
|
if len(columnStr) == 0 {
|
||||||
if len(statement.GroupByStr) > 0 {
|
if len(statement.GroupByStr) > 0 {
|
||||||
columnStr = statement.Engine.Quote(strings.Replace(statement.GroupByStr, ",", statement.Engine.Quote(","), -1))
|
columnStr = statement.Engine.quoteColumns(statement.GroupByStr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue