diff options
author | astroshot <astroshot@outlook.com> | 2023-06-23 13:05:58 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-23 07:05:58 +0200 |
commit | 69dcceb5f6d3ecbcc9e7a0a48c9bdabeed470dcd (patch) | |
tree | bcec4d19e6de6997f023f087504466a3da0380e4 /pgcli | |
parent | 6b868bbfe831678d10c7535eb2e7356fcfb42068 (diff) |
Fix sql-insert format emits NULL as 'None' (#1409)
* Sub: Fix issue #1408
Body:
1. Fix issue #1408 sql-insert format emits NULL as 'None';
2. Fix DUAL displays as ""DUAL"";
==== End ====
* Sub: Update changelog.rst
Body:
==== End ====
* Sub: Optimize if logic
Body:
==== End ====
Diffstat (limited to 'pgcli')
-rw-r--r-- | pgcli/auth.py | 4 | ||||
-rw-r--r-- | pgcli/packages/formatter/sqlformatter.py | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/pgcli/auth.py b/pgcli/auth.py index 3d2fbeb9..2f1e5526 100644 --- a/pgcli/auth.py +++ b/pgcli/auth.py @@ -26,7 +26,9 @@ def keyring_initialize(keyring_enabled, *, logger): try: keyring = importlib.import_module("keyring") - except ModuleNotFoundError as e: + except ( + ModuleNotFoundError + ) as e: # ImportError for Python 2, ModuleNotFoundError for Python 3 logger.warning("import keyring failed: %r.", e) diff --git a/pgcli/packages/formatter/sqlformatter.py b/pgcli/packages/formatter/sqlformatter.py index 5bf25fec..5224eff6 100644 --- a/pgcli/packages/formatter/sqlformatter.py +++ b/pgcli/packages/formatter/sqlformatter.py @@ -14,10 +14,13 @@ preprocessors = () def escape_for_sql_statement(value): + if value is None: + return "NULL" + if isinstance(value, bytes): return f"X'{value.hex()}'" - else: - return "'{}'".format(value) + + return "'{}'".format(value) def adapter(data, headers, table_format=None, **kwargs): @@ -29,7 +32,7 @@ def adapter(data, headers, table_format=None, **kwargs): else: table_name = table[1] else: - table_name = '"DUAL"' + table_name = "DUAL" if table_format == "sql-insert": h = '", "'.join(headers) yield 'INSERT INTO "{}" ("{}") VALUES'.format(table_name, h) |