从使用Oracle Database上的节点JS删除
我不知不觉地发送了两次请求,并带有相同的插入查询,这导致了两次添加的相同记录。现在,当我尝试使用删除语句时,它正在显示“发送请求”,并且没有向前发展。
但是,如果我尝试n删除任何其他记录,则删除语句正在工作,没有重复的值。例如- 如果我尝试在记录上使用请求1001的删除语句,则它不起作用,因为有2个带有相同request_id的记录。 但是,如果我尝试使用请求ID 1002删除记录,则可以正常工作。
这是我的代码 -
var express=require('express');
var router=express.Router();
var oracledb=require('oracledb');
router.post('/ins-rpt',function(req,res,next){
//get the data from req
const {stat,rid,rptcomp,reqr}=req.body;
//connect with db
var connectionString="(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SERVER
= DEDICATED)(SERVICE_NAME = orcl))"
oracledb.getConnection(
{
user: 'system',
password:'Valli1234',
tns:connectionString
}, async function(err,con){
if(err){
res.status(500).json({
message : 'not connected'
})
}
else{
//reqd opn
var q="delete from rpt where request_id=:1";
//send response
await con.execute(q,[],
{autoCommit:true},function(e,s){
if(e){
res.status(500).json({
message : e
})
}
else
{
res.status(200).json({
message : s
})
}
})
}
});
})
module.exports=router;
I unknowingly sent a request twice with the same insert query which led to the same record being added twice. now when I'm trying to use the delete statement it's showing 'sending request' and is not moving forward.
but the delete statement is working if I try n delete any other record with does not have duplicate values. eg-
if I try using the delete statement on the record having request 1001, it isn't working, as there are 2 records with the same request_id.
but if I try to delete the record with the request id 1002, its working.
this is my code-
var express=require('express');
var router=express.Router();
var oracledb=require('oracledb');
router.post('/ins-rpt',function(req,res,next){
//get the data from req
const {stat,rid,rptcomp,reqr}=req.body;
//connect with db
var connectionString="(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)
(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SERVER
= DEDICATED)(SERVICE_NAME = orcl))"
oracledb.getConnection(
{
user: 'system',
password:'Valli1234',
tns:connectionString
}, async function(err,con){
if(err){
res.status(500).json({
message : 'not connected'
})
}
else{
//reqd opn
var q="delete from rpt where request_id=:1";
//send response
await con.execute(q,[],
{autoCommit:true},function(e,s){
if(e){
res.status(500).json({
message : e
})
}
else
{
res.status(200).json({
message : s
})
}
})
}
});
})
module.exports=router;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论