Re: Problem with inserting newlines and ' characters - Mailing list pgsql-general

From Kyle
Subject Re: Problem with inserting newlines and ' characters
Date
Msg-id 14716.29539.806840.987556@ip146.usw5.rb1.bel.nwlink.com
Whole thread Raw
In response to Problem with inserting newlines and ' characters  (Alan Horn <ahorn@inktomi.com>)
List pgsql-general
Alan Horn wrote:
...
> The statement I'm using is thus :
>
> my($sth) = $dbh->prepare("insert into maintenance (sno, date, data) values
> ('$sno', '$date', '$tmpstring')");
>
> (all on one line of course...)
>
> My problem is this. $tmpstring may well contain embedded newlines or '
> characters (these are the two characters I've had problems with so far).
...

The method you're looking for is $dbh->quote.  You could use it like:

$sth = $dbh->prepare("insert into maintenance (sno, date, data)
                        values ($dbh->quote($sno),
                                $dbh->quote($date),
                                $dbh->quote($tmpstring))");

Hope that helps.

Regards,
Kyle


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Multithreaded libpq?
Next
From:
Date:
Subject: Re: PostgreSQL, ODBC, Access