Gorm: Logging tracer always report 0 affected row when using Raw(..)

Created on 1 Sep 2020  路  8Comments  路  Source: go-gorm/gorm

GORM Playground Link

https://github.com/go-gorm/playground/pull/101

Description

When I'm using Raw(...) for query raw sql, logger always report there is 0 returned, while it's actually not.

You could see the last failure expectation in PR

This could lead to misbehavior when monitor sql log

with reproduction steps

All 8 comments

When you are querying with Rows,Row, GORM can't get the affected row ;(

But RowsAffected should works when use Raw with Scan

@jinzhu The problem here is tracer provides wrong info (returned rows), this could lead to misbehavior when monitor sql logging (in logger I have no idea how to detect sql query is called from Raw or from Scan/Find method.

Anw, thank you for your suggestion, I will change to use Scan instead of Rows for my monitoring. However, I still think this is a bug

@jinzhu The problem here is tracer provides wrong info (returned rows), this could lead to misbehavior when monitor sql logging (in logger I have no idea how to detect sql query is called from Raw or from Scan/Find method.

What I only can do it change it to -1 for Row, Rows, Exec, but not sure if it is good.... maybe we can visit it later to see if other people have similar questions.

Wow, I spent a good deal of time wondering why my perfectly formed query was returning zero rows. This is a bug, agree with @pvhau

The tracer still doesn't return correct number of rows. :( My statement is of the following structure:

db.Table().Select().Joins().Where().Scan()

@sashankaryal Because issue was closed, I think you should create another issue with playground and ref to this to re-open issue. May be @jinzhu missed out you comments

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hypertornado picture hypertornado  路  3Comments

corvinusy picture corvinusy  路  3Comments

superwf picture superwf  路  3Comments

fieryorc picture fieryorc  路  3Comments

littletwolee picture littletwolee  路  3Comments