Gossamer Forum
Quote Reply
Deleting links...
Currently, to delete links in one of my plugins, I am using the $table->delete( { ID => $ID } ) statement.

I've just come across a problem with this. It leaves the entries in lsql_CatLinks and the count in lsql_Category does not go down. Is there a built in function to completly delete a link from the database, or would I be better creating my own code to do something like;

1) Delete from lsql_Links
2) Delete all occurences of that ID in lsql_CatLinks
3) Downgrade the number of links in the main categories, and sub-categories within it.

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: [Andy] Deleting links... In reply to
>>
I've just come across a problem with this. It leaves the entries in lsql_CatLinks and the count in lsql_Category does not go down. Is there a built in function to completly delete a link from the database, or would I be better creating my own code to do something like;
<<

It would do that if you used foreign keys =)
Quote Reply
Re: [Paul] Deleting links... In reply to
Well, I'm only using the current database structure that comes with Links SQL; so there is not a lot I can do about that. Looks like its gonna have to be the long winded method :(

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: [Andy] Deleting links... In reply to
Sorry my fault I wasn't thinking.

The CatLinks table is connected to the Category and Links table. I think what you need to do is delete from the CatLinks table to clean everything up, eg...

$DB->table('CatLinks')->delete({ LinkID => $ID });

Last edited by:

Paul: Apr 18, 2003, 3:51 PM
Quote Reply
Re: [Andy] Deleting links... In reply to
Hi,

Try $table->delete($id) and see if it makes a difference.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Deleting links... In reply to
Where should $table be linked to? 'Links', 'CatLinks' or 'Category' ?

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: [Andy] Deleting links... In reply to
The same as you have it I expect (based onthe fact Alex used your $table variable).
Quote Reply
Re: [Andy] Deleting links... In reply to
Andy,

When this sort of frustration sets in, think about where Alex/GT would have put that call, in this case probably somewhere in the Admin utilities, and try to follow it out. Often you have to follow 2 or 3 or even more attempts to find the file where the actual code is, but it's usually worth it, and you get code that works the way GT is thinking, which is a benefit as well. (It can either get you in tune, or pick up bugs in the GT code.)

Sometimes, taking a break, and wandering through the code, will not only help, but provide other ideas -- sort of like the "old days" with paper encyclopedias, where as you looked up one thing, you usually ended up reading about a lot of other stuff as well <G>

Most of what I learned about Links, perl and SQL has been by following out Alex's code. For me, that is not a bad thing, since I'm not generally interested in writing "perl" code, per se, but rather code that works with the GT engine.

This is not only directed to you :) It's sort of a "pearl" (ouch!) for those wondering how to start.

FWIW: the module documentation provides:

Quote:
delete
This method provides a robust interface to delete entries from your table(s) using join and or foreign key relations.

my $result = $obj->delete ($condition);

You can pass into delete either a condition object to delete multiple entries, or a scalar value to delete the row whose primary key equals the value. If you have a multiple primary key, then you can pass in an array ref to delete that row.

my $result = $obj->delete (
{
col1 => $val1,
col2 => $val2,
...
}
);

-or-

$obj->delete ( $val );

-or-

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

delete returns undef on failure, 1 on success. The error message will be available in $GT::SQL::error.


PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.