Ticket #2705: select_for_update_r7188.patch
File select_for_update_r7188.patch, 4.7 KB (added by , 17 years ago) |
---|
-
django/db/models/manager.py
95 95 def order_by(self, *args, **kwargs): 96 96 return self.get_query_set().order_by(*args, **kwargs) 97 97 98 def select_for_update(self, *args, **kwargs): 99 return self.get_query_set().select_for_update(*args, **kwargs) 100 98 101 def select_related(self, *args, **kwargs): 99 102 return self.get_query_set().select_related(*args, **kwargs) 100 103 -
django/db/models/query.py
88 88 def __init__(self, model=None): 89 89 self.model = model 90 90 self._filters = Q() 91 self._order_by = None # Ordering, e.g. ('date', '-name'). If None, use model's ordering. 92 self._select_related = False # Whether to fill cache for related objects. 93 self._max_related_depth = 0 # Maximum "depth" for select_related 94 self._distinct = False # Whether the query should use SELECT DISTINCT. 95 self._select = {} # Dictionary of attname -> SQL. 96 self._where = [] # List of extra WHERE clauses to use. 97 self._params = [] # List of params to use for extra WHERE clauses. 98 self._tables = [] # List of extra tables to use. 99 self._offset = None # OFFSET clause. 100 self._limit = None # LIMIT clause. 91 self._order_by = None # Ordering, e.g. ('date', '-name'). If None, use model's ordering. 92 self._select_for_update = False # Whether to select for update. 93 self._select_related = False # Whether to fill cache for related objects. 94 self._max_related_depth = 0 # Maximum "depth" for select_related 95 self._distinct = False # Whether the query should use SELECT DISTINCT. 96 self._select = {} # Dictionary of attname -> SQL. 97 self._where = [] # List of extra WHERE clauses to use. 98 self._params = [] # List of params to use for extra WHERE clauses. 99 self._tables = [] # List of extra tables to use. 100 self._offset = None # OFFSET clause. 101 self._limit = None # LIMIT clause. 101 102 self._result_cache = None 102 103 103 104 ######################## … … 222 223 223 224 counter = self._clone() 224 225 counter._order_by = () 226 counter._select_for_update = False 225 227 counter._select_related = False 226 228 227 229 offset = counter._offset … … 329 331 del_query = self._clone() 330 332 331 333 # disable non-supported fields 334 del_query._select_for_update = False 332 335 del_query._select_related = False 333 336 del_query._order_by = [] 334 337 … … 411 414 else: 412 415 return self._filter_or_exclude(None, **filter_obj) 413 416 417 def select_for_update(self, true_or_false=True): 418 "Returns a new QuerySet instance with '_select_for_update' modified." 419 return self._clone(_select_for_update=true_or_false) 420 414 421 def select_related(self, true_or_false=True, depth=0): 415 422 "Returns a new QuerySet instance with '_select_related' modified." 416 423 return self._clone(_select_related=true_or_false, _max_related_depth=depth) … … 446 453 c.model = self.model 447 454 c._filters = self._filters 448 455 c._order_by = self._order_by 456 c._select_for_update = self._select_for_update 449 457 c._select_related = self._select_related 450 458 c._max_related_depth = self._max_related_depth 451 459 c._distinct = self._distinct … … 563 571 else: 564 572 assert self._offset is None, "'offset' is not allowed without 'limit'" 565 573 574 # FOR UPDATE 575 if self._select_for_update: 576 sql.append("%s" % connection.ops.get_for_update_sql()) 577 566 578 return select, " ".join(sql), params 567 579 568 580 # Use the backend's QuerySet class if it defines one. Otherwise, use _QuerySet. -
django/db/backends/__init__.py
159 159 """ 160 160 return cursor.lastrowid 161 161 162 def get_for_update_sql(self): 163 """ 164 Return FOR UPDATE SQL clause to lock row for update 165 """ 166 return 'FOR UPDATE' 167 162 168 def limit_offset_sql(self, limit, offset=None): 163 169 """ 164 170 Returns a LIMIT/OFFSET SQL clause, given a limit and optional offset.