从使用Oracle Database上的节点JS删除

发布于 2025-02-11 15:10:26 字数 1722 浏览 0 评论 0原文

我不知不觉地发送了两次请求,并带有相同的插入查询,这导致了两次添加的相同记录。现在,当我尝试使用删除语句时,它正在显示“发送请求”,并且没有向前发展。

但是,如果我尝试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.
enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文