Pythonic shim over teradatasql, Teradata DB API driver
Project description
tddbapi
tddbapi is a DB API module that is a shim over teradatasql, the Teradata provided DB API module. teradatasql
closely follows Teradata JDBC driver in terms of functionality and behaviors, some of which, arguably aren't quite pythonic. tddbapi
attempts to correct this by altering selected teradatasql
behavior (APIs) as documented here. The remaining, unaltered, functionality is directly passed through to the teradatasql
module.
teradatasql
behavior
-
Fixed-length character column values have incorrect length when accessed in Python. According to Teradata, this is working as designed.
-
teradatasql
usesOperationalError
for all exceptions. According to Python's DB API specification,OperationalError
is reserved for a certain class of errors. Additionally, the exception object- doesn't provide easy access to the error code or the error message values.
- has text that includes unformatted stack trace of underlying gosql driver. While this may be useful in certain situations, for example, reporting errors back to Teradata, but may not be the best message to display to the users.
-
All SQL
INTERVAL
values are returned as Python typestr
instead of more appropriate native Python types, thus working with them is harder in Python. Apparently, this was done because not all SQL INTERVAL data types can be represented by Python'sdatetime.timedelta
type. -
teradatasql
exposes all internally used names, and thus can pollute the namespace if you usefrom teradatasql import *
.
tddbapi
behavior
-
Fixed-length character columns will have any extra spaces beyond their actual definition truncated.
-
Appropriate Exception raised for the most common errors. Exception objects:
- have
sqlcode
andsqltext
attributes that can be queried directly instead of having to parse the error message - provide
__str__
method that produces a human-readable error message and removesgosql
stack-trace information - note: If you want to ensure that the exception handling logic works with
teradatasql
andtddbapi
, use an Exception class that is higher in the hierarchy, for example,DatabaseError
orError
- have
-
INTERVAL
values are objects of eitherdatetime.timedelta
subclasses, or for the month based interval types, instances ofint
subclasses. The month-based intervals use the total number of months as canonical value, thus allowing comparison between two month-based intervals even if their exact types are different. -
It's safe to code
from tddbapi import *
without introducing non DB-API names into the current namespace
Note
tddbapi
always obtains resultset metadata information for all queries. If your application also needs access to resultset metadata, it can be accessed as _meta
attribute of the cursor as already-parsed JSON data.
Installation and Usage
Install tddbapi
using the standard pip
utility:
pip install --upgrade tddbapi
Using tddbapi
in a Python application is as simple as replacing teradatasql
with tddbapi
. For example:
import tddbapi as teradatasql
with teradatasql.connect(host="whomooz", user="guest", password="please") as con:
with con.cursor() as cur:
cur.execute("SELECT * FROM DBC.DBCINFOV")
print(cur.fetchall())
Disclaimers
tddbapi
module:
- does not come with any warranty and the user assumes all risks associated with its usage.
- is not endorsed by Teradata.
- overrides some internal
teradatasql
implementation details. It is possible that a future version ofteradatasql
can breaktddbapi
, at least for a short period. - will be kept compatible with
teradatasql
on a best-effort basis. If you must have the latestteradatasql
all the time and cannot live with the risk of breakage, even for a short period, you shouldn't use this module. - is available via MIT license, which may be different from the licenses of any of its dependencies (currently only
teradatasql
).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file tddbapi-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: tddbapi-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46e5f1531565ce7da5e3e2962b2f502012c5bf2d0b6c1374f413a3e0e95c4c8b |
|
MD5 | a6abe00a03f8495aa5f87fcab0f66b83 |
|
BLAKE2b-256 | bf5f454296f04851567686613b1c589d369d25b612b62ab5c27ad9fbd3dacdec |