ibmdb / node-ibm_db

IBM DB2 and IBM Informix bindings for node
MIT License
188 stars 151 forks source link

Stop query while running #867

Closed Colucho closed 2 years ago

Colucho commented 2 years ago

Hi, i would need to stop a query that takes a lot of time.

How can i stop the query before ended?

Thanks

var ibmdb = require("ibm_db"), cn = "DATABASE=dbname;HOSTNAME=hostname;PORT=port;PROTOCOL=TCPIP;UID=dbuser;PWD=xxx";

ibmdb.open(cn, function (err, db) {
    if (err) {
        return console.log(err);
    }
    console.log("Connection opened successfully.");
    db.query("SELECT ... FROM ..."); //Its takes a lot of time
    db.close(function (error) { //Its is called after query end
    if (error) {
        console.log("Error while closing connection,", error);
        return;
    }else{
        console.log("Connection clossed successfully.");
    }
    });
});
bimalkjha commented 2 years ago

@Colucho You can add "QueryTimeout=30;" in connection string to cancel the query execution after 30 seconds. For more info about this keyword, check this doc. Thanks.

Colucho commented 2 years ago

@bbigras thanks for your answer.

It wouldn't solve my problem. That will make it impossible to execute queries of more than 30 seconds.

I will try to explain better. I can have queries of a few seconds or several minutes. I would need to cancel or destroy the query whenever I want.

For instance: I execute a query that takes 2 minutes. After 20 seconds or x seconds, I want to stop it or destroy it. (before query ends) would that be possible?

Thanks again

bimalkjha commented 2 years ago

@Colucho No that is not possible. You have to kill the running application and restart it. Thanks.