You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Scott Chapman <sc...@mischko.com> on 2002/05/14 20:36:00 UTC

DBIx::Recordset $values parameter not behaving as expected.

I have a snippet here of my .epl file:

>     my ($group_file) =
>     Apache::Htgroup->load('/www/ok_users/ar_group'); DBI->trace(2,
>     '/tmp/dbitrace.txt');
> 
>     use DBIx::Recordset ;
>     $maxrow = 500;
>     $db{'!DataSource'} = $req->{website_database};
>     $db{'!Username'} = $req->{db_user};
>     $db{'!Password'} = $req->{db_pass};
>     $db{'!Table'} = 'ar_events';
>     $db{'!Fields'} = 'datetime,eventcode,user,info';
> 
>     $db{'$where'} = 'ar_id = ?';
>     $db{'$values'} = ["$req->{review_num}"];
>
>     # If user is a member of acctmgr group, don't show them Status_Viewed records. 
>     if ($group_file->ismember($req->{user},'acctmgr')) {
>       $db{'$where'} = $db{'$where'} . ' AND eventcode != ?';
>       $db{'$values'} = [$db{'$values'},'Status_Viewed'];
>     }
> 
>     # If the user is not a member of demomode,admin,developer don't show the Analyst_Activity records. 
>     if ((!$group_file->ismember($req->{user}, 'demomode')) &&
>       (!$group_file->ismember($req->{user}, 'admin')) &&
>       (!$group_file->ismember($req->{user}, 'developer'))) {
>       $db{'$where'} = $db{'$where'} . ' AND eventcode != ?';
>       $db{'$values'} = [$db{'$values'},'Analyst_Activity'];
>     }
> 
>     *set = DBIx::Recordset -> Search(\%db);
>     $names = $set -> Names;

This works fine if the two IF clauses fail.  If both of the conditions are not met then the query works like it should.  If either of the conditions is met, things 
break.   

The $values parameter is getting 'undef' in my DBI->Trace info:

>    -> bind_param for DBD::Sprite::st (DBI::st=HASH(0x85254e4)~0x883b6e4 1 ARRAY(0x8a54604) undef)
>    -> bind_param for DBD::Sprite::st (DBI::st=HASH(0x85254e4)~0x883b6e4 2 'Analyst_Activity' undef)

... so I think I'm specifying them incorrectly.  I'm not familiar with the square brackets notation.  I assume it makes an array?  Clearly I'm missing 
something in my Perl knowlege.  Can someone straighten me out?  

Thanks!
Scott



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: DBIx::Recordset $values parameter not behaving as expected.

Posted by Gerald Richter <ri...@ecos.de>.
> >
> >     $db{'$where'} = 'ar_id = ?';
> >     $db{'$values'} = ["$req->{review_num}"];
> >
> >     # If user is a member of acctmgr group, don't show them
Status_Viewed records.
> >     if ($group_file->ismember($req->{user},'acctmgr')) {
> >       $db{'$where'} = $db{'$where'} . ' AND eventcode != ?';
> >       $db{'$values'} = [$db{'$values'},'Status_Viewed'];
> >     }
> >....
>
> This works fine if the two IF clauses fail.  If both of the conditions are
not met then the query works like it should.  If either of the conditions is
met, things
> break.
>
> The $values parameter is getting 'undef' in my DBI->Trace info:
>
> >    -> bind_param for DBD::Sprite::st (DBI::st=HASH(0x85254e4)~0x883b6e4
1 ARRAY(0x8a54604) undef)

It's not undef, but an array refence, where you want to have the content of
the array. The [ ] creates an array and returns a reference to it, so either
write

      $db{'$values'} = [@{$db{'$values'}},'Status_Viewed'];

this will insert the values of $db{'$values'}into the new array (instead of
the reference to the array) or do a

push @{$db{'$values'}}, 'Status_Viewed' ;

Gerald

-------------------------------------------------------------
Gerald Richter    ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting

Post:       Tulpenstrasse 5         D-55276 Dienheim b. Mainz
E-Mail:     richter@ecos.de         Voice:    +49 6133 925131
WWW:        http://www.ecos.de      Fax:      +49 6133 925152
-------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: DBIx::Recordset $values parameter not behaving as expected.

Posted by Gavin Carr <ga...@openfusion.com.au>.
On Tue, May 14, 2002 at 11:36:00AM -0700, Scott Chapman wrote:
> >     # If user is a member of acctmgr group, don't show them Status_Viewed records. 
> >     if ($group_file->ismember($req->{user},'acctmgr')) {
> >       $db{'$where'} = $db{'$where'} . ' AND eventcode != ?';
> >       $db{'$values'} = [$db{'$values'},'Status_Viewed'];
> >     }
> > 
> >     # If the user is not a member of demomode,admin,developer don't show the Analyst_Activity records. 
> >     if ((!$group_file->ismember($req->{user}, 'demomode')) &&
> >       (!$group_file->ismember($req->{user}, 'admin')) &&
> >       (!$group_file->ismember($req->{user}, 'developer'))) {
> >       $db{'$where'} = $db{'$where'} . ' AND eventcode != ?';
> >       $db{'$values'} = [$db{'$values'},'Analyst_Activity'];
> >     }
> > 
> >     *set = DBIx::Recordset -> Search(\%db);
> >     $names = $set -> Names;
> 
> This works fine if the two IF clauses fail.  If both of the conditions are not met then the query works like it should.  If either of the conditions is met, things 
> break.   
> 
> The $values parameter is getting 'undef' in my DBI->Trace info:
> 
> >    -> bind_param for DBD::Sprite::st (DBI::st=HASH(0x85254e4)~0x883b6e4 1 ARRAY(0x8a54604) undef)
> >    -> bind_param for DBD::Sprite::st (DBI::st=HASH(0x85254e4)~0x883b6e4 2 'Analyst_Activity' undef)
> 
> ... so I think I'm specifying them incorrectly.  I'm not familiar with
> the square brackets notation.  I assume it makes an array?  Clearly
> I'm missing something in my Perl knowlege.  Can someone straighten me
> out?  

The square brackets create a reference to an array. So when you use
$db{'$values'} inside your if statements you're getting the reference,
when what you're after is the array itself.

You can either dereference the arrayref by putting a @{} around it:

  $db{'$values'} = [@{$db{'$values'}},'Analyst_Activity'];

or just use 'push' to append the item to the array:

  push @{$db{'$values'}}, 'Analyst_Activity';

An equivalent style for this second one with your scalar $where would be:
 
  $db{'$where'} .=  ' AND eventcode != ?';

HTH.

Cheers,
Gavin


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org