本文整理汇总了Python中django.db.backends.utils.CursorWrapper方法的典型用法代码示例。如果您正苦于以下问题:Python utils.CursorWrapper方法的具体用法?Python utils.CursorWrapper怎么用?Python utils.CursorWrapper使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.backends.utils
的用法示例。
在下文中一共展示了utils.CursorWrapper方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _reconfigureLogging
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import CursorWrapper [as 别名]
def _reconfigureLogging(self):
# Reconfigure the logging based on the debug mode of Django.
from django.conf import settings
if settings.DEBUG:
# In debug mode, force logging to debug mode.
logger.set_verbosity(3)
# When not in the developer environment, patch Django to not
# use the debug cursor. This is needed or Django will store in
# memory every SQL query made.
from provisioningserver.config import is_dev_environment
if not is_dev_environment():
from django.db.backends.base import base
from django.db.backends.utils import CursorWrapper
base.BaseDatabaseWrapper.make_debug_cursor = lambda self, cursor: CursorWrapper(
cursor, self
)
示例2: make_cursor
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import CursorWrapper [as 别名]
def make_cursor(self, cursor):
"""
Creates a cursor without debug logging.
"""
return utils.CursorWrapper(cursor, self)
示例3: make_cursor
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import CursorWrapper [as 别名]
def make_cursor(self, cursor):
"""Create a cursor without debug logging."""
return utils.CursorWrapper(cursor, self)
示例4: test_cursor_contextmanager
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import CursorWrapper [as 别名]
def test_cursor_contextmanager(self):
"""
Cursors can be used as a context manager
"""
with connection.cursor() as cursor:
self.assertIsInstance(cursor, CursorWrapper)
# Both InterfaceError and ProgrammingError seem to be used when
# accessing closed cursor (psycopg2 has InterfaceError, rest seem
# to use ProgrammingError).
with self.assertRaises(connection.features.closed_cursor_error_class):
# cursor should be closed, so no queries should be possible.
cursor.execute("SELECT 1" + connection.features.bare_select_suffix)
示例5: test_cursor_contextmanager_closing
# 需要导入模块: from django.db.backends import utils [as 别名]
# 或者: from django.db.backends.utils import CursorWrapper [as 别名]
def test_cursor_contextmanager_closing(self):
# There isn't a generic way to test that cursors are closed, but
# psycopg2 offers us a way to check that by closed attribute.
# So, run only on psycopg2 for that reason.
with connection.cursor() as cursor:
self.assertIsInstance(cursor, CursorWrapper)
self.assertTrue(cursor.closed)
# Unfortunately with sqlite3 the in-memory test database cannot be closed.