Hi

dbshell already passes all unknown arguments through to the underlying
program. For example on postgres you can use the psql '-c' option like so:

$ ./manage.py dbshell -c 'select 123'
 ?column?
----------
      123
(1 row)

argparse allows a -- separator to split arguments for dbshell and the
underlying program, so you can even use "shadowed" options like --help like
so:

$ ./manage.py dbshell -- --help
psql is the PostgreSQL interactive terminal.

Usage:
  psql [OPTION]... [DBNAME [USERNAME]]

General options:
...

This should allow you to pass your scripts through to the oracle tool, if I
understand your request correctly.

Thanks,

Adam

On Tue, Jul 5, 2022 at 5:12 PM dans...@gmail.com <dansm...@gmail.com> wrote:

> In Adam's blog post
> https://adamj.eu/tech/2022/06/29/run-a-django-migration-by-hand/, he
> shows a pattern I've used in the past.
>
> Would it be useful to support passing an optional positional argument to
> dbshell that is then passed to the dbshell program appropriately?   e.g.,
> with @filename for Oracle sqlplus or directly to mysql?  I suppose that
> might introduce new code to DatabaseOperations, but not too much.   I think
> only  Oracle's DatabaseOperations would be different.
>
> I've had to extend Django to run some old PL/SQL via management commands.
> This helped me with my 16 year old database to replace scripts that used
> combinations of bash, ksh, sh, expect, perl, sqlplus, and PL/SQL with just
> two three technologies - namely Python, Django, and PL/SQL.  However, since
> there are 20k lines of PL/SQL and 25k lines of Python, making the PL/SQL go
> away is not yet a priority.
>
> I've done it basically by using code like this in a management command:
>
> https://gist.github.com/danizen/a3b5e3f8514be90b796f298dfb52f99e
>
> If you look at the "run_report" method of the basereport.py, you'll see
> that I am using os.pipe() and os.dup2() to enable passing the output of a
> template to dbshell.  This is in case there is any sqlplus reliance in
> these old reports.  In my case, it will be better to assure that all of
> this report code can run in management commands or directly via cursor
> execute - and so I haven't proposed this for my use case.
>
> The one that Adam proposes makes a much better use case for this
> additional positional argument to dbshell.
>
> Has this been discussed before?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/aeb4ef0d-e8d6-46c6-9aaa-167abd5de3e5n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/aeb4ef0d-e8d6-46c6-9aaa-167abd5de3e5n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM0w%2B4geWmO5xwVVPnvgkayZ4hjDRfzQZnW9UmQnzpiYZA%40mail.gmail.com.
  • Add... dans...@gmail.com
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)

Reply via email to