642d333608cc3483f64dba38cb81bdd2

Is there a safer way to-do that if statement ?

#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 !

Ee0505bbd355292778077fb662c88f13

Fu86

June 24, 2010, June 24, 2010 07:54, permalink

No rating. Login to rate!

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

Your refactoring





Format Copy from initial code

or Cancel