diff --git a/CHANGELOG.md b/CHANGELOG.md index 87f669be..b1f27115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - [httplib: fix unstable unit test which use the httplib.org](https://github.com/beego/beego/pull/5232) - [remove adapter package](https://github.com/beego/beego/pull/5239) - [feat: add write-delete cache mode](https://github.com/beego/beego/pull/5242) +- [fix 5255: Check the rows.Err() if rows.Next() is false](https://github.com/beego/beego/pull/5256) ## ORM refactoring - [introducing internal/models pkg](https://github.com/beego/beego/pull/5238) diff --git a/client/orm/db.go b/client/orm/db.go index e4b53e36..0b3cfb80 100644 --- a/client/orm/db.go +++ b/client/orm/db.go @@ -884,6 +884,10 @@ func (d *dbBase) DeleteBatch(ctx context.Context, q dbQuerier, qs *querySet, mi cnt++ } + if err = rs.Err(); err != nil { + return 0, err + } + if cnt == 0 { return 0, nil } @@ -1123,6 +1127,10 @@ func (d *dbBase) ReadBatch(ctx context.Context, q dbQuerier, qs *querySet, mi *m cnt++ } + if err = rs.Err(); err != nil { + return 0, err + } + if !one { if cnt > 0 { ind.Set(slice) @@ -1769,6 +1777,10 @@ func (d *dbBase) ReadValues(ctx context.Context, q dbQuerier, qs *querySet, mi * cnt++ } + if err = rs.Err(); err != nil { + return 0, err + } + switch v := container.(type) { case *[]Params: *v = maps @@ -1847,7 +1859,7 @@ func (d *dbBase) GetTables(db dbQuerier) (map[string]bool, error) { } } - return tables, nil + return tables, rows.Err() } // GetColumns get all cloumns in table. @@ -1874,7 +1886,7 @@ func (d *dbBase) GetColumns(ctx context.Context, db dbQuerier, table string) (ma columns[name] = [3]string{name, typ, null} } - return columns, nil + return columns, rows.Err() } // not implement. diff --git a/client/orm/db_sqlite.go b/client/orm/db_sqlite.go index e353404e..8041f7be 100644 --- a/client/orm/db_sqlite.go +++ b/client/orm/db_sqlite.go @@ -136,7 +136,7 @@ func (d *dbBaseSqlite) GetColumns(ctx context.Context, db dbQuerier, table strin columns[name.String] = [3]string{name.String, typ.String, null.String} } - return columns, nil + return columns, rows.Err() } // get show Columns sql in sqlite. diff --git a/client/orm/filter.go b/client/orm/filter.go index bc13c3fa..cd313761 100644 --- a/client/orm/filter.go +++ b/client/orm/filter.go @@ -22,12 +22,12 @@ import ( // don't forget to call next(...) inside your Filter type FilterChain func(next Filter) Filter -// Filter's behavior is a little big strange. +// Filter behavior is a little big strange. // it's only be called when users call methods of Ormer // return value is an array. it's a little bit hard to understand, // for example, the Ormer's Read method only return error // so the filter processing this method should return an array whose first element is error -// and, Ormer's ReadOrCreateWithCtx return three values, so the Filter's result should contains three values +// and, Ormer's ReadOrCreateWithCtx return three values, so the Filter's result should contain three values type Filter func(ctx context.Context, inv *Invocation) []interface{} var globalFilterChains = make([]FilterChain, 0, 4) diff --git a/client/orm/orm_raw.go b/client/orm/orm_raw.go index d1b1d0a7..2f811c65 100644 --- a/client/orm/orm_raw.go +++ b/client/orm/orm_raw.go @@ -447,7 +447,7 @@ func (o *rawSet) QueryRow(containers ...interface{}) error { return nil } -// query data rows and map to container +// QueryRows query data rows and map to container func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) { var ( refs = make([]interface{}, 0, len(containers)) @@ -504,7 +504,6 @@ func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) { sInd := sInds[0] for rows.Next() { - if structMode { columns, err := rows.Columns() if err != nil { @@ -597,16 +596,18 @@ func (o *rawSet) QueryRows(containers ...interface{}) (int64, error) { sInd = reflect.Append(sInd, ind) } else { - if err := rows.Scan(refs...); err != nil { + if err = rows.Scan(refs...); err != nil { return 0, err } - o.loopSetRefs(refs, sInds, &nInds, eTyps, cnt == 0) } - cnt++ } + if err = rows.Err(); err != nil { + return 0, err + } + if cnt > 0 { if structMode { sInds[0].Set(sInd) @@ -734,6 +735,10 @@ func (o *rawSet) readValues(container interface{}, needCols []string) (int64, er cnt++ } + if err = rs.Err(); err != nil { + return 0, err + } + switch v := container.(type) { case *[]Params: *v = maps @@ -849,6 +854,9 @@ func (o *rawSet) queryRowsTo(container interface{}, keyCol, valueCol string) (in cnt++ } + if err = rs.Err(); err != nil { + return 0, err + } if typ == 1 { v, _ := container.(*Params) *v = maps