Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Problems with GT::SQL::Table->delete

Quote Reply
Problems with GT::SQL::Table->delete
Hi, I have a table with combination primary key (tid, pid), I want to delete all records where tid = x how can I do this? Is there an easy way?

I have tried using a condition object but it failed:
$cond = GT::SQL::Condition->new('tid', '=', $tid);
doesn't work.

I have also tried select all pid where tid = $tid, looping through the results and calling delete on each iteration as follows:
$handle = $table->select( { tid => $tid }, ['pid'] );
while(my $row = $handle->fetchrow_hashref) {
$table->delete( { tid => $tid, pid => $row->{'pid'} } );
}

And it fails saying it cannot make a condition object. Besides this is not very efficient.

Does anyone have any ideas?

Thanks in advance, regards,
Tommy

Last edited by:

tommyfotak: Sep 26, 2002, 1:00 PM
Quote Reply
Re: [tommyfotak] Problems with GT::SQL::Table->delete In reply to
From the docs:

Quote:
If you have a multiple primary key, then you can pass in an array ref to delete that row.

...

$obj->delete ( [$val1, $val2] );

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [tommyfotak] Problems with GT::SQL::Table->delete In reply to
Hi,

$table->delete( { tid => $tid } );

should remove all rows where tid = $tid. If that's not working, make sure you are actually passing in something in $tid, and that it's not empty.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [yogi] Problems with GT::SQL::Table->delete In reply to
Hi Yogi, I tried that too and it didn't work.

Thanks Alex will give that a go.