Skip to content

Commit 851caa8

Browse files
authored
Merge pull request #191 from dbcli/fix-special-cmd-d
Fix special cmd d
2 parents e58bbcd + 67e2ce9 commit 851caa8

File tree

5 files changed

+68
-64
lines changed

5 files changed

+68
-64
lines changed

CHANGELOG.md

+23-37
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
## Upcoming - TBD
2-
3-
4-
### Features
5-
1+
## 1.12.4 - 2024-11-11
62

73
### Bug Fixes
84

9-
10-
### Internal Changes
11-
5+
* Fix the syntax error when `\d tbl` is used.
126

137
## 1.12.3 - 2024-09-10
148

@@ -17,7 +11,6 @@
1711
* Specify build system in `pyproject.toml`
1812
* Don't install tests
1913

20-
2114
## 1.12.2 - 2024-09-07
2215

2316
### Bug Fixes
@@ -40,27 +33,23 @@
4033

4134
* Fix the escape sequence warning.
4235

43-
4436
## 1.11.0 - 2024-05-03
4537

4638
### Improvements
4739

4840
* When an empty `\d` is invoked the list of tables are returned instead of an error.
4941
* Show SQLite version at startup.
5042

51-
5243
### Bug Fixes
5344

5445
* Support a single item in the startup commands in the config. (bug #176)
5546

56-
5747
## 1.10.1 - 2024-3-23
5848

5949
### Bug Fixes
6050

6151
* Do not crash at start up if ~/.config/litecli is not writeable. [#172](https://github.com/dbcli/litecli/issues/172)
6252

63-
6453
## 1.10.0 - 2022-11-19
6554

6655
### Features
@@ -82,7 +71,6 @@
8271
* Skip internal indexes in the .schema output
8372
([#170](https://github.com/dbcli/litecli/issues/170)).
8473

85-
8674
## 1.9.0 - 2022-06-06
8775

8876
### Features
@@ -125,72 +113,70 @@
125113

126114
### Features
127115

128-
- Add verbose feature to `favorite_query` command. (Thanks: [Zhaolong Zhu])
129-
- `\f query` does not show the full SQL.
130-
- `\f+ query` shows the full SQL.
131-
- Add prompt format of file's basename. (Thanks: [elig0n])
116+
* Add verbose feature to `favorite_query` command. (Thanks: [Zhaolong Zhu])
117+
* `\f query` does not show the full SQL.
118+
* `\f+ query` shows the full SQL.
119+
* Add prompt format of file's basename. (Thanks: [elig0n])
132120

133121
### Bug Fixes
134122

135-
- Fix compatibility with sqlparse >= 0.4.0. (Thanks: [chocolateboy])
136-
- Fix invalid utf-8 exception. (Thanks: [Amjith])
123+
* Fix compatibility with sqlparse >= 0.4.0. (Thanks: [chocolateboy])
124+
* Fix invalid utf-8 exception. (Thanks: [Amjith])
137125

138126
## 1.4.1 - 2020-07-27
139127

140128
### Bug Fixes
141129

142-
- Fix setup.py to set `long_description_content_type` as markdown.
130+
* Fix setup.py to set `long_description_content_type` as markdown.
143131

144132
## 1.4.0 - 2020-07-27
145133

146134
### Features
147135

148-
- Add NULLS FIRST and NULLS LAST to keywords. (Thanks: [Amjith])
136+
* Add NULLS FIRST and NULLS LAST to keywords. (Thanks: [Amjith])
149137

150138
## 1.3.2 - 2020-03-11
151139

152-
- Fix the completion engine to work with newer sqlparse.
140+
* Fix the completion engine to work with newer sqlparse.
153141

154142
## 1.3.1 - 2020-03-11
155143

156-
- Remove the version pinning of sqlparse package.
144+
* Remove the version pinning of sqlparse package.
157145

158146
## 1.3.0 - 2020-02-11
159147

160148
### Features
161149

162-
- Added `.import` command for importing data from file into table. (Thanks: [Zhaolong Zhu])
163-
- Upgraded to prompt-toolkit 3.x.
150+
* Added `.import` command for importing data from file into table. (Thanks: [Zhaolong Zhu])
151+
* Upgraded to prompt-toolkit 3.x.
164152

165153
## 1.2.0 - 2019-10-26
166154

167155
### Features
168156

169-
- Enhance the `describe` command. (Thanks: [Amjith])
170-
- Autocomplete table names for special commands. (Thanks: [Amjith])
157+
* Enhance the `describe` command. (Thanks: [Amjith])
158+
* Autocomplete table names for special commands. (Thanks: [Amjith])
171159

172160
## 1.1.0 - 2019-07-14
173161

174162
### Features
175163

176-
- Added `.read` command for reading scripts.
177-
- Added `.load` command for loading extension libraries. (Thanks: [Zhiming Wang])
178-
- Add support for using `?` as a placeholder in the favorite queries. (Thanks: [Amjith])
179-
- Added shift-tab to select the previous entry in the completion menu. [Amjith]
180-
- Added `describe` and `desc` keywords.
164+
* Added `.read` command for reading scripts.
165+
* Added `.load` command for loading extension libraries. (Thanks: [Zhiming Wang])
166+
* Add support for using `?` as a placeholder in the favorite queries. (Thanks: [Amjith])
167+
* Added shift-tab to select the previous entry in the completion menu. [Amjith]
168+
* Added `describe` and `desc` keywords.
181169

182170
### Bug Fixes
183171

184-
- Clear error message when directory does not exist. (Thanks: [Irina Truong])
172+
* Clear error message when directory does not exist. (Thanks: [Irina Truong])
185173

186174
## 1.0.0 - 2019-01-04
187175

188-
- To new beginnings. :tada:
176+
* To new beginnings. :tada:
189177

190178
[Amjith]: https://blog.amjith.com
191179
[chocolateboy]: https://github.com/chocolateboy
192180
[Irina Truong]: https://github.com/j-bennet
193-
[Shawn Chapla]: https://github.com/shwnchpl
194181
[Zhaolong Zhu]: https://github.com/zzl0
195182
[Zhiming Wang]: https://github.com/zmwangx
196-
[Bjørnar Smestad]: https://brendesmestad.no

litecli/packages/special/dbcommands.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,9 @@ def load_extension(cur, arg, **_):
215215
)
216216
def describe(cur, arg, **_):
217217
if arg:
218-
args = (arg,)
219218
query = """
220219
PRAGMA table_info({})
221-
""".format(args)
220+
""".format(arg)
222221
else:
223222
return list_tables(cur)
224223

tests/test_dbspecial.py

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from test_completion_engine import sorted_dicts
33
from litecli.packages.special.utils import format_uptime
44
from litecli.packages.special.utils import check_if_sqlitedotcommand
5+
from utils import run, dbtest, assert_result_equal
56

67

78
def test_import_first_argument():
@@ -88,3 +89,21 @@ def test_check_if_sqlitedotcommand():
8889
]
8990
for command, expected_result in test_cases:
9091
assert check_if_sqlitedotcommand(command) == expected_result
92+
93+
94+
@dbtest
95+
def test_special_d(executor):
96+
run(executor, """create table tst_tbl1(a text)""")
97+
results = run(executor, """\\d""")
98+
99+
assert_result_equal(results, headers=["name"], rows=[("tst_tbl1",)], status="")
100+
101+
102+
@dbtest
103+
def test_special_d_w_arg(executor):
104+
run(executor, """create table tst_tbl1(a text)""")
105+
results = run(executor, """\\d tst_tbl1""")
106+
107+
assert_result_equal(
108+
results, headers=["cid", "name", "type", "notnull", "dflt_value", "pk"], rows=[(0, "a", "TEXT", 0, None, 0)], status=""
109+
)

tests/test_sqlexecute.py

+1-25
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,10 @@
44

55
import pytest
66

7-
from utils import run, dbtest, set_expanded_output, is_expanded_output
7+
from utils import run, dbtest, set_expanded_output, is_expanded_output, assert_result_equal
88
from sqlite3 import OperationalError, ProgrammingError
99

1010

11-
def assert_result_equal(
12-
result,
13-
title=None,
14-
rows=None,
15-
headers=None,
16-
status=None,
17-
auto_status=True,
18-
assert_contains=False,
19-
):
20-
"""Assert that an sqlexecute.run() result matches the expected values."""
21-
if status is None and auto_status and rows:
22-
status = "{} row{} in set".format(len(rows), "s" if len(rows) > 1 else "")
23-
fields = {"title": title, "rows": rows, "headers": headers, "status": status}
24-
25-
if assert_contains:
26-
# Do a loose match on the results using the *in* operator.
27-
for key, field in fields.items():
28-
if field:
29-
assert field in result[0][key]
30-
else:
31-
# Do an exact match on the fields.
32-
assert result == [fields]
33-
34-
3511
@dbtest
3612
def test_conn(executor):
3713
run(executor, """create table test(a text)""")

tests/utils.py

+24
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,27 @@ def send_ctrl_c(wait_seconds):
8888
ctrl_c_process = multiprocessing.Process(target=send_ctrl_c_to_pid, args=(os.getpid(), wait_seconds))
8989
ctrl_c_process.start()
9090
return ctrl_c_process
91+
92+
93+
def assert_result_equal(
94+
result,
95+
title=None,
96+
rows=None,
97+
headers=None,
98+
status=None,
99+
auto_status=True,
100+
assert_contains=False,
101+
):
102+
"""Assert that an sqlexecute.run() result matches the expected values."""
103+
if status is None and auto_status and rows:
104+
status = "{} row{} in set".format(len(rows), "s" if len(rows) > 1 else "")
105+
fields = {"title": title, "rows": rows, "headers": headers, "status": status}
106+
107+
if assert_contains:
108+
# Do a loose match on the results using the *in* operator.
109+
for key, field in fields.items():
110+
if field:
111+
assert field in result[0][key]
112+
else:
113+
# Do an exact match on the fields.
114+
assert result == [fields]

0 commit comments

Comments
 (0)