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

DBSQL.pm add_record problem

Quote Reply
DBSQL.pm add_record problem
Since Jerry has indicated he might not upgrade, and I'm sure others will take some time, if you are programming for Links SQL and use DBSQL.pm's add_record method with an arbitrary set of link records, you might hit this problem I did:

(This is basically excerpted from email I sent to Alex, I at first thought this too obscure to bother the forum with, then figured I should probably post anyway).

I have a script that runs along side the rest of links, and it uses a lot of hidden
fields in a form, not all of which are filled in on all submissions.

When an add_record request is made, this is logged (even though the process
finishes)

$rec = $db->add_record ( $in );


[Fri May 12 02:14:20 2000] postcards.cgi: Use of uninitialized value in pattern match (m//) at admin/Links/DBSQL.pm line 1446.


What I'm guessing, is that somewhere (that line number is not a pattern match statement in my file, it's

my @errors = ();

in sub _validate_record

Figuring that perl was just miscounting, and that the pattern match was in that subroutine, I studied it for awhile, then made two changes....


Code:
in sub _validate_record

foreach my $column (@{$self->{'db_cols'}}) {
next if ($column eq $self->{'db_key'}); # This will be auto-generated
if ( (exists ($rec_r->{$column})) and ($rec_r->{$column} =~ /^\s*$/) ) {
$not_null{$column} and push (@errors, "$column (Can not be left blank)");
}
elsif ( exists ($rec_r->{$column}) ) {
if ($valid_type{$column} and !($rec_r->{$column} =~ /$valid_type{$column}/)) {
push (@errors, "$column (Invalid format)");
}
if ($max_length{$column} and (length $rec_r->{$column} > $max_length{$column})) {
push (@errors, "$column (Too long. Max length: $max_length{$column}");
}
}
}
Basically, checking to see if the requested field exists before you try to pattern match it.

The errors went away, and records seem to be added properly.

Hopefully Alex will reply with the official statement of whether it's just my mucking around, or if this is a fix.



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