Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Problem with Links SQL v. 2.2.0 global

Quote Reply
Problem with Links SQL v. 2.2.0 global
Hi,

I have a problem with the following code/global:

<%set numhits = 100%>
<%set maxhits = 10%>
<%ifnot nh%><%set nh=1%><%endif%>


sub {
my $tags = shift;
my ($output,$sth,$link);
my $db = $DB->table ('Links');
my $nh = $tags->{nh}||10;
my $mh = $tags->{maxhits}||100;
my $offset = ($nh-1) * $mh;
$db->select_options ("ORDER BY Mod_Date DESC", "LIMIT $offset, $mh");
my $sth = $db->select ( { isValidated => 'Yes', isChanged => 'Yes' });
while ($link = $sth->fetchrow_hashref) {
$output .= Links::SiteHTML::display ('link', $link);
}
return $output;
}


Error:

Can't call method "fetchrow_hashref" on an undefined value at (eval 24) line 10.

GT::SQL::error = Failed to execute query: 'SELECT * FROM zz_Links WHERE isChanged = ? AND isValidated = ? ORDER BY Mod_Date DESC LIMIT 1.97403111175413e+16, SCALAR(0x85fdcac)' Reason: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SCALAR(0x85fdcac)' at line 1






If I just use "LIMIT 0, 10" - the results are displayed OK

Everything worked perfectly with Links SQL version 2.1.2

Crazy

Any ideas?


Thanks in advance!
Quote Reply
Re: [Payooo] Problem with Links SQL v. 2.2.0 global In reply to
Try changing

my $nh = $tags->{nh}||10;
my $mh = $tags->{maxhits}||100;

to

my $nh = $tags->{nh};
my $mh = $tags->{maxhits};
$nh =~ /\d+/ || $nh=1;
$mh =~ /\d+/ || $mh = 100;

Not sure why it isn't reading the $tags in though.
Quote Reply
Re: [afinlr] Problem with Links SQL v. 2.2.0 global In reply to
Thanks afinlr!


No luck:

Unable to compile 'global_name': Can't modify logical or (||) in scalar assignment at (eval 24) line 7, at EOF



Crazy
Quote Reply
Re: [Payooo] Problem with Links SQL v. 2.2.0 global In reply to
Blush Oops. Try this

($nh =~ /\d+/) || ($nh=1);
($mh =~ /\d+/) || ($mh = 100);
Quote Reply
Re: [afinlr] Problem with Links SQL v. 2.2.0 global In reply to
Thanks.

That worked partially: the results are displayed but <%set maxhits = 10%> part doesn't work (I can't limit the number of links per page)

But what worries me is that everything worked perfectly with 2.1.2 version Crazy
Quote Reply
Re: [Payooo] Problem with Links SQL v. 2.2.0 global In reply to
No - this is just a quick fix that will get it working. I don't know why it isn't reading in the tags. You can just change $mh=10 in the fix above to get 10 links per page in the meantime.
Quote Reply
Re: [afinlr] Problem with Links SQL v. 2.2.0 global In reply to
OK, thanks for helping me.



I guess this is a bug or something like that.

Last edited by:

Payooo: May 9, 2004, 7:38 AM
Quote Reply
Re: [Payooo] Problem with Links SQL v. 2.2.0 global In reply to
It's not exactly a bug, but a change in the way GT::Template handles things, with respect to setting and escaping variables. Change the 'my $nh' and 'my $mh' lines like this:

my $nh = (ref $tags->{nh} ? ${$tags->{nh}} : $tags->{nh}) || 10;
my $mh = (ref $tags->{mh} ? ${$tags->{mh}} : $tags->{mh}) || 100;

This happens because of GT::Template's escaping. GT::Template, by default (Links SQL turns this option off) escapes tags, and when a tag is meant not to be escaped, if can be passed as a scalar reference (e.g. \'<some html>' instead of '<some html>'). So, when you perform a 'set' within a template, GT::Template sets the value as a scalar reference, so that you can do something like: <%set myvar = '<b>foo</b>'%><%myvar%> and have it show up as foo rather than <b>foo</b>. Unfortunately, this introduces a complication when using the raw tags hash, which is what gets passed into globals by default, as the variables could be scalar references. The code above will properly handle the dereferencing, if required.

We do intend to change this behaviour, so that what gets passed in is _not_ the raw, internal GT::Template variable hash reference, but a "magic" (i.e. "tied", in Perl terminology) hash reference that will give you the value, just as if it was in a template. That way, accessing $tags->{foo} would give you the same value you'd get in a template, whether 'foo' is a global, escaped HTML, or just a normal template tag.

On an unrelated note, it is now possible to specify the LIMIT as: "LIMIT $mh OFFSET $offset" - it was added as it is easier to understand at a glance than figuring out the order of MySQL's two-argument limit.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] Problem with Links SQL v. 2.2.0 global In reply to
Fixed Wink

Thanks for all the help provided.
Quote Reply
Re: [Jagerman] Problem with Links SQL v. 2.2.0 global In reply to
Hi Jason,

any idea when that will be released. This is turning out to be a major change for my websites.
It worked perfectly in 2.1.x, but now.... not so good.

Is there a setting we can manually change to get it to work the way it did before?

peace.