How to connect oracle database in python irrespective of operating system - python

I'm trying to write a python script using cx_oracle module for perform oracle database connection. But during the execution, I found it needs oracle instant client to establish a connection. Currently, I'm developing the script in ubuntu but there is a chance to run the same in windows. So I'm confused about the implementation. Could someone please suggest the best way to connect oracle database irrespective the platform

You will always need an OS-specific library or client of some kind. Either the Oracle Instant Client or a Java JDK/JDBC library or both. If you want OS-independence then you would need to interact with the DB through REST calls or something like that instead of making a persistent connection. Otherwise you have to interact with the OS networking stack at some point, which requires OS-specific libraries.

Related

Do I need to install MySQL Server on client machine, the database is used (Read, Write, Delete) by Python script I wrote?

I have written a python script that uses the MySQL Connector for Python to read, write and update the database. Do I need to install MySQL server on the client machine (Windows) too to run the program or do I just need to make sure that the database is present in the path used by the script? I tried finding guidance on Google and here but couldn't find what I needed.
No you don't need to install MySQL Server on a client machine. By definition client machine means you don't have the DB/Server there. Where is this DB allocated? You show have an IP or a domain/subdomain address where the DB is actually hosted.

Using cx_oracle when muliple Oracle clients in the path

I am using cx_Oracle to access the Oracle database for some time and it works fine. Now my co-worker wants to run my scripts and we run across a problem with cx_Oracle. Wile trying to connect to the database we got the error: InterfaceError: Unable to acquire Oracle environment handle.
I read on a stackoverflow post that the probable error is that there are multiple oci.dll files found on the path. In our case we have two instant clients installed,I installed instant client 12 and there is another, very old installed from before that is used by some other applications. How can I tell Python which instant client to use?
She is using Windows XP and I installed her instant client 12, python 3.4 and cx_oracle 5.2, all 32 bit.
You need to ensure the PATH and ORACLE_HOME environment variables are pointing to the same Oracle client install. In the case of PATH (which you imply may contain multiple Oracle client installations), you need to ensure the one you wish to use appears first.
Instead of relying on system-wide settings for these environment variables, you may want to wrap your Python script in a batch file that ensures these variables are set correctly before starting the interpreter. For example, assuming you installed the Oracle 12.1 instant client to C:\Oracle\instantclient_12_1:
#ECHO OFF
SET ORACLE_HOME=C:\Oracle\instantclient_12_1
SET PATH=C:\Oracle\instantclient_12_1;%PATH%
python path_to_my_script.py

How to call a python script from MySQL DB (iOS)

I have an iOS app that is connecting to a MySQL db. At one point I am authenticating the users information. Doing some research informs me that the safest way to do this is by doing so server side. How would I go about calling a python script from MySQL and returning it?

Creating a Connection Between MySQL and Tornado

I am trying to get a Python and Tornado environment up and running.
As of now I am able to execute Python scripts and now I am trying to be able to make use of databases as well.
By my understanding Tornado has a MySQL wrapper, and I as of now I have XAMPP installed and I would like to continue using PhpMyAdmin as the GUI for MySQL.
The question I am having is how can I create a connection between MySQL and Tornado?
So that when you use a connection command Tornado will connect to the right MySQL installation and databases, which I of course created with PhpMyAdmin?
From Tornado's documentation:
db = database.Connection("localhost", "mydatabase")
Once you instantiate a connection ( named db in this example ), you can reuse it during your server's lifetime..
If you need to change it dynamically while your tornado server is running, then have tornado "listen" to a specific url_pattern, handled by the appropriate web.RequestHandler, which receives as (GET or POST) arguments your MYSQL connection parameters (host, database, user etc..) and creates a new database connection.
Edit
In newer versions of tornado (>=3.0) the tornado.database module has been removed. It is now available as a separate package, torndb.

cx_Oracle. How to access remote machine?

I had a look at cx_Oracle but I have a couple of problems with it. First , my oracle server is on remote machine. Second I do not know on what platform my software will be deployed. All the examples I have founded
like this
http://www.len.ro/2009/08/cx_oracle-on-ubuntu-9-04-jaunty/
or
this https://stackoverflow.com/questions/592/cx-oracle-how-do-i-access-oracle-from-python
assume to have oracle server on the same machine. Is there possibility to have some static compilation so I can easily move my software from one pc to the other?
thx
Of course cx_Oracle can work with server working on other machine. But on client machines you will have to install Oracle client and configure it. I don't know if Oracle client installation can be added to installer of your application. Normally it is huge (600 MiB or so) so it is not a good idea. Then on all client machines you will have to configure Oracle client: set ORACLE_HOME, run Oracle tools to configure connection with database etc.
The only "light" solution I know is to use JDBC from Jython or Java. In this scenario you can use "thin" version of connect string that requires only some .jar libraries. Such connect string looks like:
db = DriverManager.getConnection('jdbc:oracle:thin:169.0.1.225:1521:test_db', 'user', 'passwd')
On client machines it needs ojdbc6.jar and orai18n.jar on CLASSPATH. No installation, no configuration, simple and easy.

Categories