Hello friends,

one common problem is:
Insert foo to db if foo doesn't exists, get ID at last.
I am pretty sure it could be done better way, snippet here:

#insert link
my $sth = $dbh->prepare_cached(q[
   INSERT INTO link
   SET    link = ?
   ON DUPLICATE KEY UPDATE link = link ]);
$sth->execute( $hash{'feed_link'} );

#get ID
my ($link_id) = $mydbh->selectrow_array (' select ID FROM link Where link = ? 
', {}, $hash{'feed_link'} );

Could be this done in ine SQL statement ?
I am using MYSQL.

/brano



Reply via email to