[CDBI] problem with no primary key?

Tilman Baumann tilman.baumann at collax.com
Fri Nov 25 19:00:23 GMT 2005


Hello,

i have a little problem with Class::DBI.
I think its because one of my tables has no primary key.

I have this two tables:

CREATE TABLE "option"
(
product_id varchar(20) NOT NULL,
name varchar(30) NOT NULL,
value int8 DEFAULT 0,
CONSTRAINT option_product_id_fkey FOREIGN KEY (product_id) REFERENCES
product (id) ON UPDATE CASCADE ON DELETE CASCADE
)
WITHOUT OIDS;

CREATE TABLE product
(
id varchar(20) NOT NULL,
"type" varchar,
description text,
arcode varchar(20),
license_id varchar(20),
created date,
activated date,
duration interval,
activationkey varchar(32),
"class" varchar,
CONSTRAINT product_pkey PRIMARY KEY (id)
)
WITHOUT OIDS;


option sould be a collection of name > values for a product.
So Product has_many Options.

Here is the Code:
package LicServ::Product;
use base 'LicServ::DBI';
LicServ::Product->table('product');
LicServ::Product->columns(All => qw(id activated created type class
description duration arcode license_id activationkey));
LicServ::Product->has_a(license_id => 'LicServ::License');
LicServ::Product->has_many(options => 'LicServ::Option');

package LicServ::Option;
use base 'LicServ::DBI';
LicServ::Option->table('option');
LicServ::Option->columns(Key => qw(name product_id value));
LicServ::Option->has_a(product_id => 'LicServ::Product');


I get
-----------
LicServ::Option can't SELECT
FROM option
WHERE product_id = ?
: DBD::Pg::st execute failed: FEHLER: Fehler �Syntaxfehler� bei �FROM�
at character 9
[for Statement "SELECT
FROM option
WHERE product_id = ?
" with ParamValues: 1='CBS-1'] at
/usr/share/perl5/DBIx/ContextualFetch.pm line 52.
at /usr/share/perl5/Class/DBI/Relationship/HasMany.pm line 118
-----------
on a foreach my $option ($product->options)

FEHLER: Fehler �Syntaxfehler� bei �FROM� at character 9 -> in English is
ERROR: Error Syntaxerror near FROM at character 9
Strangely Postgres has a german locale. I thought is was running as root
ans so should have none... Howerver. :)

If i type SELECT * FROM option WHERE product_id = 'CBS-1' i get the
correct anser. So i think the problem is that no SELECT _what_ is given.


Any idea how to avoid this problem?

Tank you all

-- 
Tilman Baumann
Software Developer
Collax GmbH . Boetzinger Straße 60 . 79111 Freiburg . Germany

p: +49 (0) 761-4514-836
f: +49 (0) 761-4563-793






More information about the ClassDBI mailing list