xdenser / node-firebird-libfbclient

Firebird SQL binding
MIT License
82 stars 34 forks source link

do I need to check eof? #132

Closed sqllyw closed 2 years ago

sqllyw commented 2 years ago

Hi,

got class method as follow:

 get_list_tx(tx, sql, recs_num = -1) {
        return new Promise((resolve, reject) => {
            let ret = [];
            let num = recs_num == -1 ? 'all' : recs_num;
            tx.query(sql, (err, res) => {
                if (err)
                    reject(err);
                else {
                    res.fetch(num, true, (row) => {
                        ret.push(row);
                    }, (err, eof) => {
                        console.log("err, eof");
                        console.log(err, eof);
                        if (err)
                            reject(err);
                        else if (eof)  // sometimes this is false
                            resolve(ret);
                    });
                }
            });
        });
    }

do I have to do a if (eof) ? sometimes eof is false while err is null, when the recs_num is 1

xdenser commented 2 years ago

for example: res may have 10 records, you ask for 1 then eof == false, if you ask for 10 then eof == true

sqllyw commented 2 years ago

Thanks for the clarification, example:

 let sql = "select * from country where country = 'USA'";

the res will have only one record, but eof might differ:

if you pass 1 to res.fetch(1...) eof will always be false, if you pass res.fetch('all'...) eof will be true

is this the correct understanding?

as long as more than 1 even the res has only one record