Re: [ILUG] wee coding challenge..

From: Thomas Bridge (thomas.bridge at domain via-net-works.ie)
Date: Thu 04 May 2000 - 12:40:16 IST


 
> $dbh->do("LOCK table");
> $sth = $dbh->prepare("SELECT key,column_to_change FROM table");
> $sth->execute;
> while($ref = $sth->fetch) {
> $key = $$ref[0];
> $column = $$ref[1];
> $column =~ s/^[\w\s\.\-]//g; # Add other legal characters into square
> brackets
> $dbh->do("REPLACE INTO table (key, column_to_change) VALUES ($key,
> '$column');
> }
> $dbh->do("UNLOCK table");
>
> This is off the top of my head, I haven't tested and normal disclaimers
> to pieces of code written in two minutes apply.

Actually I just had a look - this won't work (well it will, but it'll
also nuke the rest of the information in the row which is something you
probably don't want).

Just extend the SELECT and REPLACE commands appropriately.

T.

-- 
Thomas Bridge				26 Upper Fitzwilliam St.,
Senior Hostmaster/Sysadmin,		Dublin 2,
VIA NET.WORKS Ireland.			Ph: +353 1 6763600
thomas.bridge at domain via-net-works.ie		Fax: +353 1 6627674


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:01 GMT