Node-oracledb: Problem when I execute Update query

Created on 21 Nov 2020  路  4Comments  路  Source: oracle/node-oracledb

node version: v15.2.0
oracledb version: 5.0.0
oracle: 18c

I have a problem when I execute an update query, this query work in SqlDeveloper.

The query doesn't pass the execute().

this is output in the terminal:

Escuchando el puerto:  3000
PUT RESERVA
0
id:  21
1
2

this is my code:

app.put('/reserva', async(req, res) => {
    console.log('PUT RESERVA');

    let connection;

    let step = 0;
    console.log(step);
    console.log('id: ', req.body.id);
    try {
        step = 1;
        console.log(step);
        connection = await oracledb.getConnection({
            user: 'matias',
            password: '123',
            connectString: "localhost:1521/XE"
        });
        step = 2;
        console.log(step);
        result = await connection.execute(
            `UPDATE DEPARTAMENTO DP SET DP.disponibilidad = 0 WHERE DP.id_departamento = :id`, {
                id: req.body.id
            }, { autoCommit: true }
        );
        step = 3;
        console.log(step);
        res.json(result);

    } catch (err) {
        console.error(err, 'paso: ', step);
    } finally {
        if (connection) {
            try {
                console.log('cerrar conexion');
                await connection.close();
            } catch (err) {
                console.error(err, 'paso: ', step);
            }
        }
    }
});
question

All 4 comments

Change res.json(result); to console.log(result); and check it displays what you want. After that, you'll need to do whatever transform is needed to get the results in a form usable by your app front end.

Also check out https://github.com/oracle/node-oracledb/blob/master/examples/webapp.js

but it never gets there, look the outputs only display until step 2.

Make sure there are no locks on that row from your tests in SQL Developer. Do a commit or rollback in SQL Developer.

If that doesn't help, then copy the query logic to a script that doesn't involve a web server. Hard code the input value for id. Run that. And show us the code.

Thanks bro, with rollback, it worked for me!

Was this page helpful?
0 / 5 - 0 ratings