summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-04-13 04:35:00 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-04-13 04:35:00 +0000
commitb59d57e4d23698351d367c8f42d79ed2bc7c295a (patch)
treead3c0fc274f842dec7bce8b5f6aff0032fea3322 /django
parent47333f6d1e3086aa0fb7d0bddb888bea8fb76526 (diff)
magic-removal: Fixed #1631 -- Added 'django-admin.py dbshell' command, which runs the command-line client for your database engine with your connection settings. Thanks, Paul Bissex
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2693 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
-rw-r--r--django/core/management.py12
-rw-r--r--django/db/__init__.py1
-rw-r--r--django/db/backends/ado_mssql/client.py2
-rw-r--r--django/db/backends/dummy/client.py3
-rw-r--r--django/db/backends/mysql/client.py14
-rw-r--r--django/db/backends/postgresql/client.py14
-rw-r--r--django/db/backends/sqlite3/client.py6
7 files changed, 50 insertions, 2 deletions
diff --git a/django/core/management.py b/django/core/management.py
index c4ce4cbf71..6b26d8b58a 100644
--- a/django/core/management.py
+++ b/django/core/management.py
@@ -1045,11 +1045,18 @@ def run_shell(use_plain=False):
code.interact()
run_shell.args = '[--plain]'
+def dbshell():
+ "Runs the command-line client for the current DATABASE_ENGINE."
+ from django.db import runshell
+ runshell()
+dbshell.args = ""
+
# Utilities for command-line script
DEFAULT_ACTION_MAPPING = {
'adminindex': get_admin_index,
'createcachetable' : createcachetable,
+ 'dbshell': dbshell,
'diffsettings': diffsettings,
'inspectdb': inspectdb,
'install': install,
@@ -1072,11 +1079,12 @@ DEFAULT_ACTION_MAPPING = {
NO_SQL_TRANSACTION = (
'adminindex',
'createcachetable',
+ 'dbshell',
'diffsettings',
'install',
'reset',
'sqlindexes',
- 'syncdb'
+ 'syncdb',
)
class DjangoOptionParser(OptionParser):
@@ -1138,7 +1146,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
if action == 'shell':
action_mapping[action](options.plain is True)
- elif action in ('syncdb', 'validate', 'diffsettings'):
+ elif action in ('syncdb', 'validate', 'diffsettings', 'dbshell'):
action_mapping[action]()
elif action == 'inspectdb':
try:
diff --git a/django/db/__init__.py b/django/db/__init__.py
index c7584a9bd3..317d6059bf 100644
--- a/django/db/__init__.py
+++ b/django/db/__init__.py
@@ -22,6 +22,7 @@ except ImportError, e:
get_introspection_module = lambda: __import__('django.db.backends.%s.introspection' % settings.DATABASE_ENGINE, '', '', [''])
get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, '', '', [''])
+runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, '', '', ['']).runshell()
connection = backend.DatabaseWrapper()
DatabaseError = backend.DatabaseError
diff --git a/django/db/backends/ado_mssql/client.py b/django/db/backends/ado_mssql/client.py
new file mode 100644
index 0000000000..5c197cafa4
--- /dev/null
+++ b/django/db/backends/ado_mssql/client.py
@@ -0,0 +1,2 @@
+def runshell():
+ raise NotImplementedError
diff --git a/django/db/backends/dummy/client.py b/django/db/backends/dummy/client.py
new file mode 100644
index 0000000000..e332987aa8
--- /dev/null
+++ b/django/db/backends/dummy/client.py
@@ -0,0 +1,3 @@
+from django.db.backends.dummy.base import complain
+
+runshell = complain
diff --git a/django/db/backends/mysql/client.py b/django/db/backends/mysql/client.py
new file mode 100644
index 0000000000..f9d6297b8e
--- /dev/null
+++ b/django/db/backends/mysql/client.py
@@ -0,0 +1,14 @@
+from django.conf import settings
+import os
+
+def runshell():
+ args = ['']
+ args += ["--user=%s" % settings.DATABASE_USER]
+ if settings.DATABASE_PASSWORD:
+ args += ["--password=%s" % settings.DATABASE_PASSWORD]
+ if settings.DATABASE_HOST:
+ args += ["--host=%s" % settings.DATABASE_HOST]
+ if settings.DATABASE_PORT:
+ args += ["--port=%s" % settings.DATABASE_PORT]
+ args += [settings.DATABASE_NAME]
+ os.execvp('mysql', args)
diff --git a/django/db/backends/postgresql/client.py b/django/db/backends/postgresql/client.py
new file mode 100644
index 0000000000..3d0d7a0d2a
--- /dev/null
+++ b/django/db/backends/postgresql/client.py
@@ -0,0 +1,14 @@
+from django.conf import settings
+import os
+
+def runshell():
+ args = ['']
+ args += ["-U%s" % settings.DATABASE_USER]
+ if settings.DATABASE_PASSWORD:
+ args += ["-W"]
+ if settings.DATABASE_HOST:
+ args += ["-h %s" % settings.DATABASE_HOST]
+ if settings.DATABASE_PORT:
+ args += ["-p %s" % settings.DATABASE_PORT]
+ args += [settings.DATABASE_NAME]
+ os.execvp('psql', args)
diff --git a/django/db/backends/sqlite3/client.py b/django/db/backends/sqlite3/client.py
new file mode 100644
index 0000000000..097218341f
--- /dev/null
+++ b/django/db/backends/sqlite3/client.py
@@ -0,0 +1,6 @@
+from django.conf import settings
+import os
+
+def runshell():
+ args = ['', settings.DATABASE_NAME]
+ os.execvp('sqlite3', args)