def update_columns(class_, cursor, where_column_value_pairs, **update_columns): query, bind_variables = sql_builder.update_columns_query( class_.table_name, where_column_value_pairs, **update_columns) return cursor.execute(query, bind_variables)
def update_columns(class_, cursor, where_column_value_pairs, **update_columns): query, bind_vars = sql_builder.update_columns_query( class_.table_name, where_column_value_pairs, **update_columns) return cursor.execute(query, bind_vars)
def create_update_query(class_, where_column_value_pairs, update_column_value_pairs): class_._validate_column_value_pairs_for_write( **dict(update_column_value_pairs)) return sql_builder.update_columns_query( class_.table_name, where_column_value_pairs, update_column_value_pairs=update_column_value_pairs)
def test_with_update_expr(self): sql, bind_vars = sql_builder.update_columns_query( table_name='my_table', where_column_value_pairs=[('col_a', 1), ('col_b', 2)], update_column_value_pairs=[('col_c', sql_builder.Increment(5))]) self.assertEqual( sql, 'UPDATE my_table SET col_c = (col_c + %(update_col_c_amount)s) ' 'WHERE col_a = %(col_a_1)s AND col_b = %(col_b_2)s') self.assertEqual(bind_vars, dict(update_col_c_amount=5, col_a_1=1, col_b_2=2))
def test_with_update_expr(self): sql, bind_vars = sql_builder.update_columns_query( table_name='my_table', where_column_value_pairs=[('col_a', 1), ('col_b', 2)], update_column_value_pairs=[('col_c', sql_builder.Increment(5))]) self.assertEqual( sql, 'UPDATE my_table SET col_c = (col_c + %(update_col_c_amount)s) ' 'WHERE col_a = %(col_a_1)s AND col_b = %(col_b_2)s') self.assertEqual( bind_vars, dict(update_col_c_amount=5, col_a_1=1, col_b_2=2))
def test_with_update_value_expr(self): sql, bind_vars = sql_builder.update_columns_query( table_name="my_table", where_column_value_pairs=[("col_a", 1), ("col_b", 2)], update_column_value_pairs=[("col_c", sql_builder.Increment(5))], ) self.assertEqual( sql, "UPDATE my_table SET col_c = (col_c + %(update_col_c_amount)s) " "WHERE col_a = %(col_a_1)s AND col_b = %(col_b_2)s", ) self.assertEqual(bind_vars, dict(update_col_c_amount=5, col_a_1=1, col_b_2=2))
def test_simple(self): sql, bind_vars = sql_builder.update_columns_query( table_name='my_table', where_column_value_pairs=[('col_a', 1), ('col_b', 2)], update_column_value_pairs=[('col_c', 3)], limit=5, order_by='col_d') self.assertEqual( sql, 'UPDATE my_table SET col_c = %(update_set_0)s ' 'WHERE col_a = %(col_a_1)s AND col_b = %(col_b_2)s ' 'ORDER BY col_d LIMIT %(limit_row_count)s') self.assertEqual( bind_vars, dict(update_set_0=3, col_a_1=1, col_b_2=2, limit_row_count=5))
def test_simple(self): sql, bind_vars = sql_builder.update_columns_query( table_name="my_table", where_column_value_pairs=[("col_a", 1), ("col_b", 2)], update_column_value_pairs=[("col_c", 3)], limit=5, order_by="col_d", ) self.assertEqual( sql, "UPDATE my_table SET col_c = %(update_set_0)s " "WHERE col_a = %(col_a_1)s AND col_b = %(col_b_2)s " "ORDER BY col_d LIMIT %(limit_row_count)s", ) self.assertEqual(bind_vars, dict(update_set_0=3, col_a_1=1, col_b_2=2, limit_row_count=5))
def update_columns(class_, cursor, where_column_value_pairs, **update_columns): where_column_value_pairs = class_._add_keyspace_id( unpack_keyspace_id(cursor.keyspace_ids[0]), where_column_value_pairs) query, bind_vars = sql_builder.update_columns_query( class_.table_name, where_column_value_pairs, **update_columns) rowcount = cursor.execute(query, bind_vars) # If the entity_id column is being updated, update lookup map. if class_.entity_id_lookup_map is not None: for entity_col in class_.entity_id_lookup_map.keys(): if entity_col in update_columns: class_.update_sharding_key_entity_id_lookup( cursor, sharding_key, entity_col, update_columns[entity_col]) return rowcount
def update_columns(class_, cursor, where_column_value_pairs, **update_columns): where_column_value_pairs = class_._add_keyspace_id( unpack_keyspace_id(cursor.keyspace_ids[0]), where_column_value_pairs) query, bind_vars = sql_builder.update_columns_query( class_.table_name, where_column_value_pairs, **update_columns) rowcount = cursor.execute(query, bind_vars) # If the entity_id column is being updated, update lookup map. if class_.entity_id_lookup_map is not None: for entity_col in class_.entity_id_lookup_map.keys(): if entity_col in update_columns: class_.update_sharding_key_entity_id_lookup(cursor, sharding_key, entity_col, update_columns[entity_col]) return rowcount
def update_columns(class_, cursor, where_column_value_pairs, **update_columns): sharding_key = cursor.routing.sharding_key if sharding_key is None: raise dbexceptions.ProgrammingError("sharding_key cannot be empty") # update the primary table first. query, bind_vars = sql_builder.update_columns_query( class_.table_name, where_column_value_pairs, **update_columns) rowcount = cursor.execute(query, bind_vars) # If the entity_id column is being updated, update lookup map. lookup_cursor_method = functools.partial( db_object.create_cursor_from_old_cursor, cursor) for entity_col in class_.entity_id_lookup_map.keys(): if entity_col in update_columns: class_.update_sharding_key_entity_id_lookup( lookup_cursor_method, sharding_key, entity_col, update_columns[entity_col]) return rowcount
def update_columns(class_, cursor, where_column_value_pairs, **update_columns): sharding_key = cursor.routing.sharding_key if sharding_key is None: raise dbexceptions.ProgrammingError("sharding_key cannot be empty") # update the primary table first. query, bind_vars = sql_builder.update_columns_query( class_.table_name, where_column_value_pairs, **update_columns) rowcount = cursor.execute(query, bind_vars) # If the entity_id column is being updated, update lookup map. lookup_cursor_method = functools.partial( db_object.create_cursor_from_old_cursor, cursor) for entity_col in class_.entity_id_lookup_map.keys(): if entity_col in update_columns: class_.update_sharding_key_entity_id_lookup(lookup_cursor_method, sharding_key, entity_col, update_columns[entity_col]) return rowcount
def create_update_query(class_, where_column_value_pairs, update_column_value_pairs): return sql_builder.update_columns_query( class_.table_name, where_column_value_pairs, update_column_value_pairs=update_column_value_pairs)