Merge pull request #5256 from flycash/develop

fix 5255: Check the rows.Err() if rows.Next() is false
This commit is contained in:
Ming Deng 2023-06-20 16:58:52 +08:00 committed by GitHub
commit bc7f6ffa1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 10 deletions

View File

@ -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)

View File

@ -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.

View File

@ -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.

View File

@ -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)

View File

@ -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