in reply to SQL quoting problem
$statement = something.... $dbh->do($statement); [download]
And that's worked for me, but I haven't been doing anything with single quotes.