Skip to content

Instantly share code, notes, and snippets.

@ThibTrip
Last active March 5, 2020 09:32
Show Gist options
  • Select an option

  • Save ThibTrip/85855f4059191f77d1d1e71561a20341 to your computer and use it in GitHub Desktop.

Select an option

Save ThibTrip/85855f4059191f77d1d1e71561a20341 to your computer and use it in GitHub Desktop.

Revisions

  1. ThibTrip revised this gist Mar 5, 2020. No changes.
  2. ThibTrip revised this gist Mar 5, 2020. No changes.
  3. ThibTrip created this gist Mar 5, 2020.
    49 changes: 49 additions & 0 deletions pervasive.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    """
    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)