def delete_by_columns(class_, cursor, where_column_value_pairs, limit=None): sharding_key = cursor.routing.sharding_key if sharding_key is None: raise dbexceptions.ProgrammingError('sharding_key cannot be empty') if not where_column_value_pairs: raise dbexceptions.ProgrammingError( 'deleting the whole table is not allowed') query, bind_vars = sql_builder.delete_by_columns_query( class_.table_name, where_column_value_pairs, limit=limit) cursor.execute(query, bind_vars) if cursor.rowcount == 0: raise dbexceptions.DatabaseError('DB Row not found') rowcount = cursor.rowcount # delete the lookup map. lookup_cursor_method = functools.partial( db_object.create_cursor_from_old_cursor, cursor) class_.delete_sharding_key_entity_id_lookup( lookup_cursor_method, sharding_key) return rowcount
def delete_by_columns(class_, cursor, where_column_value_pairs, limit=None): sharding_key = cursor.routing.sharding_key if sharding_key is None: raise dbexceptions.ProgrammingError("sharding_key cannot be empty") if not where_column_value_pairs: raise dbexceptions.ProgrammingError( "deleting the whole table is not allowed") query, bind_vars = sql_builder.delete_by_columns_query( class_.table_name, where_column_value_pairs, limit=limit) cursor.execute(query, bind_vars) if cursor.rowcount == 0: raise dbexceptions.DatabaseError("DB Row not found") rowcount = cursor.rowcount #delete the lookup map. lookup_cursor_method = functools.partial( db_object.create_cursor_from_old_cursor, cursor) class_.delete_sharding_key_entity_id_lookup(lookup_cursor_method, sharding_key) return rowcount
def test_simple(self): sql, bind_vars = sql_builder.delete_by_columns_query( table_name="my_table", where_column_value_pairs=[("col_a", 1), ("col_b", 2)], limit=5 ) self.assertEqual( sql, "DELETE FROM my_table " "WHERE col_a = %(col_a_1)s AND col_b = %(col_b_2)s " "LIMIT %(limit_row_count)s", ) self.assertEqual(bind_vars, dict(col_a_1=1, col_b_2=2, limit_row_count=5))
def test_simple(self): sql, bind_vars = sql_builder.delete_by_columns_query( table_name='my_table', where_column_value_pairs=[('col_a', 1), ('col_b', 2)], limit=5) self.assertEqual( sql, 'DELETE FROM my_table ' 'WHERE col_a = %(col_a_1)s AND col_b = %(col_b_2)s ' 'LIMIT %(limit_row_count)s') self.assertEqual(bind_vars, dict(col_a_1=1, col_b_2=2, limit_row_count=5))
def test_simple(self): sql, bind_vars = sql_builder.delete_by_columns_query( table_name='my_table', where_column_value_pairs=[('col_a', 1), ('col_b', 2)], limit=5) self.assertEqual( sql, 'DELETE FROM my_table ' 'WHERE col_a = %(col_a_1)s AND col_b = %(col_b_2)s ' 'LIMIT %(limit_row_count)s') self.assertEqual( bind_vars, dict(col_a_1=1, col_b_2=2, limit_row_count=5))
def delete_by_columns(class_, cursor, where_column_value_pairs, limit=None, **columns): if not where_column_value_pairs: where_column_value_pairs = columns.items() where_column_value_pairs.sort() if not where_column_value_pairs: raise dbexceptions.ProgrammingError("deleting the whole table is not allowed") query, bind_variables = sql_builder.delete_by_columns_query(class_.table_name, where_column_value_pairs, limit=limit) cursor.execute(query, bind_variables) if cursor.rowcount == 0: raise dbexceptions.DatabaseError("DB Row not found") return cursor.rowcount
def delete_by_columns(class_, cursor, where_column_value_pairs, limit=None): if not where_column_value_pairs: raise dbexceptions.ProgrammingError( 'deleting the whole table is not allowed') where_column_value_pairs = class_._add_keyspace_id( unpack_keyspace_id(cursor.keyspace_ids[0]), where_column_value_pairs) query, bind_vars = sql_builder.delete_by_columns_query( class_.table_name, where_column_value_pairs, limit=limit) cursor.execute(query, bind_vars) if cursor.rowcount == 0: raise dbexceptions.DatabaseError('DB Row not found') return cursor.rowcount
def delete_by_columns(class_, cursor, where_column_value_pairs, limit=None): if not where_column_value_pairs: raise dbexceptions.ProgrammingError("deleting the whole table is not allowed") where_column_value_pairs = class_._add_keyspace_id( unpack_keyspace_id(cursor.keyspace_ids[0]), where_column_value_pairs) query, bind_vars = sql_builder.delete_by_columns_query(class_.table_name, where_column_value_pairs, limit=limit) cursor.execute(query, bind_vars) if cursor.rowcount == 0: raise dbexceptions.DatabaseError("DB Row not found") return cursor.rowcount
def delete_by_columns(class_, cursor, where_column_value_pairs, limit=None, **columns): if not where_column_value_pairs: where_column_value_pairs = columns.items() where_column_value_pairs.sort() if not where_column_value_pairs: raise dbexceptions.ProgrammingError("deleting the whole table is not allowed") query, bind_vars = sql_builder.delete_by_columns_query(class_.table_name, where_column_value_pairs, limit=limit) cursor.execute(query, bind_vars) if cursor.rowcount == 0: raise dbexceptions.DatabaseError("DB Row not found") return cursor.rowcount
def create_delete_query(class_, where_column_value_pairs, limit=None): return sql_builder.delete_by_columns_query(class_.table_name, where_column_value_pairs, limit=limit)