Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.5
    • Component/s: Database
    • Labels:
      None

      Description

      Originally https://springpython.webfactional.com/ticket/45

      Add some code that allows connecting to an Oracle database.

      This was brought to my attention by Joe:
      =====================================
      Hello Greg,

      First, I want to express my admiration for SpringPython. I came across this gem a few days ago, and so far I am thrilled at what you have written. This is fantastic addition and I am slowly but surely trying to understand and use it.

      So, if you don't mind I have a few questions please. I use Oracle and use cx_Oracle to interface my python code with an Oracle database. Since cx_Oracle is compliant with the standard for database connectivity, I wrote a new Python script based on the mysql.py, except I called it cxora.py. I attached a copy of it.

      I have a test program I have wired up to talk to the database and it all worked perfectly with a simple query. However, I ran into a problem when passing parameters to a query. For example:

      return self.databaseTemplate.query("""

      SELECT impcarrcfg.paystat_work_dir,

      impcarrcfg.paystat_reload_dir, impcarrcfg.paystat_archive_dir, impcarrcfg.oid

      FROM impcarrcfg, carr, lklabelsys

      WHERE ( lklabelsys.oid = impcarrcfg.lklabelsys_oid) and

      ( carr.oid = impcarrcfg.carr_oid ) and ( carr.oid = ? and lklabelsys.oid = ? )

      """, (5, 5), ImpFilePropsRowCallbackHandler?())

      In the above example, I get an error message from Oracle and the python code halts on core.py with an exception at queryForList with a DataAccessException?(error). The error from oracle states the variable binding does not work. I did some research on this, and found this example: http://www.velocityreviews.com/forums/t333500-any-cxoracle-sample-code.html

      There they show a dictionary being passed as the argument. I'm not sure that is what is going on in the core.py code. The core.py code is trying to substitute the %s (converted from the ?) with the arguments and that is not working; or at least I don't think it is...

      The way around the dilemma is the following example:

      return self.databaseTemplate.query("""

      SELECT impcarrcfg.paystat_work_dir,

      impcarrcfg.paystat_reload_dir, impcarrcfg.paystat_archive_dir, impcarrcfg.oid

      FROM impcarrcfg, carr, lklabelsys

      WHERE ( lklabelsys.oid = impcarrcfg.lklabelsys_oid) and

      ( carr.oid = impcarrcfg.carr_oid ) and ( carr.oid = %s and lklabelsys.oid = %s )

      """ % (5, 5), None, ImpFilePropsRowCallbackHandler?())

      With this example, all works peachy. The substitution of the parameters is carried out just fine, and the select statement executes with no problems. I can live with this, no problem. But, just wanted to share this with you.

      Greg, I just wanted to bring this up and let you know. I am new to Python and the examples you have have helped me greatly. I just wanted to do my code based on some of your samples, and this error kinda threw me off. I hope you don't mind me writing you and letting you know about this. If this is a mistake on my part, please forgive me - we are all learning here! However, if this might be something of help that you might find worthy, then maybe this can make SpringPython? a little better...

      regards joe

        Attachments

        1. core.py
          7 kB
        2. cxora.py
          0.5 kB
        3. SpringSample.py
          0.7 kB
        4. SpringSampleController.py
          1 kB

          Activity

            People

            • Assignee:
              gregturn Greg Turnquist
              Reporter:
              gregturn Greg Turnquist
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: