luislavena / mysql-gem

MySQL/Ruby Bindings, wrapped as Gem with improved cross-platform support
http://rubyforge.org/projects/mysql-win
Other
53 stars 20 forks source link

Use ULL2NUM for affected_rows #12

Closed cbandy closed 11 years ago

cbandy commented 11 years ago

This is a partial fix for #11.

I was able to bypass disk and memory requirements by using the BLACKHOLE engine, but the tests below take 22 minutes each on my [older] desktop. Without this commit, these tests fail with <4294967296> expected but was <0>.

diff --git a/test/test_mysql.rb b/test/test_mysql.rb
index f9013cd..543db6c 100644
--- a/test/test_mysql.rb
+++ b/test/test_mysql.rb
@@ -131,6 +131,16 @@ class TC_Mysql2 < Test::Unit::TestCase
     assert_equal(1, @m.affected_rows)
   end

+  def test_affected_rows_bigint()
+    @m.query("CREATE OR REPLACE VIEW null_16  AS SELECT NULL#{' UNION ALL SELECT NULL' * 15}")
+    @m.query("CREATE OR REPLACE VIEW null_256 AS SELECT NULL FROM null_16  a, null_16  b")
+    @m.query("CREATE OR REPLACE VIEW null_64k AS SELECT NULL FROM null_256 a, null_256 b")
+    @m.query("CREATE OR REPLACE VIEW null_4g  AS SELECT NULL FROM null_64k a, null_64k b")
+
+    @m.query("CREATE TEMPORARY TABLE t ENGINE BLACKHOLE AS SELECT * FROM null_4g")
+    assert_equal(4_294_967_296, @m.affected_rows)
+  end
+
   def test_autocommit()
     if @m.methods.include? "autocommit" then
       assert_equal(@m, @m.autocommit(true))
@@ -506,6 +516,17 @@ class TC_MysqlStmt2 < Test::Unit::TestCase
     end
   end

+  def test_affected_rows_bigint()
+    @m.query("CREATE OR REPLACE VIEW null_16  AS SELECT NULL#{' UNION ALL SELECT NULL' * 15}")
+    @m.query("CREATE OR REPLACE VIEW null_256 AS SELECT NULL FROM null_16  a, null_16  b")
+    @m.query("CREATE OR REPLACE VIEW null_64k AS SELECT NULL FROM null_256 a, null_256 b")
+    @m.query("CREATE OR REPLACE VIEW null_4g  AS SELECT NULL FROM null_64k a, null_64k b")
+
+    @s.prepare("CREATE TEMPORARY TABLE t ENGINE BLACKHOLE AS SELECT * FROM null_4g")
+    @s.execute
+    assert_equal(4_294_967_296, @s.affected_rows)
+  end
+
 =begin
   def test_attr_get()
     assert_equal(false, @s.attr_get(Mysql::Stmt::ATTR_UPDATE_MAX_LENGTH))
luislavena commented 11 years ago

the tests below take 22 minutes each on my [older] desktop

Ouch!

I appreciate you investigating and providing a fix for this. I'll need to test this locally.

There isn't another way we can produce such result without an slow test like this?

Will check this later today. Thank you again! :heart: :heart: :heart: