Hey all-

I posted some questions yesterday about getting ActiveRecord working
with Oracle 10g, and I'm happy to say I was successful. ActiveRecord
makes pulling and manipulating data so easy. Now, I'm writing some data
validation scripts. Here's the goal: given two data sources, confirm
that specific fields in the first table are the same as the fields in
the 2nd for the same record, check to see if there are records in the
1st table that aren't in the 2nd, and vise-versa. I was wondering if my
general approach is the fastest way to do this, as I'm not new to ruby
but generally new to writing high performance sql (and thus the
corresponding ActiveRecord statements). I'm working with very large
datasets here and want to streamline the code as much as possible.
Here's my general strategy (assume the objects are ActiveRecord
objects), advice is much appreciated:

Table1.find(:all).each do |rec1|
  rec2 =
Table2.find(:first,:conditions=>{:key1=>rec1.key1,:key2=>rec1.key2})
  if rec2
    if rec1.field1 != rec2.field2
      #throw value mismatch here
    end
  else
    #throw missing record error here
  end
end

Table2.find(:all).each do |rec2|
  rec1 =
Table1.find(:first,:conditions=>{:key1=>rec2.key1,:key2=>rec2.key2})
  if !rec1
    #throw missing record error here
  end
end

-- 
Posted via http://www.ruby-forum.com/.