Patch select_value for MysqlAdapter

This commit is contained in:
sanemat 2013-01-09 18:56:42 +09:00
parent c493bd89fa
commit 3a4639fae5

View file

@ -55,7 +55,9 @@ module DatabaseCleaner
def row_count(table) def row_count(table)
select_value("SELECT EXISTS (SELECT 1 FROM #{quote_table_name(table)} LIMIT 1)") # Patch for MysqlAdapter with ActiveRecord 3.2.7 later
# select_value("SELECT 1") #=> "1"
select_value("SELECT EXISTS (SELECT 1 FROM #{quote_table_name(table)} LIMIT 1)").to_i
end end
# Returns a boolean indicating if the given table has an auto-inc number higher than 0. # Returns a boolean indicating if the given table has an auto-inc number higher than 0.
@ -66,7 +68,9 @@ module DatabaseCleaner
if row_count(table) > 0 if row_count(table) > 0
true true
else else
select_value(<<-SQL) > 1 # returns nil if not present # Patch for MysqlAdapter with ActiveRecord 3.2.7 later
# select_value("SELECT 1") #=> "1"
select_value(<<-SQL).to_i > 1 # returns nil if not present
SELECT Auto_increment SELECT Auto_increment
FROM information_schema.tables FROM information_schema.tables
WHERE table_name='#{table}'; WHERE table_name='#{table}';