Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does insert script using cx_Oracle hangs

Tags:

python

oracle

I'm new to Python, using cx_Oracle.execute to insert a row into a table.

I prepare the insert statement, which works on SQL developer.

print statements prior to the execute indicate it hangs on execute. A simple select statement works using the same package.

  • Python version is 2.7
  • Oracle version is 11g
  • cx_Oracle version is 5.2.1
  • Eclipse is 4.4.2
  • Pydev is 4.5.5

I have tried this on Anaconda as well, same result.

import cx_Oracle

Connection = cx_Oracle.connect('connectioninfo')
cursor = connection.cursor()
print(cx_Oracle.__file__) 
print(cx_Oracle._version)

sql1 = "insert into date_dim(dateid) values (20170523)"
print(sql1)
cursor.execute(sql1) # hangs here 
count = cursor.rowcount 

print(count)
connection.commit() # Never gets to this statement        
cursor.close()
connection.close()
like image 506
Dman Avatar asked May 25 '17 15:05

Dman


People also ask

What is the use of cx_Oracle?

cx_Oracle is a Python extension module that enables access to Oracle Database. It conforms to the Python database API 2.0 specification with a considerable number of additions and a couple of exclusions. cx_Oracle 8.3 was tested with Python versions 3.6 through 3.10.

Is cx_Oracle open source?

cx_Oracle is distributed under an open-source license (the BSD license). A detailed description of cx_Oracle changes can be found in the release notes.


1 Answers

It looks like I had another session open on Sql Developer to test the insert script where I never run a Commit so when I run the Python insert script, somehow it was hanging waiting for the other commit to be issued so it can issue its own commit which was the next line in the code but the other commit was never issued in Sql Developer! As soon as I run a commit in Sql Developer, Python completed the insert. What do you know? Posted my first question on Stackoverflow and my first answer to my first question, that's gotta be a first!

like image 198
Dman Avatar answered Sep 20 '22 06:09

Dman