Fix new-lined query execution in master DB node. (#2066)
# Issue
Such a following query is executed in master DB node with EngineGroup.
```go
s := engineGroup.NewSession(); // create session from EngineGroup.
sql := `
SELECT * FROM USER;
`;
type User struct { ... };
var users []User;
err := s.Sql(sql).Find(&users); // executed to master DB node.
```
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2066
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: rennnosuke <rennnosuke@noreply.gitea.io>
Co-committed-by: rennnosuke <rennnosuke@noreply.gitea.io>
This commit is contained in:
parent
40a135948b
commit
26f9d619cc
|
|
@ -33,7 +33,7 @@ func (session *Session) queryRows(sqlStr string, args ...interface{}) (*core.Row
|
||||||
|
|
||||||
if session.isAutoCommit {
|
if session.isAutoCommit {
|
||||||
var db *core.DB
|
var db *core.DB
|
||||||
if session.sessionType == groupSession && strings.EqualFold(sqlStr[:6], "select") {
|
if session.sessionType == groupSession && strings.EqualFold(strings.TrimSpace(sqlStr)[:6], "select") {
|
||||||
db = session.engine.engineGroup.Slave().DB()
|
db = session.engine.engineGroup.Slave().DB()
|
||||||
} else {
|
} else {
|
||||||
db = session.DB()
|
db = session.DB()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue