rlwrap and manage.py dbshell

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

rlwrap and manage.py dbshell

Dan Davis

After some work, I've modified django.db.backends.oracle.client in my virtual environment so that it will invoke Oracle's sqlplus within the excellent utility rlwrap.
In my shell, I have

* alias sqlplus='rlwrap --histsize 2000 sqlplus'

However, it is not secure for a project like Django to use subprocess.check_call with shell=True.

To turn this into a permanent feature, I'd need to:
  • Figure out how users should specify the path to rlwrap, or how to look for the rlwrap utilityp
  • Figure out how users should specify the size of history.

This could also be integrated with a 3rd party backend, such as django-oraclepool and django-oracle-drcp (the latter I've contributed to).

In any case, how would developers suggest I proceed to make this a basic option of the Oracle backend?

Thanks,

-Dan

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/5af25634-2093-451f-8b50-2c1dffb93cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: rlwrap and manage.py dbshell

Adam Johnson-2
Won't this do the trick?

diff --git a/django/db/backends/oracle/client.py b/django/db/backends/oracle/client.py
index 102e77fd15..1a0e1ca10b 100644
--- a/django/db/backends/oracle/client.py
+++ b/django/db/backends/oracle/client.py
@@ -8,5 +8,5 @@ class DatabaseClient(BaseDatabaseClient):
 
     def runshell(self):
         conn_string = self.connection._connect_string()
-        args = [self.executable_name, "-L", conn_string]
+        args = ['rlwrap', '--histsize', '2000', self.executable_name, "-L", conn_string]
         subprocess.check_call(args)

I'd suggest trying it in the third party backend first. Also the history size probably doesn't need an easy way to specify, you could just give it sensible default on a class level attribute on the DatabaseClient class so if it *really* needs specifying, projects can subclass their own backend.

On Thu, 28 Jun 2018 at 17:56, Dan Davis <[hidden email]> wrote:

After some work, I've modified django.db.backends.oracle.client in my virtual environment so that it will invoke Oracle's sqlplus within the excellent utility rlwrap.
In my shell, I have

* alias sqlplus='rlwrap --histsize 2000 sqlplus'

However, it is not secure for a project like Django to use subprocess.check_call with shell=True.

To turn this into a permanent feature, I'd need to:
  • Figure out how users should specify the path to rlwrap, or how to look for the rlwrap utilityp
  • Figure out how users should specify the size of history.

This could also be integrated with a 3rd party backend, such as django-oraclepool and django-oracle-drcp (the latter I've contributed to).

In any case, how would developers suggest I proceed to make this a basic option of the Oracle backend?

Thanks,

-Dan

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/5af25634-2093-451f-8b50-2c1dffb93cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Adam

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM0tg6iw85tx8ZuE%3DqyKyZouzxjBWc66sDBMkKiTf-F6XQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: rlwrap and manage.py dbshell

Dan Davis
Sure, but not everyone has rlwrap installed at all, or installed in the same place.
I guess the thing to do is to use shutil.which first.   I will prepare such a patch.


On Thu, Jun 28, 2018 at 2:55 PM Adam Johnson <[hidden email]> wrote:
Won't this do the trick?

diff --git a/django/db/backends/oracle/client.py b/django/db/backends/oracle/client.py
index 102e77fd15..1a0e1ca10b 100644
--- a/django/db/backends/oracle/client.py
+++ b/django/db/backends/oracle/client.py
@@ -8,5 +8,5 @@ class DatabaseClient(BaseDatabaseClient):
 
     def runshell(self):
         conn_string = self.connection._connect_string()
-        args = [self.executable_name, "-L", conn_string]
+        args = ['rlwrap', '--histsize', '2000', self.executable_name, "-L", conn_string]
         subprocess.check_call(args)

I'd suggest trying it in the third party backend first. Also the history size probably doesn't need an easy way to specify, you could just give it sensible default on a class level attribute on the DatabaseClient class so if it *really* needs specifying, projects can subclass their own backend.

On Thu, 28 Jun 2018 at 17:56, Dan Davis <[hidden email]> wrote:

After some work, I've modified django.db.backends.oracle.client in my virtual environment so that it will invoke Oracle's sqlplus within the excellent utility rlwrap.
In my shell, I have

* alias sqlplus='rlwrap --histsize 2000 sqlplus'

However, it is not secure for a project like Django to use subprocess.check_call with shell=True.

To turn this into a permanent feature, I'd need to:
  • Figure out how users should specify the path to rlwrap, or how to look for the rlwrap utilityp
  • Figure out how users should specify the size of history.

This could also be integrated with a 3rd party backend, such as django-oraclepool and django-oracle-drcp (the latter I've contributed to).

In any case, how would developers suggest I proceed to make this a basic option of the Oracle backend?

Thanks,

-Dan

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/5af25634-2093-451f-8b50-2c1dffb93cf8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Adam

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAMyDDM0tg6iw85tx8ZuE%3DqyKyZouzxjBWc66sDBMkKiTf-F6XQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CAFzonYbViyoNf5XPAvar3t_g_QnMfoU%3Dv%3D0neP-16Yr4yV9D1w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.