#!/usr/bin/env ruby require 'rubygems' require 'active_record' require 'sqlite3' ActiveRecord::Base.establish_connection({ :adapter => 'mysql', :host => '127.0.0.1', :port => 3417, :username => 'typo', :password => '', :database => 'typo', }) inp = ActiveRecord::Base.connection ActiveRecord::Base.establish_connection({ :adapter => 'sqlite3', :dbfile => 'db/typo.db' }) out = ActiveRecord::Base.connection inp.select_all("SHOW TABLES").inject("") do |str,table| name = table.to_a.first.last puts name inp.select_all("select * from #{name}").each do |r| cols = [] attrs = [] r.each { |x| cols << x[0] attrs << x[1] #puts "x: #{x[0]}, #{x[1].class}, #{x[1]}" } quoted_attrs = attrs.collect { |value| out.quote(value) } begin out.insert( "INSERT INTO #{name} " + "(#{cols.join(', ')}) " + "VALUES(#{quoted_attrs.join(', ')})") rescue ActiveRecord::StatementInvalid # do nothing end end end