Kaydet (Commit) c6525bea authored tarafından Mariusz Felisiak's avatar Mariusz Felisiak Kaydeden (comit) Tim Graham

Fixed #29534 -- Made dbshell use rlwrap on Oracle if available.

üst 9a88c6dd
import shutil
import subprocess
from django.db.backends.base.client import BaseDatabaseClient
......@@ -5,8 +6,12 @@ from django.db.backends.base.client import BaseDatabaseClient
class DatabaseClient(BaseDatabaseClient):
executable_name = 'sqlplus'
wrapper_name = 'rlwrap'
def runshell(self):
conn_string = self.connection._connect_string()
args = [self.executable_name, "-L", conn_string]
wrapper_path = shutil.which(self.wrapper_name)
if wrapper_path:
args = [wrapper_path, *args]
subprocess.check_call(args)
......@@ -185,6 +185,9 @@ Management Commands
* :djadmin:`inspectdb` now introspects :class:`~django.db.models.DurationField`
for Oracle and PostgreSQL.
* On Oracle, :djadmin:`dbshell` is wrapped with ``rlwrap``, if available.
``rlwrap`` provides a command history and editing of keyboard input.
Migrations
~~~~~~~~~~
......
from unittest import mock, skipUnless
from django.db import connection
from django.db.backends.oracle.client import DatabaseClient
from django.test import SimpleTestCase
@skipUnless(connection.vendor == 'oracle', 'Oracle tests')
class OracleDbshellTests(SimpleTestCase):
def _run_dbshell(self, rlwrap=False):
"""Run runshell command and capture its arguments."""
def _mock_subprocess_call(*args):
self.subprocess_args = tuple(*args)
return 0
client = DatabaseClient(connection)
self.subprocess_args = None
with mock.patch('subprocess.call', new=_mock_subprocess_call):
with mock.patch('shutil.which', return_value='/usr/bin/rlwrap' if rlwrap else None):
client.runshell()
return self.subprocess_args
def test_without_rlwrap(self):
self.assertEqual(
self._run_dbshell(rlwrap=False),
('sqlplus', '-L', connection._connect_string()),
)
def test_with_rlwrap(self):
self.assertEqual(
self._run_dbshell(rlwrap=True),
('/usr/bin/rlwrap', 'sqlplus', '-L', connection._connect_string()),
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment