Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

hidden features in DBSQL

Quote Reply
hidden features in DBSQL
Alex, could you explain this piece of code?
Code:
foreach my $column (@{$self->{'db_cols'}}) {
($opt_r->{$column} =~ /^>(.+)$/) and push (@gt_fields, $1) and next;
($opt_r->{$column} =~ /^<(.+)$/) and push (@lt_fields, $1) and next;
($opt_r->{$column} =~ /^\s*$/) or push (@search_fields, $column);
($opt_r->{"$column-gt"} =~ /^\s*$/) or push (@gt_fields, $column);
($opt_r->{"$column-lt"} =~ /^\s*$/) or push (@lt_fields, $column);
}

I'm alittle confused and also no where is used into LinksSQL but as I can imagine should be very helpful for me.

Thank you in advance.


Lepo
Quote Reply
Re: hidden features in DBSQL In reply to
Isn't that from the parse query routines? It's breaking up the terms into tokens of greater than, less than, etc.

You need to look at the routines in context, since what it's doing is dependent on what is stored in the:

(@{$self->{'db_cols'}} array reference.

Where is this section of code from?

I remember seeing that (or something similar) recently when I was trying to figure out how things were escaped...

I finally gave up, and just called a new instance of DBI->connect in order to access the DBI->escape routine. I couldn't figure out how to do it through DBSQL ... I might have had to bless something, but that starts getting hairy... the new handle was clearer at least to me.




------------------
POSTCARDS.COM -- Everything Postcards on the Internet www.postcards.com
LinkSQL FAQ: www.postcards.com/FAQ/LinkSQL/








Quote Reply
Re: hidden features in DBSQL In reply to
Hi Lepo,

That code is a little old, you should be looking at:

Quote:
foreach my $column (@{$self->{'db_cols'}}) {
($opt_r->{$column} =~ /^>(.+)$/) and do { $opt_r->{$column} = $1; push(@gt_fields, $column); next; };
($opt_r->{$column} =~ /^<(.+)$/) and do { $opt_r->{$column} = $1; push(@lt_fields, $column); next; };
($opt_r->{$column} =~ /^\s*$/) or push (@search_fields, $column);
($opt_r->{"$column-gt"} =~ /^\s*$/) or push (@gt_fields, $column);
($opt_r->{"$column-lt"} =~ /^\s*$/) or push (@lt_fields, $column);
}

as there is a bug in that. Basically what that code does is let you pass in to ->query either:

Field => "Value" # Normal search.
Field => ">Value" # Greater then search.
Field => "<Value" # Less then search.
Field-lt => "Value" # Less then search
Field-gt => "Value" # Greater then search.

Quote:
(@{$self->{'db_cols'}} array reference.

Where is this section of code from?

db_cols is a list of column names pulled from the .def file.

Quote:
I finally gave up, and just called a new instance of DBI->connect in order to access the DBI->escape routine. I couldn't figure out how to do it through DBSQL ... I might have had to bless something, but that starts getting hairy... the new handle was clearer at least to me.

Oh, just use:

my $quoted = $DBH->quote('something');

to do it. Smile

Cheers,

Alex