Perl and SQL

Robert A. Klahn plug-devel@lists.PLUG.phoenix.az.us
Tue Mar 25 21:27:07 2003


There is some variance here depending upon what database manager you are
using, but in general using the DBI placeholders should work for what
you are trying to do, thus:

$dbh->do("insert into my_table (big_column) VALUES
(?)",undef,$large_and_nasty);

You can also do the same thing with a $dbi->prepare() and
$sth->execute(), but I tend to use do() for insert statements.

Doing things this way (with a placeholder) is preferred over using
$dbi->quote(). quote() does not handle all binary cases the way you
would expect.

Bob.

On Tue, 2003-03-25 at 11:00, plug-devel-request@lists.PLUG.phoenix.az.us
wrote:
> 
> Message: 1
> Date: Tue, 25 Mar 2003 04:41:35 -0700
> From: Austin Godber <godber@uberhip.com>
> To: plug-devel@lists.PLUG.phoenix.az.us
> Subject: Perl and SQL
> Reply-To: plug-devel@lists.PLUG.phoenix.az.us
> 
> Hello Everyone,
> 	I am playing around with a little perl and SQL.  I am having trouble 
> doing an insert into a text field when the text is large and nasty.  I 
> am not sure how I can properly escape out the nasty characters.
> 	I have the text stored into a variable which I then use in my insert 
> statement.  This works fine with smaller stuff of course but it seems 
> like an awfully unpleasant way of inserting LARGISH text.  I am pretty 
> new to both perl and SQL so I think I may be missing something (or do I 
> have to escape out every reserved token before inserting?).
> 
> Austin
> 
> 
> 

-- 
Robert A. Klahn <robert_a_klahn@fastmail.fm>