473,387 Members | 1,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Python cx_Oracle Interfcae issue

cpiyush
31
Hi,

I am using Oracle 9i & Python.
The interface is cx_Oracle4.3

I was tryingto fire the following query using this interface: -

cursor.execute("""describe employee""")

& got error CHECK YOUR SQL SYNTAX. Although its working fine when i am firing it from SQL*Plus.

Isn't it support this query or I am missing something.

Btw I was using this query to get all the field names & field types.
I got field names using cursor.description command, but it is converting the field type into some other names like VARCHAR2--->STRING.

Kindly guide me.

Thanks & Regards,
Piyush.
Apr 20 '07 #1
5 2821
bartonc
6,596 Expert 4TB
Hi,

I am using Oracle 9i & Python.
The interface is cx_Oracle4.3

I was tryingto fire the following query using this interface: -

cursor.execute("""describe employee""")

& got error CHECK YOUR SQL SYNTAX. Although its working fine when i am firing it from SQL*Plus.

Isn't it support this query or I am missing something.

Btw I was using this query to get all the field names & field types.
I got field names using cursor.description command, but it is converting the field type into some other names like VARCHAR2--->STRING.

Kindly guide me.

Thanks & Regards,
Piyush.
If you post the actuall code, we'll be able to help you spot things like typos and see if you are trying to do something like
Expand|Select|Wrap|Line Numbers
  1. t = type(dbVar)
which will always be an str type for any character type in python.
Apr 20 '07 #2
cpiyush
31
If you post the actuall code, we'll be able to help you spot things like typos and see if you are trying to do something like
Expand|Select|Wrap|Line Numbers
  1. t = type(dbVar)
which will always be an str type for any character type in python.
My code is something like this..
Expand|Select|Wrap|Line Numbers
  1. import cx_Oracle
  2.  
  3.  
  4. #Establishing Connection string using makedsn() function.
  5.  
  6. host = 'localhost' 
  7. port = 1521 
  8. dbase = 'Sample' 
  9. login = 'demo' 
  10. passwrd = 'demo' 
  11. dsn = cx_Oracle.makedsn(host, port, dbase) 
  12. connection = cx_Oracle.connect(login, passwrd, dsn) 
  13. print "********", connection
  14.  
  15. cursor = connection.cursor()
  16. cursor.arraysize = 50
  17. cursor.execute("""describe tab1""")
  18.  
  19.  
  20. fields=[]
  21. for row in cursor.description:
  22.     fields.append(row[1])
  23. print fields
  24.  
  25.  
I Think this quesry should return tuples equal to total number of fields in the table in the format (field name, field type). But its not working.
Apr 23 '07 #3
bartonc
6,596 Expert 4TB
My code is something like this..
Expand|Select|Wrap|Line Numbers
  1. import cx_Oracle
  2.  
  3.  
  4. #Establishing Connection string using makedsn() function.
  5.  
  6. host = 'localhost' 
  7. port = 1521 
  8. dbase = 'Sample' 
  9. login = 'demo' 
  10. passwrd = 'demo' 
  11. dsn = cx_Oracle.makedsn(host, port, dbase) 
  12. connection = cx_Oracle.connect(login, passwrd, dsn) 
  13. print "********", connection
  14.  
  15. cursor = connection.cursor()
  16. cursor.arraysize = 50
  17. cursor.execute("""describe tab1""")
  18.  
  19.  
  20. fields=[]
  21. for row in cursor.description:
  22.     fields.append(row[1])
  23. print fields
  24.  
  25.  
I Think this quesry should return tuples equal to total number of fields in the table in the format (field name, field type). But its not working.
I'll bet you anything (although I don't use oracle, it looks like it comforms to the db api 2.0) the result is in cusrsor.fetchall() not cursor.description.

Use lots of print statements to see what you are getting back (but you knew that, right).
Apr 23 '07 #4
cpiyush
31
I'll bet you anything (although I don't use oracle, it looks like it comforms to the db api 2.0) the result is in cusrsor.fetchall() not cursor.description.

Use lots of print statements to see what you are getting back (but you knew that, right).
Yes you are right Bartonc, but the interface's compilre is giving arror at the cursor.execure("""describe tab1""") line, its saying check your sql syntax... All the other queries aree running fine except this one.

I am running this to get the field type of the table, this was not working thats y I used cursor.describe method, If u can suggest me any other way for my basic problem(how to get field types using this inteface) then plz tell me.

Thanks.
Apr 23 '07 #5
bartonc
6,596 Expert 4TB
Yes you are right Bartonc, but the interface's compilre is giving arror at the cursor.execure("""describe tab1""") line, its saying check your sql syntax... All the other queries aree running fine except this one.

I am running this to get the field type of the table, this was not working thats y I used cursor.describe method, If u can suggest me any other way for my basic problem(how to get field types using this inteface) then plz tell me.

Thanks.
A sql syntax error makes this more of an Oracle question. Try asking about the query (not the interface) on the Oracle Forum if you haven't done that already.

but first try
Expand|Select|Wrap|Line Numbers
  1. DESCRIBE TABLE TableName
Apr 23 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Emile van Sebille | last post by:
QOTW (advanced interfaces track): "I'm firmly in favour of any language that can DWIMNWIS." -- Tim Delaney QOTW (MS roadkill track): "Underestimate MS at your own risk. It is one thing to not...
1
by: Maxim Kuleshov | last post by:
Hello! Trying to fetch long varchar2 column and get the following error: cx_Oracle.DatabaseError: column at array pos 0 fetched with error: 1406 i.e. string buffer is not much enough to...
7
by: vb_bv | last post by:
Does Pyton PL/SQL programming language of Oracle support? Thx
4
by: hot.favorite | last post by:
Hi, I'm fairly new to Python so please pardon any dumbness on my part. I plan to write an app in Python that will run on Linux and would need to connect to Oracle and MySQL. I could use...
17
by: dananrg | last post by:
I'm a little confused about what's out there for database modules at: http://python.org/topics/database/modules.html What I'd like to do is use Python to access an Oracle 9.X database for...
0
by: cirudinezidane | last post by:
Hi!! I'd like to install Oracle 10 g express edition over Ubuntu to use with Python 2.4. I have installed Ubuntu, Python 2.4 and Oracle database. I think that I have installed correctly...
0
by: M.-A. Lemburg | last post by:
On 2008-04-30 18:42, Sean Ryan wrote: The -v option only causes Python to print more information to stderr explaining where it is looking for modules. You should be seeing any dynamic loader...
3
by: Raja | last post by:
Hi, I am trying to write a cgi program which would be executed on browser with Apache server installed. The program would make a connection to a database using cx_Oracle module and display...
0
by: harshakusam | last post by:
Hi All, In my python script i use to run some oracle queries for this i require a library to connect to oracle which is cx_Oracle. When we were using 9i(oracle).. my script was running fine.....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.