1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +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:
Adrian Holovaty 2006-04-13 04:35:00 +00:00
parent 47333f6d1e
commit b59d57e4d2
8 changed files with 65 additions and 2 deletions

View File

@ -1045,11 +1045,18 @@ def run_shell(use_plain=False):
code.interact() code.interact()
run_shell.args = '[--plain]' 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 # Utilities for command-line script
DEFAULT_ACTION_MAPPING = { DEFAULT_ACTION_MAPPING = {
'adminindex': get_admin_index, 'adminindex': get_admin_index,
'createcachetable' : createcachetable, 'createcachetable' : createcachetable,
'dbshell': dbshell,
'diffsettings': diffsettings, 'diffsettings': diffsettings,
'inspectdb': inspectdb, 'inspectdb': inspectdb,
'install': install, 'install': install,
@ -1072,11 +1079,12 @@ DEFAULT_ACTION_MAPPING = {
NO_SQL_TRANSACTION = ( NO_SQL_TRANSACTION = (
'adminindex', 'adminindex',
'createcachetable', 'createcachetable',
'dbshell',
'diffsettings', 'diffsettings',
'install', 'install',
'reset', 'reset',
'sqlindexes', 'sqlindexes',
'syncdb' 'syncdb',
) )
class DjangoOptionParser(OptionParser): class DjangoOptionParser(OptionParser):
@ -1138,7 +1146,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
if action == 'shell': if action == 'shell':
action_mapping[action](options.plain is True) action_mapping[action](options.plain is True)
elif action in ('syncdb', 'validate', 'diffsettings'): elif action in ('syncdb', 'validate', 'diffsettings', 'dbshell'):
action_mapping[action]() action_mapping[action]()
elif action == 'inspectdb': elif action == 'inspectdb':
try: try:

View File

@ -22,6 +22,7 @@ except ImportError, e:
get_introspection_module = lambda: __import__('django.db.backends.%s.introspection' % settings.DATABASE_ENGINE, '', '', ['']) 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, '', '', ['']) 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() connection = backend.DatabaseWrapper()
DatabaseError = backend.DatabaseError DatabaseError = backend.DatabaseError

View File

@ -0,0 +1,2 @@
def runshell():
raise NotImplementedError

View File

@ -0,0 +1,3 @@
from django.db.backends.dummy.base import complain
runshell = complain

View 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)

View 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)

View File

@ -0,0 +1,6 @@
from django.conf import settings
import os
def runshell():
args = ['', settings.DATABASE_NAME]
os.execvp('sqlite3', args)

View File

@ -64,6 +64,21 @@ backend. See the `cache documentation`_ for more information.
.. _cache documentation: http://www.djangoproject.com/documentation/cache/ .. _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 diffsettings
------------ ------------