コード例 #1
0
  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
コード例 #2
0
    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
コード例 #3
0
ファイル: sql_builder_test.py プロジェクト: hediehy/vitess
 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))
コード例 #4
0
 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))
コード例 #5
0
ファイル: sql_builder_test.py プロジェクト: haoqoo/vitess
 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))
コード例 #6
0
ファイル: db_object.py プロジェクト: delkyd/vitess
  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
コード例 #7
0
  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
コード例 #8
0
  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
コード例 #9
0
ファイル: db_object.py プロジェクト: chengc017/vitess
  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
コード例 #10
0
ファイル: db_object.py プロジェクト: haoqoo/vitess
 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)
コード例 #11
0
 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)