#insert new record if it dosent already exist
if !dbh.select_one('SELECT Salenm FROM Auctions Where Salenm LIKE "%' + c.attributes["href"][/....$/] + '%"')
dbh.do("INSERT INTO Auctions (Salenm, Date, Location) VALUES (?, ?, 1)",
c.attributes["href"][/....$/],
Time.parse(c.at("font").inner_html).to_s )
end
Refactorings
No refactoring yet !
Fu86
June 24, 2010, June 24, 2010 07:54, permalink
If you can alter the table, make the Salenm Field UNIQUE. If this is not possible, you have to extend your SQL query with a WHERE NOT ...
ALTER TABLE Auctions ADD UNIQUE (Salenm)
dbh.do("INSERT INTO Auctions (Salenm, Date, Location) VALUES (?, ?, 1)",
c.attributes["href"][/....$/],
Time.parse(c.at("font").inner_html).to_s)
end
Is there a safer way to-do that if statement ?