Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Selecting Array data??

Quote Reply
Selecting Array data??
I have the following function in a DbMan SQL "custom.pm" file:

sub GetClaimData {
#--------------------------------------------------------------------
# Fetch a row of data in the Claims database.
#
my $tags = GT::Template->tags;
my $id = $tags->{ClaimID};
my $info = $tags->{home}->{sql}->table('Claims')->get ($id);

# I'm just playing here.
# if($info->{'InsuredID'} eq '') { my $info->{'InsuredID'} = $tags->{'InsuredID'}; }
# if I try this... this is what I get:
# Can't use an undefined value as a HASH reference at /home/www/html/code/admin/Dbsql/custom.pm line 65.

return $info;
}

The purpose of it is to grab an entire row of data for an SQL source.

Problem:

I want to evaluate one of the columns (InsuredID) in that row and see if it is blank (eg. equal to ''), if it is, then I want to replace it with an existing variable (eg. in this case $tags->InsuredID) My problem lies in that I do not know how to break apart $info and evaluate that column and the other part is how do I replace the new variable back into the $info data array?

Am I close with the playing around above??
Quote Reply
Re: [LanceWilson2] Selecting Array data?? In reply to
Try this:
...
my $info = $tags->{home}->{sql}->table('Claims')->get ($id) || {};
...

TheStone.


B.
Quote Reply
Re: [TheStone] Selecting Array data?? In reply to
I don't understand what that does???

I want to grab the entire row of data (about 15 different columns), like it is now, but if the column named 'InsuredID' (in that row I just grabbed) is blank then I want to substitute that with the value from $tags->{InsuredID}. Does that better explain it? The problem I am having is that I have a tag <%InsuredID%> that is passed into a page. On that page I then grab a bunch of information from a table row BUT one column (InsuredID) in that row may be blank. (depending on the data) If it is blank, I want to use the origimal InsuredID passed into the page (via HTTP POST). The problem I am having is that since it is the same column name the table retrieval overwrites the page "InsuredID" variable (sometimes with a blank entry).

Maybe I'm doing this the wrong way... but it seems to make the best sense to just search, evaluate and replace (if needed) the $info storage container before it is returned back to the page and overwrites the InsuredID tag.
Quote Reply
Re: [LanceWilson2] Selecting Array data?? In reply to
Your script looks just fine which should return a hash. If you can send me the info to access your admin panel via email, I'll have a closer look.

TheStone.

B.
Quote Reply
Re: [TheStone] Selecting Array data?? In reply to
BINGO!

Figured it out. It appears that the InsuredID tag did not exist in some cases. So I added this line to the top of the template file and now it works just fine.

<%if not InsuredID%><%set InsuredID = ''%><%endif%>

Now my script, which was written correctly to begin with, works just fine. The problem was that it didn't have anything to write to when I told it to write to $tags->{'InsuredID'}. Which means that your code doesn't create a variable... it has to exist already. Correct?