Ticket #14733: 14733-xof.diff

File 14733-xof.diff, 1.8 KB (added by Xof, 5 years ago)

Per discussion on django-developers, a patch to remove the restrictions and update the documentation

  • trunk/docs/topics/db/sql.txt

    5656    :attr:`~Options.db_table` option, which also lets you manually set the
    5757    database table name.
     59.. admonition:: Statements permitted in ``.raw()`` queries
     61    No checking is done on the SQL statement that is passed in to ``.raw()``.
     62    Django expects that the statement will return a set of rows from the
     63    database, but does nothing to enforce that. If the query does not
     64    return rows, a (possibly cryptic) error will result.
    5966Of course, this example isn't very exciting -- it's exactly the same as
    6067running ``Person.objects.all()``. However, ``raw()`` has a bunch of other
    6168options that make it very powerful.
  • trunk/django/db/models/sql/query.py

    3131    """
    3333    def __init__(self, sql, using, params=None):
    34         self.validate_sql(sql)
    3534        self.params = params or ()
    3635        self.sql = sql
    3736        self.using = using
    6261        return [converter(column_meta[0])
    6362                for column_meta in self.cursor.description]
    65     def validate_sql(self, sql):
    66         if not sql.lower().strip().startswith('select'):
    67             raise InvalidQuery('Raw queries are limited to SELECT queries. Use '
    68                                'connection.cursor directly for other types of queries.')
    7064    def __iter__(self):
    7165        # Always execute a new query for a new iterator.
    7266        # This could be optimized with a cache at the expense of RAM.
Back to Top