Skip to main content

Django GBasedbtDB

A database driver for Django to connect to an GBase 8s database via pyodbc.

Some limitations:

  • Does not support default values

  • GBase 8s automatically creates indexes on foreign keys, but Django attempts to do that manually; the current implementation here just attempts to catch the error on index creation. It may unintentionally catch other index creation errors where the index already exists.

Configure local environment

The following environment variables should exist:

GBASEDBTDIR

The path to the GBase 8s client install directory

GBASEDBTSERVER

The name of the GBase 8s service to which we need to connect

GBASEDBTSQLHOSTS

The path to the sqlhosts file that the GBase 8s driver should use

LD_LIBRARY_PATH

The path(s) to the various GBase 8s library files: Usually $GBASEDBTDIR/lib:$GBASEDBTDIR/lib/cli:$GBASEDBTDIR/lib/esql

DB_LOCALE

In case of Database locale information mismatch. error during connection, you should specify your database locale, e.g. DB_LOCALE=en_US.8859-15

You will also need to add an entry within your sqlhosts file for each remote/local GBase 8s server connection in the following format:

<GBASEDBT_SERVER_NAME>    onsoctcp     <GBASEDBT_HOST_NAME>    <GBASEDBT_SERVICE_NAME>

For example:

dev    onsoctcp    localhost    9088

You may alternatively use a symbolic name in that line in place of the port number, typically sqlexec and then configure the port number in the /etc/services file:

sqlexec    9088/tcp

Configure settings.py

Django’s settings.py uses the following to connect to an GBase 8s database:

'default': {
    'ENGINE': 'django_gbasedbtdb',
    'NAME': 'myproject',
    'SERVER': 'ifxserver',
    'USER' : 'testuser',
    'PASSWORD': 'passw0rd',
    'OPTIONS': {
        'DRIVER': '/path/to/iclit09b.so'. # Or iclit09b.dylib on macOS
        'CPTIMEOUT': 120,
        'CONN_TIMEOUT': 120,
        'ISOLATION_LEVEL': 'READ_UNCOMMITTED',
        'LOCK_MODE_WAIT': 0,
        'VALIDATE_CONNECTION': True,
    },
    'CONNECTION_RETRY': {
        'MAX_ATTEMPTS': 10,
    },
    'TEST': {
        'NAME': 'myproject',
        'CREATE_DB': False
    }
}
CPTIMEOUT

This will set connection pooling timeout. Possible values:

0 - Turn off connection pooling
nn - timeout set nn seconds
CONN_TIMEOUT

This will set timeout for operations on connections (connection, ??closing??, we’re not sure). Possible values:

0 - Default timeout to the database (which could mean no timeout)
nn - timeout set nn seconds
ISOLATION_LEVEL

This will set database isolation level at connection level Possible values:

READ_COMMITED
READ_UNCOMMITTED
SERIALIZABLE
LOCK_MODE_WAIT

This will set database LOCK MODE WAIT at connection level Application can use this property to override the default server process for accessing a locked row or table. The default value is 0 (do not wait for the lock). Possible values:

-1 - WAIT until the lock is released.
0 - DO NOT WAIT, end the operation, and return with error.
nn - WAIT for nn seconds for the lock to be released.
VALIDATE_CONNECTION

Whether existing connections should be validated at the start of the request. Defaults to False.

VALIDATION_INTERVAL

How often in seconds to revalidate connections if VALIDATE_CONNECTION is enabled. Defaults to 300 (5 minutes).

VALIDATION_QUERY

Query used to validate whether a connection is usable. Defaults to “SELECT 1 FROM sysmaster:sysdual”.

CONNECTION_RETRY

When opening a new connection to the database, automatically retry up to MAX_ATTEMPTS times in the case of errors. Only error codes in ERRORS will trigger a retry. The wait time between retries is calculated using an exponential backoff with jitter formula:

random_between(WAIT_MIN, min(WAIT_MAX, WAIT_MULTIPLIER * WAIT_EXP_BASE ** (attempt - 1)))

Defaults (wait times are in milliseconds):

MAX_ATTEMPTS: 1  # this implies no retries
WAIT_MIN: 0
WAIT_MAX: 1000
WAIT_MULTIPLIER: 25
WAIT_EXP_BASE: 2
ERRORS: ['-908', '-930', '-27001']

Each of these settings can be overridden in the CONNECTION_RETRY section of the database configuration in settings.py. For example:

DATABASES = {
   'default': {
       'ENGINE': 'django_gbasedbtdb',
       'CONNECTION_RETRY': {
           'MAX_ATTEMPTS': 10,
           'WAIT_MIN': 0,
           'WAIT_MAX': 500,
       },
       # ...
    },
 }

The error codes that are retried by default correspond to the following errors:

  • -908 Attempt to connect to database server (servername) failed

  • -930 Cannot connect to database server servername

  • -27001 Read error occurred during connection attempt

These errors are often seen when the database server is too busy, too many clients are attempting to connect at the same time or a network firewall has chopped the connection.

Testing against an GBase 8s Database

Due to a bug in the GBase 8s ODBC driver, it is not currently possible to run Django tests normally. Specifically, it is not possible for Django to create a test database. As such, you will need to do it manually. By default Django will attempt to create a database with a name equal to the default database name with a test_ prefix. e.g. if you database name is my_database, the test database name would be test_my_database. This can be overridden with the NAME option under TEST.

To prevent Django from attempting to create a test database, set the CREATE_DB option under TEST to False: see ‘Configure settings.py’ above.

You can follow the steps above, in the section on using GBase 8s locally with Docker to create a test database. Then when running the test you can tell Django to re-use an existing database, rather than trying to create a new one with the -k parameter:

./manage.py test -k

For django_gbasedbtdb Developers

To run the django_gbasedbtdb test suite, you need to set the GBASEDBTDIR environment variable, and the tests expect an GBase 8s database at host “gbasedbt”. Change that host in test/conftest.py if you need to. Then run the test suite with:

tox

This will run the tests under Django 3 and 4.

Release History

Version 1.11.5

  • Fork from django_informixdb

  • Fix ‘unsupported column type -114’

Metadata

Release files for django-gbasedbtdb 1.11.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-gbasedbtdb 1.11.5
File Size Uploaded Provenance
django_gbasedbtdb-1.11.5.tar.gz 28.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-gbasedbtdb 1.11.5
File Interpreter ABI Platform
django_gbasedbtdb-1.11.5-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 54.6 kB

Release files / django_gbasedbtdb-1.11.5.tar.gz

Download URL django_gbasedbtdb-1.11.5.tar.gz
Size 28.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5a8c9206ddc708fc3221b175bea4cf633260b1506b99d3f6f78cdb5cda5384f0
BLAKE2b-256 checksum
How to use checksums
a8d9f11c79ce2d05c31932d5eaf6745530ccd510bd644fe80d010e5af77bc574
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Release files / django_gbasedbtdb-1.11.5-py2.py3-none-any.whl

Download URL django_gbasedbtdb-1.11.5-py2.py3-none-any.whl
Size 26.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
6c03f994d1c2d007bede8bd2c38573e7f2458aee9128f3057c65e08ac7acb2a5
BLAKE2b-256 checksum
How to use checksums
a35101d459f3ac53f98e81eece029c24709bf211ee81f63af35d09ae5141f1d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Security for django-gbasedbtdb 1.11.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page