You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

base.py 2.5 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. """
  2. Dummy database backend for Django.
  3. Django uses this if the database ENGINE setting is empty (None or empty string).
  4. Each of these API functions, except connection.close(), raises
  5. ImproperlyConfigured.
  6. """
  7. from django.core.exceptions import ImproperlyConfigured
  8. from django.db.backends.base.base import BaseDatabaseWrapper
  9. from django.db.backends.base.client import BaseDatabaseClient
  10. from django.db.backends.base.creation import BaseDatabaseCreation
  11. from django.db.backends.base.introspection import BaseDatabaseIntrospection
  12. from django.db.backends.base.operations import BaseDatabaseOperations
  13. from django.db.backends.base.validation import BaseDatabaseValidation
  14. from django.db.backends.dummy.features import DummyDatabaseFeatures
  15. def complain(*args, **kwargs):
  16. raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
  17. "Please supply the ENGINE value. Check "
  18. "settings documentation for more details.")
  19. def ignore(*args, **kwargs):
  20. pass
  21. class DatabaseError(Exception):
  22. pass
  23. class IntegrityError(DatabaseError):
  24. pass
  25. class DatabaseOperations(BaseDatabaseOperations):
  26. quote_name = complain
  27. class DatabaseClient(BaseDatabaseClient):
  28. runshell = complain
  29. class DatabaseCreation(BaseDatabaseCreation):
  30. create_test_db = ignore
  31. destroy_test_db = ignore
  32. class DatabaseIntrospection(BaseDatabaseIntrospection):
  33. get_table_list = complain
  34. get_table_description = complain
  35. get_relations = complain
  36. get_indexes = complain
  37. get_key_columns = complain
  38. class DatabaseWrapper(BaseDatabaseWrapper):
  39. operators = {}
  40. # Override the base class implementations with null
  41. # implementations. Anything that tries to actually
  42. # do something raises complain; anything that tries
  43. # to rollback or undo something raises ignore.
  44. _cursor = complain
  45. ensure_connection = complain
  46. _commit = complain
  47. _rollback = ignore
  48. _close = ignore
  49. _savepoint = ignore
  50. _savepoint_commit = complain
  51. _savepoint_rollback = ignore
  52. _set_autocommit = complain
  53. def __init__(self, *args, **kwargs):
  54. super(DatabaseWrapper, self).__init__(*args, **kwargs)
  55. self.features = DummyDatabaseFeatures(self)
  56. self.ops = DatabaseOperations(self)
  57. self.client = DatabaseClient(self)
  58. self.creation = DatabaseCreation(self)
  59. self.introspection = DatabaseIntrospection(self)
  60. self.validation = BaseDatabaseValidation(self)
  61. def is_usable(self):
  62. return True