Guest User

Untitled

a guest
Jan 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. # frozen_string_literal: true
  2.  
  3. STDOUT.sync = true
  4. STDERR.sync = true
  5.  
  6. require 'time'
  7. require 'mysql2'
  8.  
  9. END_OF_TIME = Time.now.to_i - 14 * 86_400
  10.  
  11. SQLS = [
  12. 'DELETE FROM co_block WHERE user IN(15) AND action IN(1) AND time < ?', # fire spread
  13. 'DELETE FROM co_block WHERE user IN(21) AND action IN(1) AND time < ?', # Water spread
  14. 'DELETE FROM co_block WHERE user IN(33) AND action IN(0, 1) AND time < ?', # Piston movement
  15. 'DELETE FROM co_block WHERE user IN(162) AND type IN(11) AND action IN(3) AND time < ?', # Creeper suicided
  16. 'DELETE FROM co_block WHERE wid IN(3, 8) AND type IN(32) AND action IN(3) AND time < ?' # Killed Enderman
  17. ].freeze
  18.  
  19. client = Mysql2::Client.new(
  20. host: '127.0.0.1',
  21. username: 'root',
  22. password: '',
  23. database: 'database'
  24. )
  25.  
  26. def query(client, sql)
  27. statement = client.prepare(sql)
  28. statement.execute(END_OF_TIME)
  29. rescue => e
  30. STDERR.puts e.message
  31. STDERR.puts e.backtrace.join("\n")
  32. end
  33.  
  34. begin
  35. SQLS.each do |sql|
  36. query_time = Time.now
  37. result = query(client, sql)
  38. affected_rows = result.affected_rows
  39. elapsed_time = Time.now - query_time
  40. puts format('Query OK, %d rows affected (%.2f sec)', affected_rows, elapsed_time)
  41. end
  42. ensure
  43. client.close if client
  44. puts 'Disconnected'
  45. end
Add Comment
Please, Sign In to add comment