DBI has a built in method, DBI->quote;
eg:
my $dbh = DBI->connect(...........);
my $str = "Haven't I got lot's of badl'y used apostrophy's";
$str = $dbh->quote($str);
# $str is now "Haven\'t I got lot\'s of badl\'y used apostrophy\'s"
# But it won't sort out intentionally bad English : )
While we're on the subject, this also saves a lot of hassle when forming
SQL statements.
# Build a hash with the stuff to insert...
my %to_insert = ( column_name => 'unquoted value'
more_columns => more_values... );
my @columns = keys %to_insert; # gets the columns
my @values = map $dbh->quote($_), values %to_insert; # DBI->quote's
each value
local $" = ","; # changes a printed array to be comma (rather than
space) seperated
my $SQL ="INSERT INTO table (@columns) VALUES (@values)";
Hope this helps,
Dave
borakovej wrote:
>
> OK here is an overview of my problem, I am running a script to take a pipe delimited
>flat file and pump the data into a database. Due to the users putting extraneous
>apostrophes I am getting errors that there are unclosed apostrophes in the fields. I
>am looking for a way to escape these apostrophes as simply as possible. Can someone
>help?
>
> Judd Borakove
--
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
David Wood, Web Developer<br>
[a] Clickmusic Ltd, 99c Talbot Road, London W11 2AT<br>
[t] 020 7727 7500
<br>[w] www.clickmusic.co.uk<br>
<br>"There are three types of people in the world; those who can count,
and those who can't."
<br> </html>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]