Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Features
* Right-align numeric columns, and make the behavior configurable.
* Add completions for stored procedures.
* Offer completions on `CREATE TABLE ... LIKE`.
* Use 0x-style hex literals for binaries in SQL output formats.


Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion mycli/packages/tabular_output/sql_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

def escape_for_sql_statement(value: Union[bytes, str]) -> str:
if isinstance(value, bytes):
return f"X'{value.hex()}'"
return f"0x{value.hex()}"
else:
return formatter.mycli.sqlexecute.conn.escape(value)

Expand Down
20 changes: 10 additions & 10 deletions test/test_tabular_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ def description(self):
`number` = 1
, `optional` = NULL
, `float` = 10.0e0
, `binary` = X'aa'
, `binary` = 0xaa
WHERE `letters` = 'abc';
UPDATE `DUAL` SET
`number` = 456
, `optional` = '1'
, `float` = 0.5e0
, `binary` = X'aabb'
, `binary` = 0xaabb
WHERE `letters` = 'd';""")
# Test sql-update-2 output format
assert list(mycli.change_table_format("sql-update-2")) == [SQLResult(None, None, None, "Changed table format to sql-update-2")]
Expand All @@ -75,12 +75,12 @@ def description(self):
UPDATE `DUAL` SET
`optional` = NULL
, `float` = 10.0e0
, `binary` = X'aa'
, `binary` = 0xaa
WHERE `letters` = 'abc' AND `number` = 1;
UPDATE `DUAL` SET
`optional` = '1'
, `float` = 0.5e0
, `binary` = X'aabb'
, `binary` = 0xaabb
WHERE `letters` = 'd' AND `number` = 456;""")
# Test sql-insert output format (without table name)
assert list(mycli.change_table_format("sql-insert")) == [SQLResult(None, None, None, "Changed table format to sql-insert")]
Expand All @@ -89,8 +89,8 @@ def description(self):
output = mycli.format_output(None, FakeCursor(), headers, False, False)
assert "\n".join(output) == dedent("""\
INSERT INTO `DUAL` (`letters`, `number`, `optional`, `float`, `binary`) VALUES
('abc', 1, NULL, 10.0e0, X'aa')
, ('d', 456, '1', 0.5e0, X'aabb')
('abc', 1, NULL, 10.0e0, 0xaa)
, ('d', 456, '1', 0.5e0, 0xaabb)
;""")
# Test sql-insert output format (with table name)
assert list(mycli.change_table_format("sql-insert")) == [SQLResult(None, None, None, "Changed table format to sql-insert")]
Expand All @@ -99,8 +99,8 @@ def description(self):
output = mycli.format_output(None, FakeCursor(), headers, False, False)
assert "\n".join(output) == dedent("""\
INSERT INTO table (`letters`, `number`, `optional`, `float`, `binary`) VALUES
('abc', 1, NULL, 10.0e0, X'aa')
, ('d', 456, '1', 0.5e0, X'aabb')
('abc', 1, NULL, 10.0e0, 0xaa)
, ('d', 456, '1', 0.5e0, 0xaabb)
;""")
# Test sql-insert output format (with database + table name)
assert list(mycli.change_table_format("sql-insert")) == [SQLResult(None, None, None, "Changed table format to sql-insert")]
Expand All @@ -109,6 +109,6 @@ def description(self):
output = mycli.format_output(None, FakeCursor(), headers, False, False)
assert "\n".join(output) == dedent("""\
INSERT INTO database.table (`letters`, `number`, `optional`, `float`, `binary`) VALUES
('abc', 1, NULL, 10.0e0, X'aa')
, ('d', 456, '1', 0.5e0, X'aabb')
('abc', 1, NULL, 10.0e0, 0xaa)
, ('d', 456, '1', 0.5e0, 0xaabb)
;""")