Or better yet

$sth->bind_param($_, $execute_args[$_]) for (0..$#execute_args);

Arrays start from zero.

Ilya

-----Original Message-----
From: Tim Bunce [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 14, 2004 11:56 AM
To: Martin Moss
Cc: Tim Bunce; Jenda Krynicky; [EMAIL PROTECTED]
Subject: Re: bind_param_inout


On Tue, Sep 14, 2004 at 02:33:41PM +0100, Martin Moss wrote:
> I've got one further issue thats driving me nuts.
> 
> Here is the code I'm running,
> 
>  $sth->bind_param($_, $execute_args[$_]) for ([EMAIL PROTECTED]);

Actually that needs to be $execute_args[$_-1]

That may fix your other problem. If not please post a small
self-contained example.

Tim.

>   $sth->bind_param_inout(scalar @execute_args+1,\$new_id,38);

> N.b. using scalar @execute_args produces rebind
> errors, unless I do the +1." Can you explain why I
> shouldn't use the +1??
> 
> Here is the SQL I'm generating:-
> 
> INSERT INTO table (CompID, User_ID, Referral, Newregistration, 
> Phonecontact, Created, Updated) VALUES (COMPID_seq.nextval, ?, ?, ?, 
> ?, from_unixdate_func(1095168082),
> from_unixdate_func(1095168082)) returning CompID into
> ?
> 
> And here is a dump of the @execute_args array
> 
> $VAR1 = 3738;
> $VAR2 = 'Y';
> $VAR3 = 'Y';
> $VAR4 = 'Y';
> 
> When I run this query I get the following error:-
> 
> DBD::Oracle::st execute failed: ORA-01722: invalid
> number (DBD ERROR: OCIStmtExecute) at 
> /opt/apps/embperl2-apache-matt/perl/perl-5.6.1/lib/site_perl/5.6.1/III
> /Oracle/Object.pm
> line 974.
> 
> If I run the insert without the column which contains
> a number (e.g. run the query without the User_ID
> value, so that ALL the variables passed to the binds
> are of type varchar (perl string) it works. And if I
> run the query for only Numbers it works, but as soon
> as I try to have strings and numbers inside my
> @execute_args array my code breaks. We're running
> Oracle 8i.
> 
> If I expressly say to_num(?) for the num column Then
> the query works when the rest of the columns are
> strings.
> 
> This whole issue seems to be 'quirky' and it's
> probably my lack of Oracle thats causing me to do
> somethign stupid, but I can't tell what.
> 
> Any help would be so much appreciated!
> 
> Marty
> 
> 
>  --- Martin Moss <[EMAIL PROTECTED]> wrote:
> > Thanks for you help,
> > 
> > Marty
> > 
> > 
> >  --- Tim Bunce <[EMAIL PROTECTED]> wrote:
> > > On Tue, Sep 14, 2004 at 12:34:09AM +0200, Jenda
> > > Krynicky wrote:
> > > > From: Tim Bunce <[EMAIL PROTECTED]>
> > > > > 
> > > > > Use bind_param() or bind_param_inout() for all
> > > the params
> > > > > and then call execute() with no arguments.
> > > > > 
> > > > > Tim.
> > > > 
> > > > I wonder ... how about adding a method
> > > bind_params() like this:
> > > > 
> > > > sub bind_params {
> > > >         my $sth = shift;
> > > >         my $pos = (ref($_[0]) ? 1 : shift);
> > > >         for my $param (@{$_[0]}) {
> > > >                 $sth->bind_param($pos++, $param);
> > > >         }
> > > > }
> > > 
> > > No need. See below.
> > > 
> > > > So that this could be shortened to
> > > > 
> > > >         $sth->bind_params([EMAIL PROTECTED]); # default
> > > position is 1
> > > > 
> > >
> >
> $sth->bind_param_inout($#execute_args+1,\$new_id,38);
> > > 
> > > Without adding any new methods it can be shortened
> > > to
> > > 
> > >   $sth->bind_param($_, $execute_args[$_]) for ([EMAIL PROTECTED]);
> > >   $sth->bind_param_inout($#execute_args+1,
> > \$new_id,
> > > 38);
> > > 
> > > I'll add that to the docs.
> > > 
> > > Tim.
> > > 
> > > p.s. I'd use "scalar @execute_args" or
> > > "[EMAIL PROTECTED]" instead of "$#execute_args+1".
> > >  
> > 
> > 
> >     
> >     
> >             
> >
> ___________________________________________________________ALL-NEW
> > Yahoo! Messenger - all new features - even more fun!  
> > http://uk.messenger.yahoo.com
> >  
> 
> 
>       
>       
>               
> ___________________________________________________________ALL-NEW 
> Yahoo! Messenger - all new features - even more fun!  
> http://uk.messenger.yahoo.com
> 

Reply via email to