Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Re: [jai] select_options and query_sth

Quote Reply
Re: [jai] select_options and query_sth In reply to
Still no feedback!!!!!!!!!!!!!!

I'll try to give more details, maybe that will help.

The plugin sub below does SEEM to work ok but I am still concerned about the reliability of the red coding.

If my GROUP BY is being applied to query_sth it may not be reliable because query_sth SELECTs ALL fields by default and whatever columns are in the SELECT must also be in the GROUP BY. In my case, I only want two columns in the GROUP BY.

As I said in my post above, if I change the my $sth = $self->{db}->query_sth ($self->{cgi}) to my $sth = $self->{db}->select ($self->{cgi}) it doesn't process the form input in the same way and I get errors in my WHERE clause.

What should I do? Are the red areas in my sub reliable or not?

Thank you.

Simon.





sub split_modify_search_results {
# -------------------------------------------------------------------
# This subroutine will get called whenever the hook 'modify_search_results'
# is run. You should call GT::Plugins->action ( STOP ) if you don't
# want the regular code to run, otherwise the code will continue as
# normal.
#
#----------------------------------------------------------------------
my $self = shift;
# Ignores the plugin if this is not contact table
($self->{cgi}->{db} ne 'public_holiday') and return @_;
GT::Plugins->action ( STOP );




return $self->home($self->_language('PER_MOD')) unless ( $self->{user}->{modify_p} );

# Make sure the user passed in some values to search on
$self->_check_opts or return $self->modify_search_form ($self->_language('SRC_FAILURE'));

# Format the cgi for searching
$self->format_search_cgi;

# Check if users can delete only their own records
if ( $self->{cfg}->{'auth_modify_own'} and $self->{cfg}->{'auth_user_field'} and !$self->{user}->{admin_p} ) {
$self->{cgi}->{$self->{cfg}->{'auth_user_field'}} = $self->{user}->{'Username'};
$self->{cgi}->{"$self->{cfg}->{'auth_user_field'}-opt"} = '=';
}



#################################

my $group = "GROUP BY public_holiday_201, public_holiday_owner_id";
$self->{db}->select_options($group);




# Do the search and count the results.
my $sth = $self->{db}->query_sth ($self->{cgi}) or return $self->modify_search_form($GT::SQL::error);
my $hits = $self->{db}->hits();


# Return if we haven't found anything.
if ( $hits == 0 ) {
#------------demo code-----------

return $self->modify_search_form ($self->_language('SRC_NOTFOUND'));
}

# Go straight to the modify form if we only have on result.
if ( $hits == 1 and !$self->{cgi}->{sdo} ) {
$self->{cgi}->{modify} = 0;
my $row = $sth->fetchrow_hashref;
foreach ( keys %$row ) {
$self->{cgi}->{$_} = $row->{$_};
}
return $self->modify_form();
}

# Build speed bar
my $speedbar = '';
if ( $hits > ($self->{cgi}->{mh}|| 25) ) {
my $name = GT::CGI->url(remove_empty => 1);
$speedbar .= $self->{disp}->toolbar($self->{cgi}->{nh}|| 1, $self->{cgi}->{mh}|| 25, $hits, $name);
}

# Return results
my @output;
my @pk = $self->{db}->pk;
my $i = 1;
while ( my $row = $sth->fetchrow_hashref ) {
my $hidden;
foreach my $key ( @pk ) {
if ( $self->{db}->can ('_complete_name') ) {
my $new = {};
for ( keys %{$row} ) {
$new->{$self->{db}->_complete_name ($_)} = $row->{$_};
}
$row = $new;
}
my $val = $row->{$key};
$hidden .= qq~<input type=hidden name="$i-$key" value="$val">~;
}
$row->{hidden} = $hidden;


push @output, $row;
$i++;
}

my $enctype = $self->{db}->_file_cols() ? 'enctype="multipart/form-data"' : '';

return ('search_results.html',{
header => $self->_language('HEA_SRC_RESULT'),
results => \@output,
enctype => $enctype,
speedbar=> $speedbar,
msg => $self->_language('SRC_RESULT', $hits),
hits => $hits
});

#end sub
}
Subject Author Views Date
Thread select_options and query_sth jai 8578 Feb 24, 2003, 7:34 PM
Thread Re: [jai] select_options and query_sth
jean 8380 Feb 26, 2003, 11:14 AM
Thread Re: [jean] select_options and query_sth
jai 8359 Feb 27, 2003, 3:08 AM
Thread Re: [jai] select_options and query_sth
jai 8345 Mar 3, 2003, 9:47 PM
Thread Re: [jai] select_options and query_sth
jai 8300 Mar 7, 2003, 3:16 PM
Post Re: [jai] select_options and query_sth
jai 8268 Mar 11, 2003, 3:58 PM
Thread Re: [jai] select_options and query_sth
jean 8252 Mar 11, 2003, 4:39 PM
Thread Re: [jean] select_options and query_sth
jai 8265 Mar 11, 2003, 9:32 PM
Thread Re: [jai] select_options and query_sth
jean 8246 Mar 12, 2003, 12:05 AM
Thread Re: [jean] select_options and query_sth
jai 8205 Mar 17, 2003, 6:08 AM
Thread Re: [jai] select_options and query_sth
jean 8216 Mar 17, 2003, 2:46 PM
Thread Re: [jean] select_options and query_sth
jai 8194 Mar 17, 2003, 3:15 PM
Post Re: [jai] select_options and query_sth
rgbworld 7774 May 22, 2005, 3:44 PM