A Python script may be used to connect to TDV (TIBCO Data Virtualization), using an ODBC DSN. The steps are below.
1. If a TDV ODBC driver is not already installed on the Linux box, install the ODBC driver.
The latest driver may be downloaded from
https://edelivery.tibco.com/ 2. Set environment variables
ODBCINSTINI and
ODBCINI.
Example export
ODBCINSTINI=/Anil/odbc83_anil_only/odbcinst.ini
export
ODBCINI=/Anil/odbc83_anil_only/odbc.ini
3. Run the
driverConfig utility from the TDV ODBC driver installation.
Follow the prompts that the utility presents to create an ODBC DSN, say "dsn1".
Example - driverConfig will create two files named odbc.ini and odbc.inst.
- odbc.ini contains the DSN, as shown below. The Python script will use the DSN.
4. Create a Python script, as shown in the example below.
The script will do the following:
- open the odbc.ini file.
- read the DSN to obtain the driver details and connection details.
- load the driver into memory and then open a connection.
test.py import pyodbc
import os
os.environ["
TDV_ODBC_UODBC"]="TRUE"
os.environ["
ODBCINI"]="/Anil/odbc_83_anil_only//
odbc.ini"
conn = pyodbc.connect('DSN=dsn1')
conn.setdecoding(pyodbc.SQL_CHAR, encoding='utf-8')
conn.setencoding(unicode, encoding='utf-8');
cur = conn.cursor()
cur.execute("select CompanyName from ViewOrder")
row = cur.fetchall()
print(row)
Note: For using the ODBC driver with the unixODBC Driver Manager, the script needs to set the environment variable
TDV_ODBC_UODBC to TRUE.
5. Run the Python script.