Re: [CDBI] Dealing with non-required primary keys

[prev] [thread] [next] [Date index for 2005/09/04]

From: Rusty Phillips
Subject: Re: [CDBI] Dealing with non-required primary keys
Date: 12:04 on 04 Sep 2005
I'm trying to not require primary keys during insertion, which will work
for all RDBMSs.

If you don't create a sequence (or your Class::DBI subclass doesn't),
then you get this error message when you try to do an insert without
specifying the primary key:
ERROR:  null value in column "columname" violates not-null constraint

Most of the Class::DBI subclasses don't just not insert anything.
Instead, they know the name of the sequence that is autogenerated by the
database, and refer to it in the insert clause...or at least, they know
what it was called when the Class::DBI subclass was created.  This isn't
always the same as the autogenerated sequence name in the current
version of the RDBMS.  Once again, for the reasons I've stated, I'd
rather go with a RDBMS-agnostic solution if it is possible.

On Sun, 2005-09-04 at 06:44 -0500, Peter Speltz wrote:
> On 9/4/05, Rusty Phillips <rustyp@xxxxxxxxx.xxx> wrote:
> 
> > > It seems your solution would be to patch the specific drivers for each
> > > RDBMS you want to use so they work.
> > I guess that's one way.  There's a lot of brokenness in them, though.
> > It also means only using the databases that have Class::DBI drivers and
> > hoping that they continue to work forever.
> >  A database-agnostic way would be to have a way to specify that
> > Class::DBI doesn't have to worry about certain primary keys because the
> > database will take care of it.  
> > In which case, may I suggest a change to Class::DBI to
> > make it possible?  How about allowing this behaviour (ignoring the
> > primary keys during insert) when the "use sequence" command has no
> > arguments?  I'd be happy to implement it and send in a patch.
> > 
> 
> I really don't know that much about the internals of CDBI or its
> subclasses.  However I thought this was exactly what CDBI does. If you
> want CDBI to worry about making the PK, then you set a sequence.
> ($class->sequence($name) ). If your RDBMS does not need you to create
> values for the PK, like Mysql, you  don't  set a sequence and
> Class::DBI won't make a value for that column and instead lets the DB
> do it.  Is this not what happens?
> 
> Are you trying to make one CDBI class that works for all RDBMS's auto
> inc or sequence mechanisms?
> 
> _______________________________________________
> ClassDBI mailing list
> ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
> http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
> 


_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

(message missing)

[CDBI] Dealing with non-required primary keys
Rusty Phillips 01:20 on 04 Sep 2005

RE: [CDBI] Dealing with non-required primary keys
Rusty Phillips 02:39 on 04 Sep 2005

Re: [CDBI] Dealing with non-required primary keys
Peter Speltz 10:17 on 04 Sep 2005

Re: [CDBI] Dealing with non-required primary keys
Rusty Phillips 11:24 on 04 Sep 2005

Re: [CDBI] Dealing with non-required primary keys
Peter Speltz 11:44 on 04 Sep 2005

Re: [CDBI] Dealing with non-required primary keys
Peter Speltz 11:46 on 04 Sep 2005

Re: [CDBI] Dealing with non-required primary keys
Rusty Phillips 12:04 on 04 Sep 2005

Re: [CDBI] Dealing with non-required primary keys
Matt S Trout 12:12 on 04 Sep 2005

Generated at 13:57 on 10 Sep 2005 by mariachi v0.52