class BaseDatabaseOperations: (source)
Known subclasses: django.db.backends.dummy.base.DatabaseOperations
, django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Encapsulate backend-specific differences, such as the way a backend performs ordering or calculates the ID of a recently-inserted row.
Method | __init__ |
Undocumented |
Method | adapt |
Transform a date value to an object compatible with what is expected by the backend driver for date columns. |
Method | adapt |
Transform a datetime value to an object compatible with what is expected by the backend driver for datetime columns. |
Method | adapt |
Transform a decimal.Decimal value to an object compatible with what is expected by the backend driver for decimal (numeric) columns. |
Method | adapt |
Transform a string representation of an IP address into the expected type for the backend driver. |
Method | adapt |
Transform a time value to an object compatible with what is expected by the backend driver for time columns. |
Method | adapt |
Transform a value to something compatible with the backend driver. |
Method | autoinc |
Return any SQL needed to support auto-incrementing primary keys, or None if no SQL is necessary. |
Method | binary |
Some backends require special syntax to insert binary content (MySQL for example uses '_binary %s'). |
Method | bulk |
Return the maximum allowed batch size for the backend. The fields are the fields going to be inserted in the batch, the objs contains all the objects to be inserted. |
Method | cache |
Return an SQL query that retrieves the first cache key greater than the n smallest. |
Method | check |
Check that the backend supports the provided expression. |
Method | combine |
Undocumented |
Method | combine |
Combine a list of subexpressions into a single expression, using the provided connecting operator. This is required because operators can vary between backends (e.g., Oracle with %% and &) and between subexpression types (e... |
Method | compiler |
Return the SQLCompiler class corresponding to the given name, in the namespace corresponding to the `compiler_module` attribute on this backend. |
Method | conditional |
Return True, if the conditional expression is supported in the WHERE clause. |
Method | convert |
Undocumented |
Method | date |
Given a lookup_type of 'year', 'month', or 'day', return the SQL that extracts a value from the given date field field_name. |
Method | date |
Given a lookup_type of 'year', 'month', or 'day', return the SQL that truncates the given date or datetime field field_name to a date object with only the given specificity. |
Method | datetime |
Return the SQL to cast a datetime value to date value. |
Method | datetime |
Return the SQL to cast a datetime value to time value. |
Method | datetime |
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute', or 'second', return the SQL that extracts a value from the given datetime field field_name. |
Method | datetime |
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute', or 'second', return the SQL that truncates the given datetime field field_name to a datetime object with only the given specificity. |
Method | deferrable |
Return the SQL to make a constraint "initially deferred" during a CREATE TABLE statement. |
Method | distinct |
Return an SQL DISTINCT clause which removes duplicate rows from the result set. If any fields are given, only check the given fields for duplicates. |
Method | end |
Return the SQL statement required to end a transaction. |
Method | execute |
Execute a list of SQL statements to flush the database. |
Method | explain |
Undocumented |
Method | fetch |
Given a cursor object that has just performed an INSERT...RETURNING statement into a table, return the newly created data. |
Method | field |
Given a column type (e.g. 'BLOB', 'VARCHAR') and an internal type (e.g. 'GenericIPAddressField'), return the SQL to cast it before using it in a WHERE statement. The resulting string should contain a '%s' placeholder for the column being searched against. |
Method | for |
Return the FOR UPDATE SQL clause to lock rows for an update operation. |
Method | force |
Return a list used in the "ORDER BY" clause to force no ordering at all. Return an empty list to include nothing in the ordering. |
Method | format |
Undocumented |
Method | get |
Return a list of functions needed to convert field data. |
Method | insert |
Undocumented |
Method | integer |
Given an integer field internal type (e.g. 'PositiveIntegerField'), return a tuple of the (min_value, max_value) form representing the range of the column type bound to the field. |
Method | last |
Return a string of the query last executed by the given cursor, with placeholders replaced with actual values. |
Method | last |
Given a cursor object that has just performed an INSERT statement into a table that has an auto-incrementing ID, return the newly created ID. |
Method | limit |
Return LIMIT/OFFSET SQL clause. |
Method | lookup |
Return the string to use in a query when performing lookups ("contains", "like", etc.). It should contain a '%s' placeholder for the column being searched against. |
Method | max |
Return the maximum number of items that can be passed in a single 'IN' list condition, or None if the backend does not impose a limit. |
Method | max |
Return the maximum length of table and column names, or None if there is no limit. |
Method | modify |
Allow modification of insert parameters. Needed for Oracle Spatial backend due to #10888. |
Method | no |
Return the value to use for the LIMIT when we are wanting "LIMIT infinity". Return None if the limit clause can be omitted in this case. |
Method | on |
Undocumented |
Method | pk |
Return the value to use during an INSERT statement to specify that the field should use its default value. |
Method | prep |
Prepare a value for use in a LIKE query. |
Method | prepare |
Take an SQL script that may contain multiple lines and return a list of statements to feed to successive cursor.execute() calls. |
Method | process |
Return the value of a CLOB column, for backends that return a locator object that requires additional processing. |
Method | quote |
Return a quoted version of the given table, index, or column name. Do not quote the given name if it's already been quoted. |
Method | regex |
Return the string to use in a query when performing regular expression lookups (using "regex" or "iregex"). It should contain a '%s' placeholder for the column being searched against. |
Method | return |
For backends that support returning columns as part of an insert query, return the SQL and params to append to the INSERT query. The returned fragment should contain a format string to hold the appropriate column. |
Method | savepoint |
Return the SQL for committing the given savepoint. |
Method | savepoint |
Return the SQL for starting a new savepoint. Only required if the "uses_savepoints" feature is True. The "sid" parameter is a string for the savepoint id. |
Method | savepoint |
Return the SQL for rolling back the given savepoint. |
Method | sequence |
Return a list of the SQL statements required to reset sequences passed in `sequences`. |
Method | sequence |
Return a list of the SQL statements required to reset sequences for the given models. |
Method | set |
Return the SQL that will set the connection's time zone. |
Method | sql |
Return a list of SQL statements required to remove all data from the given database tables (without actually removing the tables themselves). |
Method | start |
Return the SQL statement required to start a transaction. |
Method | subtract |
Undocumented |
Method | tablespace |
Return the SQL that will be used in a query to define the tablespace. |
Method | time |
Given a lookup_type of 'hour', 'minute', or 'second', return the SQL that extracts a value from the given time field field_name. |
Method | time |
Given a lookup_type of 'hour', 'minute' or 'second', return the SQL that truncates the given time or datetime field field_name to a time object with only the given specificity. |
Method | unification |
Given a field instance, return the SQL that casts the result of a union to that type. The resulting string should contain a '%s' placeholder for the expression being cast. |
Method | validate |
Certain backends do not accept some values for "serial" fields (for example zero in MySQL). Raise a ValueError if the value is invalid, otherwise return the validated value. |
Method | window |
Undocumented |
Method | window |
Undocumented |
Method | window |
Return SQL for start and end points in an OVER clause window frame. |
Method | window |
Undocumented |
Method | year |
Return a two-elements list with the lower and upper bound to be used with a BETWEEN operator to query a DateField value using a year lookup. |
Method | year |
Return a two-elements list with the lower and upper bound to be used with a BETWEEN operator to query a DateTimeField value using a year lookup. |
Constant | CURRENT |
Undocumented |
Constant | FOLLOWING |
Undocumented |
Constant | PRECEDING |
Undocumented |
Constant | UNBOUNDED |
Undocumented |
Constant | UNBOUNDED |
Undocumented |
Class Variable | cast |
Undocumented |
Class Variable | cast |
Undocumented |
Class Variable | compiler |
Undocumented |
Class Variable | explain |
Undocumented |
Class Variable | integer |
Undocumented |
Class Variable | set |
Undocumented |
Instance Variable | connection |
Undocumented |
Method | _get |
Undocumented |
Instance Variable | _cache |
Undocumented |
django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
Transform a date value to an object compatible with what is expected by the backend driver for date columns.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Transform a datetime value to an object compatible with what is expected by the backend driver for datetime columns.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
Transform a decimal.Decimal value to an object compatible with what is expected by the backend driver for decimal (numeric) columns.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Transform a time value to an object compatible with what is expected by the backend driver for time columns.
Transform a value to something compatible with the backend driver. This method only depends on the type of the value. It's designed for cases where the target type isn't known, such as .raw() SQL queries. As a consequence it may not work perfectly in all circumstances.
Return any SQL needed to support auto-incrementing primary keys, or None if no SQL is necessary. This SQL is executed when a table is created.
django.db.backends.mysql.operations.DatabaseOperations
Some backends require special syntax to insert binary content (MySQL for example uses '_binary %s').
django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return the maximum allowed batch size for the backend. The fields are the fields going to be inserted in the batch, the objs contains all the objects to be inserted.
django.db.backends.oracle.operations.DatabaseOperations
Return an SQL query that retrieves the first cache key greater than the n smallest. This is used by the 'db' cache backend to determine where to start culling.
django.db.backends.sqlite3.operations.DatabaseOperations
Check that the backend supports the provided expression. This is used on specific backends to rule out known expressions that have problematic or nonexistent implementations. If the expression has a known problem, the backend should raise NotSupportedError.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Combine a list of subexpressions into a single expression, using the provided connecting operator. This is required because operators can vary between backends (e.g., Oracle with %% and &) and between subexpression types (e.g., date expressions).
Return the SQLCompiler class corresponding to the given name, in the namespace corresponding to the `compiler_module` attribute on this backend.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
Return True, if the conditional expression is supported in the WHERE clause.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Given a lookup_type of 'year', 'month', or 'day', return the SQL that extracts a value from the given date field field_name.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Given a lookup_type of 'year', 'month', or 'day', return the SQL that truncates the given date or datetime field field_name to a date object with only the given specificity. If `tzname` is provided, the given value is truncated in a specific timezone.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return the SQL to cast a datetime value to date value.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return the SQL to cast a datetime value to time value.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute', or 'second', return the SQL that extracts a value from the given datetime field field_name.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute', or 'second', return the SQL that truncates the given datetime field field_name to a datetime object with only the given specificity.
django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
Return the SQL to make a constraint "initially deferred" during a CREATE TABLE statement.
Return an SQL DISTINCT clause which removes duplicate rows from the result set. If any fields are given, only check the given fields for duplicates.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
Undocumented
django.db.backends.oracle.operations.DatabaseOperations
Given a cursor object that has just performed an INSERT...RETURNING statement into a table, return the newly created data.
django.db.backends.oracle.operations.DatabaseOperations
Given a column type (e.g. 'BLOB', 'VARCHAR') and an internal type (e.g. 'GenericIPAddressField'), return the SQL to cast it before using it in a WHERE statement. The resulting string should contain a '%s' placeholder for the column being searched against.
django.db.backends.mysql.operations.DatabaseOperations
Return a list used in the "ORDER BY" clause to force no ordering at all. Return an empty list to include nothing in the ordering.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Undocumented
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return a list of functions needed to convert field data. Some field types on some backends do not provide data in the correct format, this is the hook for converter functions.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Undocumented
django.db.backends.sqlite3.operations.DatabaseOperations
Given an integer field internal type (e.g. 'PositiveIntegerField'), return a tuple of the (min_value, max_value) form representing the range of the column type bound to the field.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return a string of the query last executed by the given cursor, with placeholders replaced with actual values. `sql` is the raw query containing placeholders and `params` is the sequence of parameters. These are used by default, but this method exists for database backends to provide a better implementation according to their own quoting schemes.
django.db.backends.oracle.operations.DatabaseOperations
Given a cursor object that has just performed an INSERT statement into a table that has an auto-incrementing ID, return the newly created ID. `pk_name` is the name of the primary-key column.
django.db.backends.oracle.operations.DatabaseOperations
Return LIMIT/OFFSET SQL clause.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
Return the string to use in a query when performing lookups ("contains", "like", etc.). It should contain a '%s' placeholder for the column being searched against.
django.db.backends.oracle.operations.DatabaseOperations
Return the maximum number of items that can be passed in a single 'IN' list condition, or None if the backend does not impose a limit.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
Return the maximum length of table and column names, or None if there is no limit.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return the value to use for the LIMIT when we are wanting "LIMIT infinity". Return None if the limit clause can be omitted in this case.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return the value to use during an INSERT statement to specify that the field should use its default value.
Take an SQL script that may contain multiple lines and return a list of statements to feed to successive cursor.execute() calls. Since few databases are able to process raw SQL scripts in a single cursor.execute() call and PEP 249 doesn't talk about this use case, the default implementation is conservative.
django.db.backends.oracle.operations.DatabaseOperations
Return the value of a CLOB column, for backends that return a locator object that requires additional processing.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return a quoted version of the given table, index, or column name. Do not quote the given name if it's already been quoted.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
Return the string to use in a query when performing regular expression lookups (using "regex" or "iregex"). It should contain a '%s' placeholder for the column being searched against. If the feature is not supported (or part of it is not supported), raise NotImplementedError.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
For backends that support returning columns as part of an insert query, return the SQL and params to append to the INSERT query. The returned fragment should contain a format string to hold the appropriate column.
Return the SQL for starting a new savepoint. Only required if the "uses_savepoints" feature is True. The "sid" parameter is a string for the savepoint id.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return a list of the SQL statements required to reset sequences passed in `sequences`. The `style` argument is a Style object as returned by either color_style() or no_style() in django.core.management.color.
django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
Return a list of the SQL statements required to reset sequences for the given models. The `style` argument is a Style object as returned by either color_style() or no_style() in django.core.management.color.
Return the SQL that will set the connection's time zone. Return '' if the backend doesn't support time zones.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Return a list of SQL statements required to remove all data from the given database tables (without actually removing the tables themselves). The `style` argument is a Style object as returned by either color_style() or no_style() in django.core.management.color. If `reset_sequences` is True, the list includes SQL statements required to reset the sequences. The `allow_cascade` argument determines whether truncation may cascade to tables with foreign keys pointing the tables being truncated. PostgreSQL requires a cascade even if these tables are empty.
django.db.backends.oracle.operations.DatabaseOperations
Return the SQL statement required to start a transaction.
django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
Return the SQL that will be used in a query to define the tablespace. Return '' if the backend doesn't support tablespaces. If `inline` is True, append the SQL to a row; otherwise append it to the entire CREATE TABLE or CREATE INDEX statement.
django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Given a lookup_type of 'hour', 'minute', or 'second', return the SQL that extracts a value from the given time field field_name.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
, django.db.backends.postgresql.operations.DatabaseOperations
, django.db.backends.sqlite3.operations.DatabaseOperations
Given a lookup_type of 'hour', 'minute' or 'second', return the SQL that truncates the given time or datetime field field_name to a time object with only the given specificity. If `tzname` is provided, the given value is truncated in a specific timezone.
Given a field instance, return the SQL that casts the result of a union to that type. The resulting string should contain a '%s' placeholder for the expression being cast.
django.db.backends.mysql.operations.DatabaseOperations
Certain backends do not accept some values for "serial" fields (for example zero in MySQL). Raise a ValueError if the value is invalid, otherwise return the validated value.
Return a two-elements list with the lower and upper bound to be used with a BETWEEN operator to query a DateField value using a year lookup. `value` is an int, containing the looked-up year. If `iso_year` is True, return bounds for ISO-8601 week-numbering years.
Return a two-elements list with the lower and upper bound to be used with a BETWEEN operator to query a DateTimeField value using a year lookup. `value` is an int, containing the looked-up year. If `iso_year` is True, return bounds for ISO-8601 week-numbering years.
django.db.backends.mysql.operations.DatabaseOperations
, django.db.backends.oracle.operations.DatabaseOperations
Undocumented