I run SQL query with ruby script that should take around 2 hours.
How I can make sure the script will exit/end only when the process of the query finish, because right now I ran the script, it pass the query to the DB, and the script immediately close while the query still running on the DB.
most of the query is commands like inserts, drop tables, create tables.
client = Mysql2::Client.new(:host => ENV_YML['host'], :username => ENV_YML['username'], :password => ENV_YML['password'], :database => ENV_YML['dbtemp'], :flags => Mysql2::Client::MULTI_STATEMENTS)
client.query("SELECT ;").each do |row|
Multiple result sets
You can also retrieve multiple result sets. For this to work you need to connect with flags Mysql2::Client::MULTI_STATEMENTS. Multiple result sets can be used with stored procedures that return more than one result set, and for bundling several SQL statements into a single call to client.query.
client = Mysql2::Client.new(:host => "localhost", :username => "root", :flags => Mysql2::Client::MULTI_STATEMENTS) result = client.query('...') while client.next_result result = client.store_result # result now contains the next result set end