question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty error when 0 rows updated

See original GitHub issue

First of all thank you a lot for all the support and implementation of this module. Great work!

However I faced a bug and decided to share my thoughts about it with you.

So, the following code:

"use strict";

const odbc = require("odbc");

odbc.connect("Dsn=example;Uid=example;Pwd=example;", function (err, connection) {
    if (err) {
        return console.error(err);
    }
    connection.query("UPDATE some_entity SET value = 10000 WHERE book = (SELECT id FROM books WHERE name = 'Best book of the world')", function (error, results) {
        if (error) {
            return console.error(error);
        }
        console.log(results);
    });
});

Shows the following output on the terminal: [Error: "errors": []]

This error is shown when I execute an UPDATE query that the WHERE criteria does not match any rows, if it matches at least 1 row, there’s no error… I don’t know if this is the correct behaviour although I don’t agree it should be. Imagine the following situation: I want to execute an UPDATE, and if no rows were updated on that same query, I want to be able to execute an INSERT query instead.

Currently using version 2.0.0-4.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
markdirishcommented, Aug 30, 2019

I think the issue is probably that the query is returning SQL_NO_DATA, which isn’t passing the error check (which is only passing on SQL_SUCCESS and SQL_SUCCESS_WITH_INFO). I actually found this same bug this morning and I am hoping to remedy for the next release.

0reactions
markdirishcommented, Apr 19, 2022

Going to mark as closed, a lot of development since the last update and I just tried on my Db2 for i ODBC connection. For both update and delete where 0 rows were affected, the query ran fine and produced no errors.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mySQL UPDATE query returns "0 rows affected"
If the column you want to update is an integer or boolean, and you set it to a string, it won't be updated...
Read more >
Question about 0 rows updated when there should have been 1
So, the error "0 rows updated when there should have been 1" is the result of a INSERT or UPDATE which had zero...
Read more >
How to fail a transaction when update affected 0 rows #77
I can detect zero row update using .result, but I don't know how to do ... rowCount) { // 1. throw new Error("Ops,...
Read more >
Bulk Insert giving no error but 0 rows affected
UPDATE - It is clearly someting at the very end of the file. If I set the LASTROW = 500 it will import...
Read more >
Update Statement and Exception Handling - Ask TOM
There are NO exceptions when 0 rows are updated-- that is NOT an error. If is the right way to catch that. 2)...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found