[CDBI] Dealing with non-required primary keys

Rusty Phillips rustyp at freeshell.org
Sun Sep 4 13:04:41 BST 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 at freeshell.org> 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 at lists.digitalcraftsmen.net
> http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi
> 





More information about the ClassDBI mailing list