Best way to access Firebird DB from a remote desktop. - python

I have a Firebird DB set up on my computer and I want to be able to retrieve data from a different computer. What is the best way to go about this?
I am running windows and using python.

Install firebird client to the client pc
To connect firebird programmaticaly from python you should install a python Firebird driver.
For Python 2.x, you can use kinterbasdb. This is the legacy driver and I think it is not actively developed but only maintained.
To connect windows based server database from kinterbasdb you can use
Import kinterbasdb as k
k.init(type_conv = 300) #
con = k.connect(dsn='127.0.0.1:c:\\db\\test.fdb', user='sysdba', password='masterkey', charset='YOUR_CHARSET', dialect=3)
Of course you should adjust connection parameters according to your system. Kinterbasdb documentation is here
If you want use an ORM, you can use SqlAlchemy which uses kinterbasdb for Firebird Support
For Python 3k you can use pyfirebirdsql which also supports Python 2.5+ and under active development, but not supported by SqlAlchemy yet.

Run Firebird server on the computer with database file and connect to it from remote computer. You will need in Firebird client library installed on remote computer.

I think we need a bit more info.
Do you want database access - as in "I want to be able to edit table layout and define new tables, views, procedures and so on" ?
Or do you only need to get data from the database using python ?
The latter could be achieved by installing a Firebird client (in essence its a dll (fbclient.dll)) and then use a connect string from python to connect to your database.

Related

Setting up cx_Oracle and Oracle 11g for Django, name vs host? Where to put Instant Client?

I'm trying to follow this tutorial to connect django with a legacy oracle database a little confused what to put in the Name. In addition, I'm a little confused how to install the Instant Client so that my django/python application will be able to see the instant client.
I'm on Windows 10, django 3.0.1, python 3.8
1.) First of all, when I connect to the database with the enterprise manager, I see this (edited):
So when I fill in my django, this is what I put(edited):
in the Name, am I suppose to put ServerName (following the enterprise manager image) or do I put servername/schema that I'm trying to connect to?
2.) I contacted the admin, and the Oracle database is 11g, and also in Visual Studio, I connected to the database and checked the version, it is
So I download the instant client for 11.2.0.4.0 (32 bit)
I use 32bit because I think my python is 32 bit.
Unzipped it into C:\instantclient_11_2
Added C:\instantclient_11_2 to my System Environment Variables, in the PATH
And tried to run the following
And I receive the error:
But according to the documentation here, I need to set it to lib_dir, but I'm not sure where the lib_dir variable is? is this an environment variable? Or something in my application? Settings.py?
In your case, I would use an Oracle client 18c or 19c . Both can connect to a 11g database without any issue.
Using 11g version with cx_Oracle 8.0 might lead to issues.

How do I connect to Oracle Exadata from Python?

I have tried connecting exadata from python using cx_Oracle, but faced issue stating
cx_Oracle.DatabaseError: DPI - 1047: Cannot locate a 64bit Oracle client library.
I am trying to install a 64bit cx_Oracle, but I need to know can I connect from python to exadata.
Follow the cx_Oracle Linux installation instructions. The piece you are missing is access to Oracle Client libraries. As noted in the other answer, using Instant Client is the way to go. You'll need the "Basic" or "Basic Light" package for Linux x86-64. If you don't know your character set requirement, then use "Basic". You can use the latest 19c version. This will let you connect to Oracle DB 11.2 and newer.
If you have root access (?) you may find the RPM packages easier. If you want to use ZIP files, unzip the package, set your LD_LIBRARY_PATH environment variable to the directory, and run Python.
In your cx_Oracle scripts you use the same database credentials and connection string that you would use in SQL*Plus.
Welcome to Stack Overflow!
For the record, Oracle Exadata is a platform consisting of hardware and software designed for extreme Oracle Database performance. cx_Oracle is the Python client library to operate on an Oracle Database - hence you want to connect to an Oracle Database utilizing the Python programming language.
cx_Oracle depends on OCI (Oracle Call Interface). You need to download and install Oracle Client Library on your workstation before you can do import cx_Oracle from within Python.
You will find the Oracle Client Library here
Best of luck!

Run MySQL Server in Python

So I've been looking all over the internet and only found resources/tutorials on how to connect to a MySQL server but my question is, how do you host a MySQL server both on Windows & Linux?
I am not quite sure what you are asking but if the question is how to run a database for python independent of the OS, consider using sqlite.
From the link (emphasis mine)
SQLite is an embedded SQL database engine. Unlike most other SQL
databases, SQLite does not have a separate server process. SQLite
reads and writes directly to ordinary disk files. A complete SQL
database with multiple tables, indices, triggers, and views, is
contained in a single disk file. The database file format is
cross-platform - you can freely copy a database between 32-bit and
64-bit systems or between big-endian and little-endian architectures.
These features make SQLite a popular choice as an Application File
Format. Think of SQLite not as a replacement for Oracle but as a
replacement for fopen().
So it allows you to use a database from your python code without the hassle of running a server or setting something up locally.
Note that sqlite can also be stored in-memory if you want to avoid writing to disk.
Unless you have a very specific reason to start the server from Python, I.e. you want to be able to programmatically do stuff you wouldn't do from the command line, I think the best you could do is to install an instance of Mysql server in your local machine, run it and then, you'll be able to connect to it from Python.
Bear in mind that your local installation of Mysql will be running on localhost (127.0.0.1)

How do I access an Oracle db without installing Oracle's client and cx_Oracle?

I have two RHEL servers running Python 2.4 and 2.6 separately. There is an Oracle database on the other server I need to access.
I was trying to install cx_oracle on my RHEL server but found out that the Oracle client must be installed first.
The problem is, I don’t have permission to install Oracle's client on both RHEL servers. On the same servers, a Perl program can connect to the Oracle db using:
DBI->connect("dbi:Oracle:host=myhost.prod.com;sid=prddb",'username','password')
Can Python do the same without installing cx_oracle and the Oracle client? Or are there any suggestions about how to write a module myself to do the same thing?
Thanks in advance!
An excerpt from https://forum.omz-software.com/topic/184/oracle-database:
There's no pure python client for Oracle and likely never will be. Even wonderful third-party toolsets like SQLalchemy still rely on cx_Oracle underneath to do the actual communication to the Oracle database servers.
—also, deciding by Google, the answer is no: there do not seem to be any pure Python Oracle clients in existence as of today.
Usually, all you need are the libraries, which don't necessarily require sudo rights. Extract them to a place the software will be able to read from and set the following environment variables accordingly:
ORACLE_HOME=path/to/where/you/extracted/libs
TNS_ADMIN=path/to/tnsnames.ora
I have had best luck skipping tnsnames, and just specifying the host, port, etc in the connection, but it's quite possible you'll need it for cx_oracle...I don't remember from when I used it ages ago.
if you don't want use cx_Oracle you should use expect scripting. ( for python pexpect). But you need to be carefully for handle all expectations.

MySQL connector

I am trying to build a tool that one step of it is connecting to MySQL database.
Just I am so confused about ODBC. If I want to build a cross platform connector by python, should I use python connector or ODBC connector?
I know JDBC, but ODBC stands for Open Database Connectivity. It looks like more compatible.
Could anyone help me clarify that? Thank you very much.
Python has its own DB API v2.0 abstraction layer to connect to databases (it serves the same purpose of ODBC or JDBC but for Python). You should use one of the DB API v2.0 compliant oursql, MySQLdb or PyMySQL packages to connect to MySQL from Python. All these packages are cross platform and will work on Linux, Windows and MacOS X. oursql, and MySQLdb are wrappers for libmysql and PyMySQL is a pure Python implementation.
Note that there are DB API v2.0 implementations (like pyodbc) that provide ODBC connectivity, so conceptually you could connect to MySQL via ODBC, but this would have inferior performance than the above mentioned "native" drivers because of the extra abstraction layers.

Categories