On 18 Jan 2005, Dmitry Karasik wrote:
> >> Then I've modified the script so it looks like this:
> >>
> >> my $sth = $dbh->prepare( "SELECT dummy(?)"); $sth-> bind_param_array(
> >> 1, [1,2,3]);
>
> Rudy> You caould hack it by passing in a searlized copy of the array and
> Rudy> let bind_param do the final quote pass.
>
> I'm not sure how do I do that?
>
Do a recursive traversial of the array and turn it into a string with elements
surrounded with '"'s and separated by ','s, with dementions delimited by '{}'
pairs and separated by ','s. And of course, you have to escape " that are
already in the string and then do a final pass with standard postgres string
quoting -- but you can let the bind_param() call do this last pass.
> Rudy> $sth->bind_param(":array_column", [EMAIL PROTECTED],
> Rudy> {pg_type=>INT4ARRAYOID}); $sth->execute();
>
> Rudy> I need to make a final pass at the array code (probably on either
> Rudy> tue, or wed or friday) before it in production ready, but I think
> Rudy> that you will be fine with the integer support as it is now.
>
> Thanks for a quick response. Well, I also need strings (TEXT) arrays,
> and I think I'd rather wait for a production-ready version. Especially,
> if the array binding requires such an undocumented syntax.
It's not undocumnted. This is the same way that you bind integers or any
non-standard type that you don't want quoted as a varchar.
> If I understand correctly, this feature is not fully designed yet, therefore
> I'd like to stick with a well-defined syntax or best practices (if there's
> any) so next upgrades won't be painful.
It is fully designed. However, I need to take another pass at the string
handling code to clean it up and make sure that there are no hidden segfaults --
I have not convinced myself yet that the malloc()s are large enough and that
thereis no place where the code could run off the end of a string.
Rudy