Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Error message using get

Quote Reply
Error message using get
I have a list of LinkIDs and I want to do some updates on their records if they exist, or add them if not. So I am using a foreach loop:

foreach my $link (@list) {

...

my $rec = $DB->table('Links')->get("$link");

...

}

This works for the first value in the list and then gives me an error message:

Can't call method "prepare" without a package or object reference at /pathtoadmin/GT/SQL/Driver/MYSQL.pm line 36.

Any ideas what the problem may be? None of the IDs in the list exists in the table.

Thanks, Laura.
The UK High Street
Quote Reply
Re: [afinlr] Error message using get In reply to
You may use count($id) to check if a record exists, then use get($id) if the count() showed it exists...

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Error message using get In reply to
Thanks for replying. I changed it to count(LinkID=>"$link") and it is still giving the same error message for the second id in the list.
Quote Reply
Re: [afinlr] Error message using get In reply to
No LinkID column in Links table as I know.
Try: count( ID =>"$link")

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Error message using get In reply to
Sorry - typing error - that is what I used.

I've cut out all the extra code and this is what I have:

my @listlink = (5000,5001,5002);
foreach my $link (@listlink){
print "LinkID = $link\n";
my $rec = $DB->table('Links')->get($link);
}

And this is the output:

LinkID = 5000
LinkID = 5001
Content-type: text/html

Can't call method "prepare" without a package or object reference at /path to admin/GT/SQL/Driver/MYSQL.pm line 36.

So it works fine for the first one - just can't do any more than that.

Last edited by:

afinlr: Mar 21, 2003, 7:38 AM
Quote Reply
Re: [afinlr] Error message using get In reply to
Hmm. Strange.
Do you have any plugins installed, mod changed added on core code?
Could you post the full debug message or if it's too long send by PM to me?

Could you also post the exact code you used?

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [afinlr] Error message using get In reply to
Code:
require GT::SQL::Condition;
$DB->table('Links')->update({ Foo => 'Bar' }, GT::SQL::Condition->new('ID', 'IN', \@list));

That's all you need....if you do get that error again you can turn on debugging to find the cause.

Btw, the code above equates to...

UPDATE Links SET Foo = 'Bar' WHERE ID IN ('1','2','3');

...where 1,2,3 are whatever ID's are in @list
Quote Reply
Re: [webmaster33] Error message using get In reply to
Mmm, strange. It says that it can't connect to the database because I don't have DBI installed. I have recently upgraded perl so this could indeed be the problem - but how has my site been working without it?

Checking the Environment it says DBI.pm Version: 1.14 - but it also has the perl version as the old version - I'm very confused now!

Anyway, hopefully it will be sorted if I install DBI. Thanks for your help.