mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Patch select_value for MysqlAdapter
This commit is contained in:
parent
c493bd89fa
commit
3a4639fae5
1 changed files with 6 additions and 2 deletions
|
@ -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}';
|
||||||
|
|
Loading…
Reference in a new issue