brianmario / mysql2

A modern, simple and very fast Mysql library for Ruby - binding to libmysql
http://github.com/brianmario/mysql2
MIT License
2.25k stars 550 forks source link

MULTI_STATEMENT seems to ignore async => false #356

Open aprescott opened 11 years ago

aprescott commented 11 years ago
client = Mysql2::Client.new(
  :host     => "localhost",
  :port     => 3306,
  :database => "foo",
  :socket   => "/tmp/mysql.sock",
  :flags    => Mysql2::Client::MULTI_STATEMENTS
)
client.query(sql, :async => false)

sql contains a bunch of CREATE TABLE statements and a few INSERTs.

The :async => false is explicitly set to remove any doubt about it being in effect.

With the above code, client.query returns nil immediately (no errors or any other indication of failure) and the Rake task finishes normally, but the tables in sql haven't finished being created. If you look at show tables from a command-line MySQL client every few seconds, the tables are being created in the background.

The behaviour I was expecting is query to block until all statements have finished, which is what I thought MULTI_STATEMENT with :async => false does.

Other people seem to be having this same issue: http://stackoverflow.com/questions/14914314/ruby-mysql2-error-when-executing-statements-in-rapid-succession

sodabrew commented 11 years ago

Please include the version of mysql2 gem, mysql server, ruby, etc. that you are using.

aprescott commented 11 years ago
sodabrew commented 11 years ago

Thanks! All very up-to-date, could you try mysql2 0.3.12b6? There are some changes to multistatement support that may help.

aprescott commented 11 years ago

No such luck. Same problem.