Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _connect(config: Config) -> pyexasol.ExaConnection:
"""Establish connection with exasol"""
params = {"compression": True}
if "schema" in config:
params["schema"] = config.schema
params.update(config.params)
try:
return pyexasol.connect(
dsn=config.dsn,
user=config.user,
password=config.password,
fetch_dict=True,
fetch_mapper=pyexasol.exasol_mapper,
**params,
)
except pyexasol.exceptions.ExaConnectionDsnError as exc:
raise ConnectionEstablishError(config.name, reason="Bad dsn", dsn=config.dsn) from exc
except pyexasol.exceptions.ExaAuthError as exc:
raise ConnectionEstablishError(
config.name, reason="Authentication failed", dsn=config.dsn, user=config.user,
) from exc
except pyexasol.exceptions.ExaConnectionFailedError as exc:
raise ConnectionEstablishError(
config.name, reason="Connection refused", dsn=config.dsn,
) from exc
except pyexasol.exceptions.ExaError as exc:
raise ConnectionEstablishError(config.name, dsn=config.dsn) from exc
select_q = 'SELECT dec36_0, dec36_36, dbl, bl, dt, ts, var100, LENGTH(var2000000) AS len_var FROM edge_case'
C.execute('TRUNCATE TABLE edge_case')
# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))
# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())
# Same actions with "exasol_mapper"
C.fetch_mapper = pyexasol.exasol_mapper
C.execute('TRUNCATE TABLE edge_case')
# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))
# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())
# Import and export
edge_tuples = C.execute("SELECT * FROM edge_case").fetchall()
select_q = 'SELECT dec36_0, dec36_36, dbl, bl, dt, ts, var100, LENGTH(var2000000) AS len_var FROM edge_case'
C.execute('TRUNCATE TABLE edge_case')
# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))
# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())
# Same actions with "exasol_mapper"
C.fetch_mapper = pyexasol.exasol_mapper
C.execute('TRUNCATE TABLE edge_case')
# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))
# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())
# Import and export
edge_tuples = C.execute("SELECT * FROM edge_case").fetchall()
C.execute('TRUNCATE TABLE edge_case')
TIMESTAMP -> datetime.datetime
BOOLEAN -> bool
VARCHAR -> str
CHAR -> str
-> str
"""
import pyexasol
import _config as config
import pprint
printer = pprint.PrettyPrinter(indent=4, width=180)
# Basic connect (custom mapper
C = pyexasol.connect(dsn=config.dsn, user=config.user, password=config.password, schema=config.schema,
fetch_mapper=pyexasol.exasol_mapper)
# Fetch objects
stmt = C.execute("SELECT * FROM users ORDER BY user_id LIMIT 5")
printer.pprint(stmt.fetchall())
# Test timestamp formats with different amount of decimal places
# Please note: Exasol stores timestamps with millisecond precision (3 decimal places)
# Lack of precision is not a bug, it's the documented feature
for i in range(0, 9):
C.execute(f"ALTER SESSION SET NLS_TIMESTAMP_FORMAT='YYYY-MM-DD HH24:MI:SS.FF{i}'")
printer.pprint(C.execute("SELECT TIMESTAMP'2018-01-01 03:04:05.123456'").fetchval())
select_q = 'SELECT dec36_0, dec36_36, dbl, bl, dt, ts, var100, LENGTH(var2000000) AS len_var FROM edge_case'
C.execute('TRUNCATE TABLE edge_case')
# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))
# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())
# Same actions with "exasol_mapper"
C.fetch_mapper = pyexasol.exasol_mapper
C.execute('TRUNCATE TABLE edge_case')
# Insert (test formatting)
C.execute(insert_q, dict(edge_cases[0]))
C.execute(insert_q, dict(edge_cases[1]))
C.execute(insert_q, dict(edge_cases[2]))
# Select and fetch
stmt = C.execute(select_q)
printer.pprint(stmt.fetchall())
# Import and export
edge_tuples = C.execute("SELECT * FROM edge_case").fetchall()