Gossamer Forum
Home : Products : Gossamer Links : Pre Sales :

SEARCH BUG????????

Quote Reply
SEARCH BUG????????
 

when search data by < mark the same as < a, happened software error!!

Content-type: text/html
Software error:
DBSQL (6224): Fatal Error: Unable to execute query: SELECT COUNT(*) FROM Search_Log WHERE a <= NULL Reason: Unknown column 'a' in 'where clause' at /home/gossamer-threads/perl/resources/search.cgi line 199
For help, please send mail to the webmaster (alex@gossamer-threads.com), giving this error message and the time and date of the error.

see below url;
http://gossamer-threads.com/perl/resources/search.cgi?query=<a

How can i solve a problem?


Quote Reply
Re: SEARCH BUG???????? In reply to
Hello alexkk,

I quess the search.cgi has to be modify's so that search input will be filtered. Like sign < > and so on will be filtered. But i don't know how to code (/^\) it . I quess someone else can easily fix this problem.

Regards startpoint.

Quote Reply
Re: SEARCH BUG???????? In reply to
Actually, the Search.pm module would have to be hacked.

Regards,

Eliot Lee

Quote Reply
Re: SEARCH BUG???????? In reply to
Actually, the problem is that <a get's passed to ->query method which interprets that as a search for everything < a. Not what we want.

Change sub log_query in search.cgi to:

Code:
sub log_query {
# --------------------------------------------------------
# Logs the search term.
#
my ($query, $results) = @_;
my $db = new Links::DBSQL "$LINKS{admin_root_path}/defs/Search_Log.def";
$query =~ s/^\s*//g; $query =~ s/\s*$//g;
$query = lc $query;

my $hit = $db->get_record ( $query, 'HASH' );
my $time = $db->get_date . " " . $db->get_time;

if ($hit) {
$hit->{Count}++;
$hit->{Last_Hit} = $time;
$hit->{Results} = $results;
$db->modify_record ($hit);
}
else {
$db->add_record ( { Term => $query, Count => 1, Last_Hit => $time, Results => $results } );
}
}
And you should be fine. Thanks for the bug posting!

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: SEARCH BUG???????? In reply to
Thanks Alex, didn't beat you this time Smile.



Quote Reply
Re: SEARCH BUG???????? In reply to
Hello Alex and rest,

There is still 1 'bug' left in it i believe.

If i enter twice the same search query and it's bigger then 25 i have a problem.
I figure out in table search_log to make field term bigger like 150 will solve this problem.

But if i enter a query bigger then 150 the same problem is appearing.

Something like:
DBSQL (30616): Fatal Error: Unable to execute query: INSERT INTO Search_Log (Term, Count,Results,Last_Hit) VALUES (?,
'1','1','2000-09-06 13:22:22') . Reason: Duplicate entry


So i quess in search.cgi we have to cut the query to a max. lenght. 150 in my case

This part:
$query =~ s/^\s*//g; $query =~ s/\s*$//g;
$query = lc $query;

But how to cut the lenght of the (string) query?

Allready thanks.

Regards Startpoint.

Quote Reply
Re: SEARCH BUG???????? In reply to
my $short_query = substr ($query, 0, 150);

http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/

Quote Reply
Re: SEARCH BUG???????? In reply to
Thanks Pugdog !

I make it $query = substr ($query, 0, 150);

Below follows my log_query from search.cgi with some bug fix like Alex told us and the cut.

But remember that field term in search_log has lenght 25. So make it: $query = substr ($query, 0, 25);
I did adjust the lenght of field term to 150. Maybe there is a other way to do this better but this work without errors for me.


# *** bug fixed search on <a and cut query to 150.
sub log_query {
# --------------------------------------------------------
# Logs the search term.
#
my ($query, $results) = @_;
my $db = new Links::DBSQL "$LINKS{admin_root_path}/defs/Search_Log.def";
$query = substr ($query, 0, 150);
$query =~ s/^\s*//g; $query =~ s/\s*$//g;
$query = lc $query;
my $hit = $db->get_record ( $query, 'HASH' );
my $time = $db->get_date . " " . $db->get_time;
if ($hit) {
$hit->{Count}++;
$hit->{Last_Hit} = $time;
$hit->{Results} = $results;
$db->modify_record ($hit);
}
else {
$db->add_record ( { Term => $query, Count => 1, Last_Hit => $time, Results => $results } );
}
}


Regards Startpoint.