Ticket #14733: 14733-xof.diff
File 14733-xof.diff, 1.8 KB (added by , 14 years ago) |
---|
-
trunk/docs/topics/db/sql.txt
56 56 :attr:`~Options.db_table` option, which also lets you manually set the 57 57 database table name. 58 58 59 .. admonition:: Statements permitted in ``.raw()`` queries 60 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. 65 59 66 Of course, this example isn't very exciting -- it's exactly the same as 60 67 running ``Person.objects.all()``. However, ``raw()`` has a bunch of other 61 68 options that make it very powerful. -
trunk/django/db/models/sql/query.py
31 31 """ 32 32 33 33 def __init__(self, sql, using, params=None): 34 self.validate_sql(sql)35 34 self.params = params or () 36 35 self.sql = sql 37 36 self.using = using … … 62 61 return [converter(column_meta[0]) 63 62 for column_meta in self.cursor.description] 64 63 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.')69 70 64 def __iter__(self): 71 65 # Always execute a new query for a new iterator. 72 66 # This could be optimized with a cache at the expense of RAM.