rlwrap and manage.py dbshell

36 views
Skip to first unread message

Dan Davis

unread,
Jun 28, 2018, 1:15:05 PM6/28/18
to Django developers (Contributions to Django itself)

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

Adam Johnson

unread,
Jun 28, 2018, 2:56:03 PM6/28/18
to django-d...@googlegroups.com
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.

--
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-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
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

Dan Davis

unread,
Jun 28, 2018, 11:21:21 PM6/28/18
to django-d...@googlegroups.com
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.
Reply all
Reply to author
Forward
0 new messages