Fix to add session.statement.IsForUpdate check in Session.queryRows() (#2064)

# Issue
The 'for-update' query is executed to slave DB node.

# Example

```go
s := engineGroup.NewSession(); // create session from EngineGroup.
...

s.ForUpdate();

type User struct { ... };
var user User;
has, err := s.Get(&user); // executed to slave DB node.
...
```

Co-authored-by: rennnosuke <rennnosuke@noreply.gitea.io>
Co-authored-by: RenKanai <turutekab@gmail.com>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/xorm/xorm/pulls/2064
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: RenKanai <rennnosuke@noreply.gitea.io>
Co-committed-by: RenKanai <rennnosuke@noreply.gitea.io>
This commit is contained in:
RenKanai 2021-11-24 10:29:39 +08:00 committed by Lunny Xiao
parent f35ff7c2eb
commit 885f582677
1 changed files with 1 additions and 1 deletions

View File

@ -33,7 +33,7 @@ func (session *Session) queryRows(sqlStr string, args ...interface{}) (*core.Row
if session.isAutoCommit {
var db *core.DB
if session.sessionType == groupSession && strings.EqualFold(strings.TrimSpace(sqlStr)[:6], "select") {
if session.sessionType == groupSession && strings.EqualFold(strings.TrimSpace(sqlStr)[:6], "select") && !session.statement.IsForUpdate {
db = session.engine.engineGroup.Slave().DB()
} else {
db = session.DB()