pip-services3-go / pip-services3-postgres-go

Postresql components for Pip.Services in Golang
MIT License
0 stars 0 forks source link

Total references select instead of filter to get the WHERE clause #8

Closed antonio-alexander closed 2 years ago

antonio-alexander commented 2 years ago

https://github.com/pip-services3-go/pip-services3-postgres-go/blob/34afd39ad7c36b46b0a11380b040185443d9709a/persistence/PostgresPersistence.go#L658

This is related to the previous issue, as coded, this will always fail (unless the sel/select string is provided) which will cause the total to be the total elements in the table rather than the total number of elements actually returned. Should be a quick fix:

    if pagingEnabled {
        query := "SELECT COUNT(*) AS count FROM " + c.QuotedTableName()
        if filter != nil {
            if flt, ok := filter.(string); ok && flt != "" {
                query += " WHERE " + flt
            }
        }

        qResult2, qErr2 := c.Client.Query(context.TODO(), query)
        if qErr2 != nil {
            return nil, qErr2
        }
        defer qResult2.Close()
        var count int64 = 0
        if qResult2.Next() {
            rows, _ := qResult2.Values()
            if len(rows) == 1 {
                count = cconv.LongConverter.ToLong(rows[0])
            }
        }
        page = cdata.NewDataPage(&count, items)
        return page, qResult2.Err()
    }
levichevdmitry commented 2 years ago

Hi @antonio-alexander, thank you for report! I fixed and made new release, please update you dependencies v1.2.9

antonio-alexander commented 2 years ago

Sorry for the late reply. @levichevdmitry I was able to integrate the change and confirm it works as expected. Thanks for the quick fix!

levichevdmitry commented 2 years ago

No worries, your feedback always in time :) You always help us to make our toolkit more usable and better! Thanks!