Gossamer Forum
Home : Products : Gossamer Links : Discussions :

table->delete question

Quote Reply
table->delete question
Could someone tell me how to delete the 1st record of the search I have below?
Actually, I need to delete the "oldest" comment, but because the records are added
chronologically, I think deleting the first 'found' record should suffice.

# Get our Comments db object
my $comments = $DB->table('GB_Comments');

# Do the search
$comments->select_options ('ORDER BY GB_Comment_Date ASC');
my $comments_sth = $comments->select( { GB_Comment_LinkID => '$id' } );
my $comment_hits = $comments->hits;

if($comment_hits >= $opts->{gb_max_comments})
{
$DB->table('GB_Comments')->delete(row=0);
}

Thank you
Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] table->delete question In reply to
Hi,

Maybe this?

Code:
my $minID = $DB->table('GB_Comments')->select( ['MIN(ID)'] )->fetchrow;
$DB->table('GB_Comments')->delete( { ID => $minID } );


Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [rgbworld] table->delete question In reply to
Better to use the "limit" option. Set up your search, but only request ONE record.

$comments->select_options ('ORDER BY GB_Comment_Date ASC', 'Limit 1');

That will return one unique record, which will be the oldest.

Then, simply delete that.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] table->delete question In reply to
I actually had tried the LIMIT, but this works out best because if the MaxComments pref is lowered from say 10 to 5, the next time a comment is added to a link, the total number of comments will be reduced to the new max. It is self-reducing Cool

You guys are great. Thanks!

Code:
# Get our Comments db object
my $comments = $DB->table('GB_Comments');

# Do the search
my $comments_sth = $comments->select( { GB_Comment_LinkID => $id } );
my $comment_hits = $comments->hits;

while (my $row = $comments_sth->fetchrow_hashref()) {

if($comment_hits >= $opts->{gb_max_comments})
{
my $minID = $DB->table('GB_Comments')->select({ GB_Comment_LinkID => $id }, ['MIN(GB_Comment_ID)'])->fetchrow;
$DB->table('GB_Comments')->delete( { GB_Comment_ID => $minID } );
$DB->table('GB_Clicks')->delete( { GB_Click_CommentID => $minID } );

$comment_hits--;
}
}


I'm sure it could be shortened, but it works perfectly.

Chris
RGB World, Inc. - Software & Web Development.
rgbworld.com