Python cx_Oracle Interfcae issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cpiyush
    New Member
    • Jan 2007
    • 31

    Python cx_Oracle Interfcae issue

    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.descript ion command, but it is converting the field type into some other names like VARCHAR2--->STRING.

    Kindly guide me.

    Thanks & Regards,
    Piyush.
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by cpiyush
    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.descript ion 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
    Code:
    t = type(dbVar)
    which will always be an str type for any character type in python.

    Comment

    • cpiyush
      New Member
      • Jan 2007
      • 31

      #3
      Originally posted by bartonc
      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
      Code:
      t = type(dbVar)
      which will always be an str type for any character type in python.
      My code is something like this..
      Code:
      import cx_Oracle
      
      
      #Establishing Connection string using makedsn() function.
      
      host = 'localhost' 
      port = 1521 
      dbase = 'Sample' 
      login = 'demo' 
      passwrd = 'demo' 
      dsn = cx_Oracle.makedsn(host, port, dbase) 
      connection = cx_Oracle.connect(login, passwrd, dsn) 
      print "********", connection
      
      cursor = connection.cursor()
      cursor.arraysize = 50
      cursor.execute("""describe tab1""")
      
      
      fields=[]
      for row in cursor.description:
      	fields.append(row[1])
      print fields
      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.

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by cpiyush
        My code is something like this..
        Code:
        import cx_Oracle
        
        
        #Establishing Connection string using makedsn() function.
        
        host = 'localhost' 
        port = 1521 
        dbase = 'Sample' 
        login = 'demo' 
        passwrd = 'demo' 
        dsn = cx_Oracle.makedsn(host, port, dbase) 
        connection = cx_Oracle.connect(login, passwrd, dsn) 
        print "********", connection
        
        cursor = connection.cursor()
        cursor.arraysize = 50
        cursor.execute("""describe tab1""")
        
        
        fields=[]
        for row in cursor.description:
        	fields.append(row[1])
        print fields
        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.fetchal l() not cursor.descript ion.

        Use lots of print statements to see what you are getting back (but you knew that, right).

        Comment

        • cpiyush
          New Member
          • Jan 2007
          • 31

          #5
          Originally posted by bartonc
          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.fetchal l() not cursor.descript ion.

          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.

          Comment

          • bartonc
            Recognized Expert Expert
            • Sep 2006
            • 6478

            #6
            Originally posted by cpiyush
            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
            Code:
            DESCRIBE TABLE TableName

            Comment

            Working...