Python - reading Oracle from Linux or Windows with the SAME code
here is a background: We have an Oracle server running on Windows. Years ago I wrote a client (windows) which reads data from Oracle, process, create XML and send it back to the instrument (mass spectrometer) controlling software (running on the same machine as Oracle). Utility was written in C++ as dll with two wrappers: GUI and console (for LIMS). Connection has been done via ADO/ODBC, so you don't have to have Oracle client installed (MS for Oracle ODBC driver works just fine...) Works like a charm for years, but... Now LIMS is migrating to Linux. I have a choice to make:
- to write a Linux version and maintain both Win and Linux (which is NOT good), or
- to write platform independent code (thinking of Python) and live happily ever after.
here is my (poorly formulated) question: Is it possible to write Python code which reads Oracle data residing on either Linux or Windows PROVIDING no Oracle client installed?
Edit:reformulating poorly formulated question: What are minimal changes I have to make for standard Python configuration/lib in order to use the same code on either Linux or Windows for reading Oracle data?
All I need just to execute a bunch of SELECT statements, READ ONLY.
already done:
- understand that it CAN be done in Java
- Python: I can detect what platform I am running on and branch the code if nec开发者_Go百科essary (I'll do that, but prefer NOT to, may be just a connect string?)
- looked at Python cx_Oracle, still can't understand if I can use it and have the same code for Linux and Win (writing test right now)
Any inside will be much appreciated. Thanks
Edit1: found a very good starting point: thanks to cx_Oracle and the data source paradigm
Using pyodbc might be another option:
http://pyodbc.sourceforge.net/
Your question
Is it possible to write Python code which reads Oracle data residing on either
does not make much sense this you can access any database in a portable way by using the standard Python DB API which is implemented by all related database bindings.
So what is the specific problem here?
In every case you need platform and specific bindings on your system in order to let your underlaying Python database driver talk to Oracle or which ever database but this is completely independent of any application code. In theory the code could work against every database as long as there is a driver and as long as your application uses "standard" SQL features.
精彩评论