Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In Django when i passed a query to insert a row, in Oracle Db the row is being inserted twice in the table

@api_view(['PUT'])
def updateRule1(request, id):
    nums15 = 'OK'
    json_data = json.loads(request.body)
    # print(json_data)
    con = None
    cur = None

    try:
        con = cx_Oracle.connect('<server connection details>')
        cur = con.cursor()
    except cx_Oracle.DatabaseError as e:
        print("Problem establishing connection with Oracle DB", e)

    q = "INSERT INTO XXMSE.RE_PREDICATE (RULE_ID, PREDICATE_ID, INPUT_VALUE_ID1,  
         MATHEMATICAL_VALUE, INPUT_VALUE_ID2, BOOLEAN_OPERATOR) VALUES 
         ('1','2','2000000','equals','30000000','None')"
    print(q)
    sql5 = cur.execute(q)
    cur.execute(sql5)
    con.commit()

    if cur:
        cur.close()
    if con:
        con.close()    
    
    return Response(nums15)

DB screenshot
|ID |Idx|Value_1 |Operator|Value_2 |Boolean |
|—|—|———-|——–|———–|——–|
|1 |1 |1 |equals |2 |AND |
|1 |2 |2000000 |equals |30000000 |None |
|1 |2 |2000000 |equals |30000000 |None |

I see that there are 2 rows inserted into the DB.
Django version is 4.1.1

What would be the reason for duplicate rows? Appreciate your help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I used breakpoint() and made sure that api is called getting once.There is no duplicate entries in the backend.

>Solution :

you call twice cur.execute(...). Not sure what you want to do with that, but I think the twice entries come from this lines probably

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading