... のデータベースコネクションを表します。データベースコネクションを利用するには、カーソルオブジェクトを取得するため connection.cursor() を呼び出してください。そして、 cursor.execute(sql, [params]) を呼び出して SQL を実行した後、 cursor.fetchone() もしくは ... ursor.fetchall() が結果の行を返します。 例: from django.db import connection def my_custom_sql ( self ): with connection . cursor () as cursor : cursor . execute ( "UPDATE bar SET foo = 1 WHERE baz = %s " , [ self . baz ]) cursor . execute ( "SELECT fo ... o FROM bar WHERE baz = %s " , [ self . baz ]) row = cursor . fetchone () return row SQLインジェクションから保護するために、SQL文字列の %s プレースホルダの前後に引用符を含めてはいけま ... ... のデータベースコネクションを表します。データベースコネクションを利用するには、カーソルオブジェクトを取得するため connection.cursor() を呼び出してください。そして、 cursor.execute(sql, [params]) を呼び出して SQL を実行した後、 cursor.fetchone() もしくは ... ursor.fetchall() が結果の行を返します。 例: from django.db import connection def my_custom_sql ( self ): with connection . cursor () as cursor : cursor . execute ( "UPDATE bar SET foo = 1 WHERE baz = %s " , [ self . baz ]) cursor . execute ( "SELECT fo ... o FROM bar WHERE baz = %s " , [ self . baz ]) row = cursor . fetchone () return row SQLインジェクションから保護するために、SQL文字列の %s プレースホルダの前後に引用符を含めてはいけま ... ... on PostgreSQL ¶ The change in Django 1.11 to make QuerySet.iterator() use server-side cursors on PostgreSQL prevents running Django with PgBouncer in transaction pooling mode. To reallow that, use the DISABLE_SERVER ... _SIDE_CURSORS setting in DATABASES . See トランザクションプールとサーバーサイドカーソル for more discussion. バグ修正 ¶ Made migrations ... #28059 ). Fixed crash in BaseGeometryWidget.subwidgets() ( #28039 ). Fixed exception reraising in ORM query execution when cursor.execute() fails and the subsequent cursor.close() also fails ( #28091 ). Fixed a regression where CheckboxSelectMultiple , ... ... ix (which returns FormMixin.prefix by default) to allow customizing the prefix of the form. Raw queries ( Manager.raw() or cursor.execute() ) can now use the "pyformat" parameter style, where placeholders in the query are given as '%(name)s' and the pa ... on Oracle, an exception is generated. No database change is needed for SQLite or PostgreSQL databases. Percent literals in cursor.execute queries ¶ When you are running raw SQL queries through the cursor.execute method, the rule about doubling percent ... ral percent characters if you are also providing replacement parameters. For example: # No parameters, no percent doubling cursor . execute ( "SELECT foo FROM bar WHERE baz = '30%'" ) # Parameters passed, non-placeholders have to be doubled cursor . ex ... ... on PostgreSQL ¶ The change in Django 1.11 to make QuerySet.iterator() use server-side cursors on PostgreSQL prevents running Django with PgBouncer in transaction pooling mode. To reallow that, use the DISABLE_SERVER ... _SIDE_CURSORS setting in DATABASES . See トランザクションプールとサーバーサイドカーソル for more discussion. バグ修正 ¶ Made migrations ... #28059 ). Fixed crash in BaseGeometryWidget.subwidgets() ( #28039 ). Fixed exception reraising in ORM query execution when cursor.execute() fails and the subsequent cursor.close() also fails ( #28091 ). Fixed a regression where CheckboxSelectMultiple , ... ... ix (which returns FormMixin.prefix by default) to allow customizing the prefix of the form. Raw queries ( Manager.raw() or cursor.execute() ) can now use the "pyformat" parameter style, where placeholders in the query are given as '%(name)s' and the pa ... on Oracle, an exception is generated. No database change is needed for SQLite or PostgreSQL databases. Percent literals in cursor.execute queries ¶ When you are running raw SQL queries through the cursor.execute method, the rule about doubling percent ... ral percent characters if you are also providing replacement parameters. For example: # No parameters, no percent doubling cursor . execute ( "SELECT foo FROM bar WHERE baz = '30%'" ) # Parameters passed, non-placeholders have to be doubled cursor . ex ... ... it was None on databases that support time zones. connection._nodb_connection property is changed to the connection._nodb_cursor() method and now returns a context manager that yields a cursor and automatically closes the cursor and connection upon ex ... ... it was None on databases that support time zones. connection._nodb_connection property is changed to the connection._nodb_cursor() method and now returns a context manager that yields a cursor and automatically closes the cursor and connection upon ex ... ... ser and server time zone are different, to clarify how the value inserted in the field will be interpreted. Using database cursors as context managers ¶ Prior to Python 2.7, database cursors could be used as a context manager. The specific backend's cu ... rsor defined the behavior of the context manager. The behavior of magic method lookups was changed with Python 2.7 and cursors were no longer usable as context managers. Django 1.7 allows a cursor to be used as a context manager. That is, the follo ... wing can be used: with connection . cursor () as c : c . execute ( ... ) 代わりに、次のようにします: c = connection . cursor () try : c . execute ( ... ) finally : c ... ... ser and server time zone are different, to clarify how the value inserted in the field will be interpreted. Using database cursors as context managers ¶ Prior to Python 2.7, database cursors could be used as a context manager. The specific backend's cu ... rsor defined the behavior of the context manager. The behavior of magic method lookups was changed with Python 2.7 and cursors were no longer usable as context managers. Django 1.7 allows a cursor to be used as a context manager. That is, the follo ... wing can be used: with connection . cursor () as c : c . execute ( ... ) 代わりに、次のようにします: c = connection . cursor () try : c . execute ( ... ) finally : c ... 2026年10月08日