Help with accessing DB for general purpose on Active Record


I’m converting data from a db to another.
It’s kinda complex migration.
I need to merge some tables into one and change some column values by

I want to use ActiveRecord instead of DBI (For some reason, on my
ubuntu box, DBI for MySql doesn’t work.)
Modeling is not important here.
And I don’t want to define all models for every table (more than 800
I just want to use my sql statements for retrieval and update (select/
So basically, I’m not taking advantage of ActiveRecord.
I’m just using it as DB interface.

Through some research, I figured out how to retrieve data.

rows = ActiveRecord::Base.find_by_sql(“select * from table1”)
rows.each do |row|
hash = row.attributes_before_type_cast


In this way, row.attributes didn’t work but
attributes_before_type_cast did.

Question 1:
Is there a way to make row.attributes work? And for better, how can I
make row.col_name work?

Question 2:
How can I use insert/update statement?
For example, ActiveRecord::Base.insert_by_sql(“insert into…”)

I googled it already but couldn’t find good examples.