Skip to content

Instantly share code, notes, and snippets.

@ThibTrip
Last active March 5, 2020 09:32
Show Gist options
  • Save ThibTrip/85855f4059191f77d1d1e71561a20341 to your computer and use it in GitHub Desktop.
Save ThibTrip/85855f4059191f77d1d1e71561a20341 to your computer and use it in GitHub Desktop.
Pervasive SQL in Python 3.7 (tested 2020-05-03)
"""
Tested with Pop OS (an Ubuntu clone)
# **INSTALLATION**:
## Install Python dependencies
* pip install jaydebeapi # latest version was '1.1.1' at the time of writing the gist
* pip install JPype1==0.6.3 # IMPORTANT! (latest: 0.7.2 did not work)
## Get the Persavive SQL driver
You can get it here: https://esd.actian.com/
You will have to select "Actian Zen (SQL)" as product and choose the correct version and platform.
You should end up with 3 files with the extension .jar. Those are drivers for the database written in Java.
They are meant to be used with JDBC (https://en.wikipedia.org/wiki/Java_Database_Connectivity).
## Install Java SDK
Look it up on the net.
"""
import jaydebeapi
import jpype as jp
import os
import pandas as pd # optional, pip install pandas
# CHANGE THIS!!
user = 'USER'
password = 'PASSWORD'
host = 'EXAMPLE.COM'
db = 'DATABASE'
# the files with the extension ".jar" must be in the same folder as the script!!!
classpath = os.pathsep.join((r"jpscs.jar", r"pvjdbc2.jar", r"pvjdbc2x.jar"))
jp.startJVM(jp.getDefaultJVMPath(),"-ea", f"-Djava.class.path={classpath}")
# connect
con = jaydebeapi.connect(jclassname="com.pervasive.jdbc.v2.Driver",
url=f"jdbc:pervasive://{host}:1583/{db}?transport=tcp",
driver_args=[user, password])
# query
# CHANGE query AND params!
query = 'SELECT * FROM SOME_TABLE WHERE user_id=?;'
params = [100]
df = pd.read_sql(query, con=con, params=params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment