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.

operations.py 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. import datetime
  2. import decimal
  3. from importlib import import_module
  4. import sqlparse
  5. from django.conf import settings
  6. from django.db import NotSupportedError, transaction
  7. from django.db.backends import utils
  8. from django.utils import timezone
  9. from django.utils.encoding import force_text
  10. class BaseDatabaseOperations:
  11. """
  12. Encapsulate backend-specific differences, such as the way a backend
  13. performs ordering or calculates the ID of a recently-inserted row.
  14. """
  15. compiler_module = "django.db.models.sql.compiler"
  16. # Integer field safe ranges by `internal_type` as documented
  17. # in docs/ref/models/fields.txt.
  18. integer_field_ranges = {
  19. 'SmallIntegerField': (-32768, 32767),
  20. 'IntegerField': (-2147483648, 2147483647),
  21. 'BigIntegerField': (-9223372036854775808, 9223372036854775807),
  22. 'PositiveSmallIntegerField': (0, 32767),
  23. 'PositiveIntegerField': (0, 2147483647),
  24. }
  25. set_operators = {
  26. 'union': 'UNION',
  27. 'intersection': 'INTERSECT',
  28. 'difference': 'EXCEPT',
  29. }
  30. # Mapping of Field.get_internal_type() (typically the model field's class
  31. # name) to the data type to use for the Cast() function, if different from
  32. # DatabaseWrapper.data_types.
  33. cast_data_types = {}
  34. # CharField data type if the max_length argument isn't provided.
  35. cast_char_field_without_max_length = None
  36. # Start and end points for window expressions.
  37. PRECEDING = 'PRECEDING'
  38. FOLLOWING = 'FOLLOWING'
  39. UNBOUNDED_PRECEDING = 'UNBOUNDED ' + PRECEDING
  40. UNBOUNDED_FOLLOWING = 'UNBOUNDED ' + FOLLOWING
  41. CURRENT_ROW = 'CURRENT ROW'
  42. # Prefix for EXPLAIN queries, or None EXPLAIN isn't supported.
  43. explain_prefix = None
  44. def __init__(self, connection):
  45. self.connection = connection
  46. self._cache = None
  47. def autoinc_sql(self, table, column):
  48. """
  49. Return any SQL needed to support auto-incrementing primary keys, or
  50. None if no SQL is necessary.
  51. This SQL is executed when a table is created.
  52. """
  53. return None
  54. def bulk_batch_size(self, fields, objs):
  55. """
  56. Return the maximum allowed batch size for the backend. The fields
  57. are the fields going to be inserted in the batch, the objs contains
  58. all the objects to be inserted.
  59. """
  60. return len(objs)
  61. def cache_key_culling_sql(self):
  62. """
  63. Return an SQL query that retrieves the first cache key greater than the
  64. n smallest.
  65. This is used by the 'db' cache backend to determine where to start
  66. culling.
  67. """
  68. return "SELECT cache_key FROM %s ORDER BY cache_key LIMIT 1 OFFSET %%s"
  69. def unification_cast_sql(self, output_field):
  70. """
  71. Given a field instance, return the SQL that casts the result of a union
  72. to that type. The resulting string should contain a '%s' placeholder
  73. for the expression being cast.
  74. """
  75. return '%s'
  76. def date_extract_sql(self, lookup_type, field_name):
  77. """
  78. Given a lookup_type of 'year', 'month', or 'day', return the SQL that
  79. extracts a value from the given date field field_name.
  80. """
  81. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a date_extract_sql() method')
  82. def date_interval_sql(self, timedelta):
  83. """
  84. Implement the date interval functionality for expressions.
  85. """
  86. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a date_interval_sql() method')
  87. def date_trunc_sql(self, lookup_type, field_name):
  88. """
  89. Given a lookup_type of 'year', 'month', or 'day', return the SQL that
  90. truncates the given date field field_name to a date object with only
  91. the given specificity.
  92. """
  93. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a date_trunc_sql() method.')
  94. def datetime_cast_date_sql(self, field_name, tzname):
  95. """
  96. Return the SQL to cast a datetime value to date value.
  97. """
  98. raise NotImplementedError(
  99. 'subclasses of BaseDatabaseOperations may require a '
  100. 'datetime_cast_date_sql() method.'
  101. )
  102. def datetime_cast_time_sql(self, field_name, tzname):
  103. """
  104. Return the SQL to cast a datetime value to time value.
  105. """
  106. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a datetime_cast_time_sql() method')
  107. def datetime_extract_sql(self, lookup_type, field_name, tzname):
  108. """
  109. Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute', or
  110. 'second', return the SQL that extracts a value from the given
  111. datetime field field_name.
  112. """
  113. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a datetime_extract_sql() method')
  114. def datetime_trunc_sql(self, lookup_type, field_name, tzname):
  115. """
  116. Given a lookup_type of 'year', 'month', 'day', 'hour', 'minute', or
  117. 'second', return the SQL that truncates the given datetime field
  118. field_name to a datetime object with only the given specificity.
  119. """
  120. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a datetime_trunc_sql() method')
  121. def time_trunc_sql(self, lookup_type, field_name):
  122. """
  123. Given a lookup_type of 'hour', 'minute' or 'second', return the SQL
  124. that truncates the given time field field_name to a time object with
  125. only the given specificity.
  126. """
  127. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a time_trunc_sql() method')
  128. def time_extract_sql(self, lookup_type, field_name):
  129. """
  130. Given a lookup_type of 'hour', 'minute', or 'second', return the SQL
  131. that extracts a value from the given time field field_name.
  132. """
  133. return self.date_extract_sql(lookup_type, field_name)
  134. def deferrable_sql(self):
  135. """
  136. Return the SQL to make a constraint "initially deferred" during a
  137. CREATE TABLE statement.
  138. """
  139. return ''
  140. def distinct_sql(self, fields, params):
  141. """
  142. Return an SQL DISTINCT clause which removes duplicate rows from the
  143. result set. If any fields are given, only check the given fields for
  144. duplicates.
  145. """
  146. if fields:
  147. raise NotSupportedError('DISTINCT ON fields is not supported by this database backend')
  148. else:
  149. return ['DISTINCT'], []
  150. def fetch_returned_insert_id(self, cursor):
  151. """
  152. Given a cursor object that has just performed an INSERT...RETURNING
  153. statement into a table that has an auto-incrementing ID, return the
  154. newly created ID.
  155. """
  156. return cursor.fetchone()[0]
  157. def field_cast_sql(self, db_type, internal_type):
  158. """
  159. Given a column type (e.g. 'BLOB', 'VARCHAR') and an internal type
  160. (e.g. 'GenericIPAddressField'), return the SQL to cast it before using
  161. it in a WHERE statement. The resulting string should contain a '%s'
  162. placeholder for the column being searched against.
  163. """
  164. return '%s'
  165. def force_no_ordering(self):
  166. """
  167. Return a list used in the "ORDER BY" clause to force no ordering at
  168. all. Return an empty list to include nothing in the ordering.
  169. """
  170. return []
  171. def for_update_sql(self, nowait=False, skip_locked=False, of=()):
  172. """
  173. Return the FOR UPDATE SQL clause to lock rows for an update operation.
  174. """
  175. return 'FOR UPDATE%s%s%s' % (
  176. ' OF %s' % ', '.join(of) if of else '',
  177. ' NOWAIT' if nowait else '',
  178. ' SKIP LOCKED' if skip_locked else '',
  179. )
  180. def _get_limit_offset_params(self, low_mark, high_mark):
  181. offset = low_mark or 0
  182. if high_mark is not None:
  183. return (high_mark - offset), offset
  184. elif offset:
  185. return self.connection.ops.no_limit_value(), offset
  186. return None, offset
  187. def limit_offset_sql(self, low_mark, high_mark):
  188. """Return LIMIT/OFFSET SQL clause."""
  189. limit, offset = self._get_limit_offset_params(low_mark, high_mark)
  190. return '%s%s' % (
  191. (' LIMIT %d' % limit) if limit else '',
  192. (' OFFSET %d' % offset) if offset else '',
  193. )
  194. def last_executed_query(self, cursor, sql, params):
  195. """
  196. Return a string of the query last executed by the given cursor, with
  197. placeholders replaced with actual values.
  198. `sql` is the raw query containing placeholders and `params` is the
  199. sequence of parameters. These are used by default, but this method
  200. exists for database backends to provide a better implementation
  201. according to their own quoting schemes.
  202. """
  203. # Convert params to contain string values.
  204. def to_string(s):
  205. return force_text(s, strings_only=True, errors='replace')
  206. if isinstance(params, (list, tuple)):
  207. u_params = tuple(to_string(val) for val in params)
  208. elif params is None:
  209. u_params = ()
  210. else:
  211. u_params = {to_string(k): to_string(v) for k, v in params.items()}
  212. return "QUERY = %r - PARAMS = %r" % (sql, u_params)
  213. def last_insert_id(self, cursor, table_name, pk_name):
  214. """
  215. Given a cursor object that has just performed an INSERT statement into
  216. a table that has an auto-incrementing ID, return the newly created ID.
  217. `pk_name` is the name of the primary-key column.
  218. """
  219. return cursor.lastrowid
  220. def lookup_cast(self, lookup_type, internal_type=None):
  221. """
  222. Return the string to use in a query when performing lookups
  223. ("contains", "like", etc.). It should contain a '%s' placeholder for
  224. the column being searched against.
  225. """
  226. return "%s"
  227. def max_in_list_size(self):
  228. """
  229. Return the maximum number of items that can be passed in a single 'IN'
  230. list condition, or None if the backend does not impose a limit.
  231. """
  232. return None
  233. def max_name_length(self):
  234. """
  235. Return the maximum length of table and column names, or None if there
  236. is no limit.
  237. """
  238. return None
  239. def no_limit_value(self):
  240. """
  241. Return the value to use for the LIMIT when we are wanting "LIMIT
  242. infinity". Return None if the limit clause can be omitted in this case.
  243. """
  244. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a no_limit_value() method')
  245. def pk_default_value(self):
  246. """
  247. Return the value to use during an INSERT statement to specify that
  248. the field should use its default value.
  249. """
  250. return 'DEFAULT'
  251. def prepare_sql_script(self, sql):
  252. """
  253. Take an SQL script that may contain multiple lines and return a list
  254. of statements to feed to successive cursor.execute() calls.
  255. Since few databases are able to process raw SQL scripts in a single
  256. cursor.execute() call and PEP 249 doesn't talk about this use case,
  257. the default implementation is conservative.
  258. """
  259. return [
  260. sqlparse.format(statement, strip_comments=True)
  261. for statement in sqlparse.split(sql) if statement
  262. ]
  263. def process_clob(self, value):
  264. """
  265. Return the value of a CLOB column, for backends that return a locator
  266. object that requires additional processing.
  267. """
  268. return value
  269. def return_insert_id(self):
  270. """
  271. For backends that support returning the last insert ID as part of an
  272. insert query, return the SQL and params to append to the INSERT query.
  273. The returned fragment should contain a format string to hold the
  274. appropriate column.
  275. """
  276. pass
  277. def compiler(self, compiler_name):
  278. """
  279. Return the SQLCompiler class corresponding to the given name,
  280. in the namespace corresponding to the `compiler_module` attribute
  281. on this backend.
  282. """
  283. if self._cache is None:
  284. self._cache = import_module(self.compiler_module)
  285. return getattr(self._cache, compiler_name)
  286. def quote_name(self, name):
  287. """
  288. Return a quoted version of the given table, index, or column name. Do
  289. not quote the given name if it's already been quoted.
  290. """
  291. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a quote_name() method')
  292. def random_function_sql(self):
  293. """Return an SQL expression that returns a random value."""
  294. return 'RANDOM()'
  295. def regex_lookup(self, lookup_type):
  296. """
  297. Return the string to use in a query when performing regular expression
  298. lookups (using "regex" or "iregex"). It should contain a '%s'
  299. placeholder for the column being searched against.
  300. If the feature is not supported (or part of it is not supported), raise
  301. NotImplementedError.
  302. """
  303. raise NotImplementedError('subclasses of BaseDatabaseOperations may require a regex_lookup() method')
  304. def savepoint_create_sql(self, sid):
  305. """
  306. Return the SQL for starting a new savepoint. Only required if the
  307. "uses_savepoints" feature is True. The "sid" parameter is a string
  308. for the savepoint id.
  309. """
  310. return "SAVEPOINT %s" % self.quote_name(sid)
  311. def savepoint_commit_sql(self, sid):
  312. """
  313. Return the SQL for committing the given savepoint.
  314. """
  315. return "RELEASE SAVEPOINT %s" % self.quote_name(sid)
  316. def savepoint_rollback_sql(self, sid):
  317. """
  318. Return the SQL for rolling back the given savepoint.
  319. """
  320. return "ROLLBACK TO SAVEPOINT %s" % self.quote_name(sid)
  321. def set_time_zone_sql(self):
  322. """
  323. Return the SQL that will set the connection's time zone.
  324. Return '' if the backend doesn't support time zones.
  325. """
  326. return ''
  327. def sql_flush(self, style, tables, sequences, allow_cascade=False):
  328. """
  329. Return a list of SQL statements required to remove all data from
  330. the given database tables (without actually removing the tables
  331. themselves) and the SQL statements required to reset the sequences
  332. passed in `sequences`.
  333. The `style` argument is a Style object as returned by either
  334. color_style() or no_style() in django.core.management.color.
  335. The `allow_cascade` argument determines whether truncation may cascade
  336. to tables with foreign keys pointing the tables being truncated.
  337. PostgreSQL requires a cascade even if these tables are empty.
  338. """
  339. raise NotImplementedError('subclasses of BaseDatabaseOperations must provide an sql_flush() method')
  340. def execute_sql_flush(self, using, sql_list):
  341. """Execute a list of SQL statements to flush the database."""
  342. with transaction.atomic(using=using, savepoint=self.connection.features.can_rollback_ddl):
  343. with self.connection.cursor() as cursor:
  344. for sql in sql_list:
  345. cursor.execute(sql)
  346. def sequence_reset_by_name_sql(self, style, sequences):
  347. """
  348. Return a list of the SQL statements required to reset sequences
  349. passed in `sequences`.
  350. The `style` argument is a Style object as returned by either
  351. color_style() or no_style() in django.core.management.color.
  352. """
  353. return []
  354. def sequence_reset_sql(self, style, model_list):
  355. """
  356. Return a list of the SQL statements required to reset sequences for
  357. the given models.
  358. The `style` argument is a Style object as returned by either
  359. color_style() or no_style() in django.core.management.color.
  360. """
  361. return [] # No sequence reset required by default.
  362. def start_transaction_sql(self):
  363. """Return the SQL statement required to start a transaction."""
  364. return "BEGIN;"
  365. def end_transaction_sql(self, success=True):
  366. """Return the SQL statement required to end a transaction."""
  367. if not success:
  368. return "ROLLBACK;"
  369. return "COMMIT;"
  370. def tablespace_sql(self, tablespace, inline=False):
  371. """
  372. Return the SQL that will be used in a query to define the tablespace.
  373. Return '' if the backend doesn't support tablespaces.
  374. If `inline` is True, append the SQL to a row; otherwise append it to
  375. the entire CREATE TABLE or CREATE INDEX statement.
  376. """
  377. return ''
  378. def prep_for_like_query(self, x):
  379. """Prepare a value for use in a LIKE query."""
  380. return str(x).replace("\\", "\\\\").replace("%", r"\%").replace("_", r"\_")
  381. # Same as prep_for_like_query(), but called for "iexact" matches, which
  382. # need not necessarily be implemented using "LIKE" in the backend.
  383. prep_for_iexact_query = prep_for_like_query
  384. def validate_autopk_value(self, value):
  385. """
  386. Certain backends do not accept some values for "serial" fields
  387. (for example zero in MySQL). Raise a ValueError if the value is
  388. invalid, otherwise return the validated value.
  389. """
  390. return value
  391. def adapt_unknown_value(self, value):
  392. """
  393. Transform a value to something compatible with the backend driver.
  394. This method only depends on the type of the value. It's designed for
  395. cases where the target type isn't known, such as .raw() SQL queries.
  396. As a consequence it may not work perfectly in all circumstances.
  397. """
  398. if isinstance(value, datetime.datetime): # must be before date
  399. return self.adapt_datetimefield_value(value)
  400. elif isinstance(value, datetime.date):
  401. return self.adapt_datefield_value(value)
  402. elif isinstance(value, datetime.time):
  403. return self.adapt_timefield_value(value)
  404. elif isinstance(value, decimal.Decimal):
  405. return self.adapt_decimalfield_value(value)
  406. else:
  407. return value
  408. def adapt_datefield_value(self, value):
  409. """
  410. Transform a date value to an object compatible with what is expected
  411. by the backend driver for date columns.
  412. """
  413. if value is None:
  414. return None
  415. return str(value)
  416. def adapt_datetimefield_value(self, value):
  417. """
  418. Transform a datetime value to an object compatible with what is expected
  419. by the backend driver for datetime columns.
  420. """
  421. if value is None:
  422. return None
  423. return str(value)
  424. def adapt_timefield_value(self, value):
  425. """
  426. Transform a time value to an object compatible with what is expected
  427. by the backend driver for time columns.
  428. """
  429. if value is None:
  430. return None
  431. if timezone.is_aware(value):
  432. raise ValueError("Django does not support timezone-aware times.")
  433. return str(value)
  434. def adapt_decimalfield_value(self, value, max_digits=None, decimal_places=None):
  435. """
  436. Transform a decimal.Decimal value to an object compatible with what is
  437. expected by the backend driver for decimal (numeric) columns.
  438. """
  439. return utils.format_number(value, max_digits, decimal_places)
  440. def adapt_ipaddressfield_value(self, value):
  441. """
  442. Transform a string representation of an IP address into the expected
  443. type for the backend driver.
  444. """
  445. return value or None
  446. def year_lookup_bounds_for_date_field(self, value):
  447. """
  448. Return a two-elements list with the lower and upper bound to be used
  449. with a BETWEEN operator to query a DateField value using a year
  450. lookup.
  451. `value` is an int, containing the looked-up year.
  452. """
  453. first = datetime.date(value, 1, 1)
  454. second = datetime.date(value, 12, 31)
  455. first = self.adapt_datefield_value(first)
  456. second = self.adapt_datefield_value(second)
  457. return [first, second]
  458. def year_lookup_bounds_for_datetime_field(self, value):
  459. """
  460. Return a two-elements list with the lower and upper bound to be used
  461. with a BETWEEN operator to query a DateTimeField value using a year
  462. lookup.
  463. `value` is an int, containing the looked-up year.
  464. """
  465. first = datetime.datetime(value, 1, 1)
  466. second = datetime.datetime(value, 12, 31, 23, 59, 59, 999999)
  467. if settings.USE_TZ:
  468. tz = timezone.get_current_timezone()
  469. first = timezone.make_aware(first, tz)
  470. second = timezone.make_aware(second, tz)
  471. first = self.adapt_datetimefield_value(first)
  472. second = self.adapt_datetimefield_value(second)
  473. return [first, second]
  474. def get_db_converters(self, expression):
  475. """
  476. Return a list of functions needed to convert field data.
  477. Some field types on some backends do not provide data in the correct
  478. format, this is the hook for converter functions.
  479. """
  480. return []
  481. def convert_durationfield_value(self, value, expression, connection):
  482. if value is not None:
  483. return datetime.timedelta(0, 0, value)
  484. def check_expression_support(self, expression):
  485. """
  486. Check that the backend supports the provided expression.
  487. This is used on specific backends to rule out known expressions
  488. that have problematic or nonexistent implementations. If the
  489. expression has a known problem, the backend should raise
  490. NotSupportedError.
  491. """
  492. pass
  493. def combine_expression(self, connector, sub_expressions):
  494. """
  495. Combine a list of subexpressions into a single expression, using
  496. the provided connecting operator. This is required because operators
  497. can vary between backends (e.g., Oracle with %% and &) and between
  498. subexpression types (e.g., date expressions).
  499. """
  500. conn = ' %s ' % connector
  501. return conn.join(sub_expressions)
  502. def combine_duration_expression(self, connector, sub_expressions):
  503. return self.combine_expression(connector, sub_expressions)
  504. def binary_placeholder_sql(self, value):
  505. """
  506. Some backends require special syntax to insert binary content (MySQL
  507. for example uses '_binary %s').
  508. """
  509. return '%s'
  510. def modify_insert_params(self, placeholder, params):
  511. """
  512. Allow modification of insert parameters. Needed for Oracle Spatial
  513. backend due to #10888.
  514. """
  515. return params
  516. def integer_field_range(self, internal_type):
  517. """
  518. Given an integer field internal type (e.g. 'PositiveIntegerField'),
  519. return a tuple of the (min_value, max_value) form representing the
  520. range of the column type bound to the field.
  521. """
  522. return self.integer_field_ranges[internal_type]
  523. def subtract_temporals(self, internal_type, lhs, rhs):
  524. if self.connection.features.supports_temporal_subtraction:
  525. lhs_sql, lhs_params = lhs
  526. rhs_sql, rhs_params = rhs
  527. return "(%s - %s)" % (lhs_sql, rhs_sql), lhs_params + rhs_params
  528. raise NotSupportedError("This backend does not support %s subtraction." % internal_type)
  529. def window_frame_start(self, start):
  530. if isinstance(start, int):
  531. if start < 0:
  532. return '%d %s' % (abs(start), self.PRECEDING)
  533. elif start == 0:
  534. return self.CURRENT_ROW
  535. elif start is None:
  536. return self.UNBOUNDED_PRECEDING
  537. raise ValueError("start argument must be a negative integer, zero, or None, but got '%s'." % start)
  538. def window_frame_end(self, end):
  539. if isinstance(end, int):
  540. if end == 0:
  541. return self.CURRENT_ROW
  542. elif end > 0:
  543. return '%d %s' % (end, self.FOLLOWING)
  544. elif end is None:
  545. return self.UNBOUNDED_FOLLOWING
  546. raise ValueError("end argument must be a positive integer, zero, or None, but got '%s'." % end)
  547. def window_frame_rows_start_end(self, start=None, end=None):
  548. """
  549. Return SQL for start and end points in an OVER clause window frame.
  550. """
  551. if not self.connection.features.supports_over_clause:
  552. raise NotSupportedError('This backend does not support window expressions.')
  553. return self.window_frame_start(start), self.window_frame_end(end)
  554. def window_frame_range_start_end(self, start=None, end=None):
  555. return self.window_frame_rows_start_end(start, end)
  556. def explain_query_prefix(self, format=None, **options):
  557. if not self.connection.features.supports_explaining_query_execution:
  558. raise NotSupportedError('This backend does not support explaining query execution.')
  559. if format:
  560. supported_formats = self.connection.features.supported_explain_formats
  561. normalized_format = format.upper()
  562. if normalized_format not in supported_formats:
  563. msg = '%s is not a recognized format.' % normalized_format
  564. if supported_formats:
  565. msg += ' Allowed formats: %s' % ', '.join(sorted(supported_formats))
  566. raise ValueError(msg)
  567. if options:
  568. raise ValueError('Unknown options: %s' % ', '.join(sorted(options.keys())))
  569. return self.explain_prefix
  570. def insert_statement(self, ignore_conflicts=False):
  571. return 'INSERT INTO'
  572. def ignore_conflicts_suffix_sql(self, ignore_conflicts=None):
  573. return ''