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

Admin Modify Observation

Quote Reply
Admin Modify Observation
This isn't really a problem, but I was surprised when I encountered it and was wondering if it's intentional.

If you modify links through the admin area, but don't actually make changes (i.e. select one or more links and check them off to modify), then you get an error that the record cannot be found in the database.

When I first noticed this, it was just after setting up a priority field and playing around with a couple of links with priority rankings. I thought it was some bi-product of adding the priority field, but it turned out to happen with any link regardless of priority, but only if no fields are changed.

By the way, what's the best way to add a field for a newly updated Links 2 database? Is there any advantage to first importing with the standard number of fields then adding the priority field vs. adding the priority field first then importing the database into the appropriate fields? The first option sounds the least cumbersome.

Quote Reply
Re: Admin Modify Observation In reply to
I had this problem too. It will happen if the script call $db->modify_record ($rec).
Quote Reply
Re: Admin Modify Observation In reply to
i fixed this before.. alex said it shouldn't do that though.. he said that when no change is made it returns '0E0' and it returns '0' when it doesn't exist..

i made an error message in DBSQL.pm

'NOCHANGE' => 'No changes were made to the record!'

then i changed my sub modify_record to

sub modify_record {
# --------------------------------------------------------
# Updates a record.
# IN : Hash reference of record to update, Hash ref of Where clause.
# OUT: Number of records affected.
my ($self, $rec_r, $extra, $in) = @_;
(ref $rec_r eq 'HASH') or return $self->error ("NOTHASHREF", "modify_record");

# Make sure this record is still ok.
my $status = $self->_validate_record($rec_r);
if ($status ne "ok") { return $self->error('VALIDATE', $status); }

# Create the SQL query.
my $update = '';
foreach my $column (@{$self->{'db_cols'}}) {
$update .= $column . "=" . $DBH->quote($rec_r->{$column}) . ",";
chop $update;
my $key = $self->{'db_key'};
my $key_q = $DBH->quote($rec_r->{$key});
my $table = $self->{'db_table'};
my $where = "$key = $key_q";

my $query = qq!SELECT * FROM $table WHERE $where!;
my $sth = $DBH->prepare($query) or return $self->error ('CANTPREPARE', $query, $DBI::errstr);
$sth->execute() or return $self->error('CANTEXECUTE', $query, $DBI::errstr);
$self->{'last_query'} = $query;
$sth->rows or return $self->error('NOTFOUND');

if (defined $extra and ref($extra) eq 'HASH') {
foreach my $key (keys %$extra) {
$where .= "\nAND $key = " . $DBH->quote($extra->{$key});
$query = qq!
UPDATE $table SET $update
WHERE $where
my $rc = $DBH->do($query) or return $self->error ('CANTEXECUTE', $query, $DBI::errstr);
$self->{'last_query'} = $query;
carp "DBSQL: Record $key_q updated ($rc)" if ($DEBUG);

# Update attachment list.
if ($self->{attach_dir} and (ref $in eq 'CGI')) {
foreach my $aid ($in->param('ATTACH-DELETE')) {
$self->delete_attach ($aid, $rec_r->{$key});
if ($in->param('ATTACH-ADD')) {
$self->attach_file ($rec_r->{$key}, "ATTACH-ADD", $in);

# Update the indexes.
$self->update_index ($rec_r->{$key}, $rec_r) if ($self->{db_is_indexed});

($rc == 0) ? return $self->error('NOCHANGE') : return 1;

i don't think i'm suppose to post from DBSQL.pm.. so if this has to be taken off.. go ahead

Jerry Su
Links SQL User
Quote Reply
Re: Admin Modify Observation In reply to
This seems to be driver dependant. I'll look into it a little more, but we don't want to assume no changes, as if the id can't be found, then it will say "no changes" which isn't the same.