On Wed, 23 Oct 2002, David Wheeler wrote:

> Okay, the problem is that DBD::Pg's execute() method doesn't call 
> quote() for the parameters passed to it. So quote() is never called for 
> your code. The good news is that you don't have to base64 encode your 
> binary data. Instead, call the quote() method yourself:
> 
> while (my $rd = read $fh, $data2, 65536) {
>       $data .= $dbh->quote($data2);
>       $datasize += $rd;
> }
> 
> Then the data will be properly escaped and insertable into a bytea 
> field.

Albeit with a few extra quotes, if I am reading the above code correctly.


Instead of using the quote() method, why not just bind the paramater as 
SQL_BINARY and let the  quoting in execute() take care of escaping 
all non-printable characters?

So: 

my $ins = $dbh->prepare ('INSERT INTO binfile (size, data) VALUES (?, ?)');
$ins->bind_param(1,$datasize,SQL_INTEGER);
$ins->bind_param(2,$data,SQL_BINARY);
$ins->execute ();
$dbh->commit;

 
> However, this is a workaround. The DBI documentation says of the 
> quote() method, "There is no need to quote values being used with 
> "Placeholders and Bind Values". However, Crist�v�o used Placeholders 

Try binding as SQL_BINARY and let me know if that works.

> and got the error. Should DBD::Pg be calling quote() from its execute 
> method? I looked around a bit at the DBD::Pg code, but the XS is a 

Good question.  Probably, but then it should be calling the libpq
functions when available. And quoting should be made to understand text[] 
types,  also (getting them out, is a complately different problem).


-r

Reply via email to