mirror of https://github.com/dbcli/pgcli
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 ====
This commit is contained in:
parent
6b868bbfe8
commit
69dcceb5f6
|
@ -23,6 +23,7 @@ Bug fixes:
|
||||||
* Fix \ev not producing a correctly quoted "schema"."view"
|
* Fix \ev not producing a correctly quoted "schema"."view"
|
||||||
* Fix 'invalid connection option "dsn"' ([issue 1373](https://github.com/dbcli/pgcli/issues/1373)).
|
* Fix 'invalid connection option "dsn"' ([issue 1373](https://github.com/dbcli/pgcli/issues/1373)).
|
||||||
* Fix explain mode when used with `expand`, `auto_expand`, or `--explain-vertical-output` ([issue 1393](https://github.com/dbcli/pgcli/issues/1393)).
|
* Fix explain mode when used with `expand`, `auto_expand`, or `--explain-vertical-output` ([issue 1393](https://github.com/dbcli/pgcli/issues/1393)).
|
||||||
|
* Fix sql-insert format emits NULL as 'None' ([issue 1408](https://github.com/dbcli/pgcli/issues/1408)).
|
||||||
|
|
||||||
3.5.0 (2022/09/15):
|
3.5.0 (2022/09/15):
|
||||||
===================
|
===================
|
||||||
|
|
|
@ -26,7 +26,9 @@ def keyring_initialize(keyring_enabled, *, logger):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
keyring = importlib.import_module("keyring")
|
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)
|
logger.warning("import keyring failed: %r.", e)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -14,10 +14,13 @@ preprocessors = ()
|
||||||
|
|
||||||
|
|
||||||
def escape_for_sql_statement(value):
|
def escape_for_sql_statement(value):
|
||||||
|
if value is None:
|
||||||
|
return "NULL"
|
||||||
|
|
||||||
if isinstance(value, bytes):
|
if isinstance(value, bytes):
|
||||||
return f"X'{value.hex()}'"
|
return f"X'{value.hex()}'"
|
||||||
else:
|
|
||||||
return "'{}'".format(value)
|
return "'{}'".format(value)
|
||||||
|
|
||||||
|
|
||||||
def adapter(data, headers, table_format=None, **kwargs):
|
def adapter(data, headers, table_format=None, **kwargs):
|
||||||
|
@ -29,7 +32,7 @@ def adapter(data, headers, table_format=None, **kwargs):
|
||||||
else:
|
else:
|
||||||
table_name = table[1]
|
table_name = table[1]
|
||||||
else:
|
else:
|
||||||
table_name = '"DUAL"'
|
table_name = "DUAL"
|
||||||
if table_format == "sql-insert":
|
if table_format == "sql-insert":
|
||||||
h = '", "'.join(headers)
|
h = '", "'.join(headers)
|
||||||
yield 'INSERT INTO "{}" ("{}") VALUES'.format(table_name, h)
|
yield 'INSERT INTO "{}" ("{}") VALUES'.format(table_name, h)
|
||||||
|
|
|
@ -34,7 +34,7 @@ def test_output_sql_insert():
|
||||||
"Jackson",
|
"Jackson",
|
||||||
"jackson_test@gmail.com",
|
"jackson_test@gmail.com",
|
||||||
"132454789",
|
"132454789",
|
||||||
"",
|
None,
|
||||||
"2022-09-09 19:44:32.712343+08",
|
"2022-09-09 19:44:32.712343+08",
|
||||||
"2022-09-09 19:44:32.712343+08",
|
"2022-09-09 19:44:32.712343+08",
|
||||||
]
|
]
|
||||||
|
@ -58,7 +58,7 @@ def test_output_sql_insert():
|
||||||
output_list = [l for l in output]
|
output_list = [l for l in output]
|
||||||
expected = [
|
expected = [
|
||||||
'INSERT INTO "user" ("id", "name", "email", "phone", "description", "created_at", "updated_at") VALUES',
|
'INSERT INTO "user" ("id", "name", "email", "phone", "description", "created_at", "updated_at") VALUES',
|
||||||
" ('1', 'Jackson', 'jackson_test@gmail.com', '132454789', '', "
|
" ('1', 'Jackson', 'jackson_test@gmail.com', '132454789', NULL, "
|
||||||
+ "'2022-09-09 19:44:32.712343+08', '2022-09-09 19:44:32.712343+08')",
|
+ "'2022-09-09 19:44:32.712343+08', '2022-09-09 19:44:32.712343+08')",
|
||||||
";",
|
";",
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue