Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trim_char_fields connection argument #120

Merged
merged 8 commits into from
Sep 8, 2021
16 changes: 14 additions & 2 deletions sqlalchemy_ibmi/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
* ``use_system_naming`` - If ``True``, the connection is set to use the System
naming convention, otherwise it will use the SQL naming convention.
Defaults to ``False``.
* ``trim_char_fields`` - If ``True``, all character fields will be returned
with trailing spaces truncated. Defaults to ``False``.

create-engine arguments:

Expand Down Expand Up @@ -791,7 +793,7 @@ def create_connect_args(self, url):
opts.update(url.query)
allowed_opts = {'system', 'user', 'password', 'autocommit', 'readonly',
'timeout', 'database', 'use_system_naming',
'library_list', 'current_schema'
'library_list', 'current_schema', 'trim_char_fields'
}

if not allowed_opts.issuperset(opts.keys()):
Expand All @@ -800,9 +802,19 @@ def create_connect_args(self, url):

try:
opts['Naming'] = str(util.strtobool(opts['use_system_naming']))
except (ValueError, KeyError):
except KeyError:
opts['Naming'] = '0'
except ValueError:
raise ValueError("Invalid value specified for use_system_naming")

try:
trim_char_fields = opts.pop('trim_char_fields')
opts['TrimCharFields'] = str(util.strtobool(trim_char_fields))
except KeyError:
pass
except ValueError:
raise ValueError("Invalid value specified for trim_char_fields")

if 'current_schema' in opts or 'library_list' in opts:
opts['DefaultLibraries'] = opts.pop('current_schema', '') + ','
if isinstance(opts["DefaultLibraries"], str):
Expand Down