{{{
./manage.py dbshell -c "select * from auth_group"
}}}
You have to use pipes, that are not always convenient:
{{{
echo "select * from auth_group" | ./manage.py dbshell
}}}
If we add `-c` argument, it would be in sync with `shell` command, where
you could provide commands already.
--
Ticket URL: <https://code.djangoproject.com/ticket/29501>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* version: 2.0 => master
* stage: Unreviewed => Accepted
Comment:
This seems reasonable, at first glance at least. The trick will be to pass
the command to each of the backend clients correctly, but there's no
reason that's not possible right? Accepting on that basis. A PR is very
welcome.
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:1>
* owner: nobody => Zijian He
* cc: Zijian He (added)
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:2>
* owner: Zijian He => cedric05
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:3>
* status: assigned => new
* owner: Shiva Prasanth => (none)
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:4>
Comment (by Artem Skoretskiy):
It should be easy to implement since we don’t need to use database-
specific backend
Something like that:
{{{
from django.db import connection
if command:
cursor = connection.cursor()
cursor.execute(command)
# show `cursor.fetchall()` result
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:5>
Comment (by Volodymyr Dmytriiev):
any progress on this one? Is the previously suggested approach good
enough? If so, I'd love to give a try?
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:6>
Comment (by Artem Skoretskiy):
No progress AKAIK.
Maybe it would be easier to call database-specific CLI tool with right
parameters than run cursor.
Pros:
* No need to care about printing results (user could execute SELECT)
* Could run commands that are unique for the CLI (e.g. \dt to show tables
in psql)
Cons:
* Each backend would need its own command to run (but we already have
dbshell, so we know name of binary; just need a parameter to execute a
query).
* Each backend would show results in its own format, so you cannot e. g.
save result as cab file)
Another completely different approach would be to pass all command line
arguments provided to dbshell, e.g. after “—“ divider to database CLI app.
For example:
{{{
./manage.py dbshell — -c “select * from auth_user”
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:7>
Comment (by Adam (Chainz) Johnson):
I don't think opening a cursor is the right way. My mental model of
dbshell is that it always passes through to the underlying tool, which can
have subtle implications on even what SQL/commands are accepted.
I am actually most in favour of passing all arguments through after a `--`
divider as that is the most flexible.
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:8>
* status: new => assigned
* owner: (none) => introquest
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:9>
* needs_docs: 0 => 1
* has_patch: 0 => 1
* needs_tests: 0 => 1
* stage: Accepted => Ready for checkin
Comment:
https://github.com/django/django/pull/10186
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:10>
* stage: Ready for checkin => Accepted
Comment:
"Ready for checkin" is set by a patch reviewer. And the patch isn't ready
for review without tests and documentation.
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:11>
Comment (by David Vaz):
So the PR is closed due to missing Tests and Documentation. Does anybody
care that I take this?
I could make a PR based on the original one and add tests and docs
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:12>
Comment (by Claude Paroz):
Absolutely, feel free to work on issues obviously stalled. Just credit
original patch writers if appropriate.
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:13>
* owner: introquest => Adam (Chainz) Johnson
* needs_docs: 1 => 0
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:14>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:15>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:16>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:17>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"5b884d45ac5b76234eca614d90c83b347294c332" 5b884d45]:
{{{
#!CommitTicketReference repository=""
revision="5b884d45ac5b76234eca614d90c83b347294c332"
Fixed #29501 -- Allowed dbshell to pass options to underlying tool.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:22>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"6cad911674dc067ffab44eea4f5c8170fa0a89b1" 6cad9116]:
{{{
#!CommitTicketReference repository=""
revision="6cad911674dc067ffab44eea4f5c8170fa0a89b1"
Refs #29501 -- Simplified BaseCommand.run_from_argv() a bit.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:20>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"8189976663eb160bfd4b2ae44fd5250da1089744" 8189976]:
{{{
#!CommitTicketReference repository=""
revision="8189976663eb160bfd4b2ae44fd5250da1089744"
Refs #29501 -- Added test for missing dbshell executable.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:18>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"8bd9000a7db3dcf14b003e8ef18137ea1296c07b" 8bd9000]:
{{{
#!CommitTicketReference repository=""
revision="8bd9000a7db3dcf14b003e8ef18137ea1296c07b"
Refs #29501 -- Made dbshell catch more specific FileNotFoundError.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:19>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"8e8c3f964e23e669fc563a74750e51abba4c2e3a" 8e8c3f96]:
{{{
#!CommitTicketReference repository=""
revision="8e8c3f964e23e669fc563a74750e51abba4c2e3a"
Refs #29501 -- Allowed customizing exit status for management commands.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29501#comment:21>