Re: [ILUG] wee coding challenge..

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


"John P. Looney" wrote:
>
> Anyone know how to trim any character that's not a letter, number,
> fullstop, or space from a certain column, in a certain MySQL table ? Turns
> out that silly people have been storing their "fullname" in the database
> of my email system, with colons, commas etc. You have no idea how much
> that upsets Qmail and sendmail. I've stuck some javascript in to stop
> people entering it...but that's not much good for the 5000 users that
> already could have done it...

what about something like

$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.

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