I'm not sure I follow what you're trying to do here, but I think
you could just keep track of the have-i-bound-this-param yourself.
Tim.
On Wed, Feb 26, 2003 at 07:29:49PM -0500, Rudy Lippan wrote:
> On Wed, 26 Feb 2003, Tim Bunce wrote:
>
> > > I know there is a {NUM_OF_PARAMS} attribute and a {ParamValues} attribute,
> > > but is there a way to get the names of :foo style params before they are
> > > bound?
> >
> > Umm, not officially currently but there's a good chance that keys
> > %{$sth->{ParamValues}} would work on many drivers that support it.
> >
> > I'll add a note to that effect in the docs so that'll become the
> > standard way.
> >
> > A slight downside is that it won't be possible to tell the difference
> > between a placeholder that's not been bound and one that has but
> > was bound to undef. But I don't think that'll be a big issue.
> > Anyone disagree?
>
> Humm. I don't know. I just stated playing with named placeholders and have
> not compleatly hashed this out, but I have been going down the lines of
> using :foo with data structs that match the param names so I can just
> iterate and bind instead of having to count placeholers or having to
> create an array of '?'s and an array of data to send to execute. So:
>
>
> # set params to hash of params.
> while (my ($k,$v) = each %data) {
> $sth->bind_param(":$k",$v);
> }
>
> # or more cleanly
> for (qw( list of names to bind) {
>
> }
>
>
> But what would be nice to be able to do (and what motivated my qustion),
> is to just grab the list of placeholders from the DBD since it
> already knows. like:
>
> for (kyes %{$sth->{ParamValues}) {
>
> unless ($bind_undef_to_unkown && exists $data{$_}) {
> $sth->bind_param($_, undef);
> }
> $sth->bind_param($_, $data{$_})
> }
> $sth->execute();
>
>
> The problem that I see with the above is if $bind_undef_to_unknown is
> false :unbound would keep its value from the last call. The loop could
> probably thow an exception if $bound_undef... is false and the data
> element does not exist. So I guess I would like soemthing that does not
> tell me whether a placeholder has been bound but more something that lets
> me reset the "bound status" (But not for type binding, just for execute)
>
> As an example:
>
> eval {
> $sth->bind_hash(\%data, {bind_undef_to_unkown=>1}); #
> $sth->execute(); # Throws error on unbound param.
> $sth->reset_bind(); # reset so some other f(x) does not get our params.
>
> $sth1->bind_hash(\%data1);
> $sth1->execute; # remembers bindings not in %data1
>
> }; if (my $e = @_) {
> ...
> }
>
>
> Thoughts? Make sense? Am I loosing it?
>
> -r
>
>