mirror of
https://github.com/django/django.git
synced 2025-07-04 09:49:12 +00:00
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
This commit is contained in:
parent
47333f6d1e
commit
b59d57e4d2
@ -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:
|
||||
|
@ -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
|
||||
|
2
django/db/backends/ado_mssql/client.py
Normal file
2
django/db/backends/ado_mssql/client.py
Normal file
@ -0,0 +1,2 @@
|
||||
def runshell():
|
||||
raise NotImplementedError
|
3
django/db/backends/dummy/client.py
Normal file
3
django/db/backends/dummy/client.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db.backends.dummy.base import complain
|
||||
|
||||
runshell = complain
|
14
django/db/backends/mysql/client.py
Normal file
14
django/db/backends/mysql/client.py
Normal file
@ -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)
|
14
django/db/backends/postgresql/client.py
Normal file
14
django/db/backends/postgresql/client.py
Normal file
@ -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)
|
6
django/db/backends/sqlite3/client.py
Normal file
6
django/db/backends/sqlite3/client.py
Normal file
@ -0,0 +1,6 @@
|
||||
from django.conf import settings
|
||||
import os
|
||||
|
||||
def runshell():
|
||||
args = ['', settings.DATABASE_NAME]
|
||||
os.execvp('sqlite3', args)
|
@ -64,6 +64,21 @@ backend. See the `cache documentation`_ for more information.
|
||||
|
||||
.. _cache documentation: http://www.djangoproject.com/documentation/cache/
|
||||
|
||||
dbshell
|
||||
-------
|
||||
|
||||
Runs the command-line client for the database engine specified in your
|
||||
``DATABASE_ENGINE`` setting, with the connection parameters specified in your
|
||||
``DATABASE_USER``, ``DATABASE_PASSWORD``, etc., settings.
|
||||
|
||||
* For PostgreSQL, this runs the ``psql`` command-line client.
|
||||
* For MySQL, this runs the ``mysql`` command-line client.
|
||||
* For SQLite, this runs the ``sqlite3`` command-line client.
|
||||
|
||||
This command assumes the programs are on your PATH so that a simple call to
|
||||
the program name (``psql``, ``mysql``, ``sqlite3``) will find the program in
|
||||
the right place.
|
||||
|
||||
diffsettings
|
||||
------------
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user