Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A used stmt can not get result by get() when there is no parameter #1743

Open
JiaJiaJiang opened this issue Jan 1, 2024 · 0 comments
Open
Labels

Comments

@JiaJiaJiang
Copy link

JiaJiaJiang commented Jan 1, 2024

Issue Summary

I created a stmt instance by db.prepare, then I found the 'get' method of stmt cannot return correct result but undefined after the first time it was called when there is no parameter for this method.

I think this bug is caused by the if condition here:

if (stmt->status != SQLITE_DONE || baton->parameters.size()) {

Steps to Reproduce

const sqlite3 = require('sqlite3');
function promiseify(fn) {
    return function (...args) {
        return new Promise((resolve, reject) => {
            fn(...args, (err, res) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(res);
                }
            });
        });
    };
}
const db = new sqlite3.Database(':memory:');
(async () => {
    //no parameter test
    const stmt = await db.prepare('select 1'); //simply select 1 here
    const get = promiseify((cb) => {
        return stmt.get(cb);
    });
    console.log(await get()); //print { '1': 1 }
    console.log(await get()); //print undefined
    console.log(await get()); //print undefined
    //You can see the `get` method won't return a result from the second call.

    //1 parameter test
    const stmt2 = await db.prepare('select 1+?'); 
    const get2 = promiseify((arg,cb) => {
        return stmt2.get(arg,cb);
    });
    console.log(await get2(1)); //print { '1+?': 2 }
    console.log(await get2(2)); //print { '1+?': 3 }
    console.log(await get2(3)); //print { '1+?': 4 }
    //it returns correctly when there have parameter
})();

Version

5.1.6

Node.js Version

v18.17.0

How did you install the library?

npm i, on windows

@JiaJiaJiang JiaJiaJiang added the bug label Jan 1, 2024
@JiaJiaJiang JiaJiaJiang changed the title A used stmt can not get result when there is no parameter A used stmt can not get result by get() when there is no parameter Jan 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant