Reputation: 3091
I want to disable the query cache of ActiveRecord from ruby, but it doesn't work, the code is below:
def test_transaction
ActiveRecord::Base.connection.execute("create table if not exists t(name varchar(100))")
ActiveRecord::Base.connection.uncached do
begin
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute("insert into t values('one')")
ActiveRecord::Base.connection.execute("insert into t values('two')")
ActiveRecord::Base.connection.execute("insert into t values('three')")
ActiveRecord::Base.connection.execute("insert into t values('four')")
result = ActiveRecord::Base.connection.select_all("select count(*) as total from t")[0]['total'].to_i
assert_equal(0, result)
end
ensure
ActiveRecord::Base.connection.execute("drop table if exists t")
end
end
end
As matter of fact when the code run on the line before select, i logon mysql by console and executed the same select query, the result total is zero, so that's ok, but after the code execute the select, the result is 4, that's to say the select must fetch from the query cache, but that's what i don't intend to, so could anyone can provide any help for me?
Thank you in advance!
Upvotes: 1
Views: 1063
Reputation: 3091
after do experiments directly on mysql console and found finally that it's not related to ActiveRecord, it's due to the mechanism of mysql transaction.
Upvotes: 1