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

Valid format for update() with CatLinks.CategoryID ?

Quote Reply
Valid format for update() with CatLinks.CategoryID ?
Hi,

I'm trying to write a script, that will update some links with new categories.

However, I'm getting an error:

PROCESSING: Andytest test test (validate_and_email)

Quote:
A fatal error has occured:

CategoryID cannot contain the value '25846
25850
25821' at /home/user/domain.com/cgi-bin/directory/admin/Plugins/ValidationSystem.pm line 242.

Please enable debugging in setup for more details.

The values are built up like so:

Code:
$add->{'CatLinks.CategoryID'} = join("\n",$IN->param($num.'-CatLinks.CategoryID'));

..giving something like:

25846\n25850\n25821

Can anyone suggest why I'm getting that error? (also tried with \r\n)

I've also tried it with:

Code:
$add->{'CatLinks.CategoryID'} = $IN->param($num.'-CatLinks.CategoryID');

..but that only gets the *last* category ID I want :/

TIA

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] Valid format for update() with CatLinks.CategoryID ? In reply to
CategoryID seems to suggest you need to pass in an ID. What made you think you could pass in a newline delimited list?

Have you looked at the update() method to see what it's looking for?
Quote Reply
Re: [Wychwood] Valid format for update() with CatLinks.CategoryID ? In reply to
Hi,

Thanks for the reply.

Thats pretty much what I'm doing already.

1) Get the link (from the DB)
2) Make changes to the hash, so its ready to be added back (this includes thew CatLinks.CategoryID changes too)

3) Do;

Code:
$DB->table('CatLinks','Links')->update( $link, { ID => 4$ink->{ID} } ) || die $GT::SQL::error;

I think what I may have to do as a work around, is just do something like:

Code:
$DB->table('CatLinks')->do_query("DELETE FROM glinks_CatLinks WHERE LinkID = $link->{ID}");
foreach (@cat_ids) {
# add the values here
}

Not the ideal solution, but it will work ok for now (until a fix is found)

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] Valid format for update() with CatLinks.CategoryID ? In reply to
Hi,

For anyone interested, heres the solution code:

$link is the one hash of the link in question.. and @CategoryIDs is an array of the category ID's this link needs to be assigned to

Code:
$DB->table('CatLinks')->do_query(qq|DELETE FROM lsql_CatLinks WHERE LinkID = $link->{ID}|) || die $GT::SQL::error;

foreach (@CategoryIDs) {
$DB->table('CatLinks')->do_query(qq|INSERT INTO lsql_CatLinks (LinkID,CategoryID) VALUES ($link->{ID},$_)|) || die $GT::SQL::error;
}

Just in case anyone comes across a similar problem :)

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] Valid format for update() with CatLinks.CategoryID ? In reply to
You should use the delete/insert methods instead of do_query in order to handle any foreign keys.

Code:
$DB->table('CatLinks')->delete({ LinkID => $link->{ID} });
foreach (@CategoryIDs) {
$DB->table('CatLinks')->insert({ LinkID => $link->{ID}, CategoryID => $_ });
}

Last edited by:

Wychwood: May 12, 2008, 9:59 AM
Quote Reply
Re: [Wychwood] Valid format for update() with CatLinks.CategoryID ? In reply to
Hi,

Doing:

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

..deletes the link - cos the tables are interlinked, so thats a no go <G>

Quote:
$DB->table('CatLinks')->insert({ LinkID => $link->{ID}, CategoryID => $_ });

I'll give that a go - not sure it will work though (seem to remember i tried it before - and it gave me errors)

Ideally, I'd prefer GT to let me know why the update() isn't likeing the format I was trying to use - but at least the solution I have will work for the momeny :)

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] Valid format for update() with CatLinks.CategoryID ? In reply to
It's basic Perl really. You're calling $IN->param() in scalar context ($foo = $IN->param('foo')), so it's only returning a single value. Call it in list context and you'll get all values: my @foo = $IN->param('foo'). The other issue you're having is that add/insert/modify/update obviously do not take newline delimited values - pass it an array ref instead.

Adrian
Quote Reply
Re: [brewt] Valid format for update() with CatLinks.CategoryID ? In reply to
Hi,

Thanks, I'll play about with that tomorrow Smile

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!