Exemplo n.º 1
0
    def delete(self):
        """Delete objects selected by the QuerySet"""
        # Try to keep things simple by resolving a direct DELETE ... WHERE ...
        # query. If that proves impossible, fallback to the naive DELETE ...
        # WHERE <pk> IN (SELECT ...) solution.
        self._for_write = True
        handler = get_engine_handler(self.db)
        table = self.model._meta.db_table

        params = copy.deepcopy(self._params)
        where = params.pop('where')

        with handler.patch():
            if any(params.values()):
                # If any of the remaining params is not empty, play safe and
                # fallback to subquery
                query = delete(table, where=handler.get_where_for_delete(self))
            else:
                # Try to be smart
                query = delete(table, where=where)

        # Execute the query
        cursor = handler.cursor()
        cursor.execute(query)
        return cursor.rowcount
Exemplo n.º 2
0
 def test_delete(self):
     with self.db as cur:
         cur.execute(delete('person', {'person_id': 'mosky'}))
         self.db._conn.rollback()
Exemplo n.º 3
0
 def test_delete(self):
     with self.db as cur:
         cur.execute(delete("person", {"person_id": "mosky"}))
         self.db._conn.rollback()
Exemplo n.º 4
0
 def test_delete(self):
     with self.db as cur:
         cur.execute(delete('person', {'person_id': 'mosky'}))
         self.db._conn.rollback()