Re: DB_DataObject and multiple column primary keys

From: Date: Fri, 04 Feb 2005 06:44:58 +0000
Subject: Re: DB_DataObject and multiple column primary keys
References: 1  Groups: php.pear.general php.pear.general 
Request: Send a blank email to pear-general+get-17373@lists.php.net to get a copy of this message
I ran this on it, update facture set currency='GBP' where id=1; seemed ok. I'm still experimenting with the logic for DBDO on this - when it is sorted I will probably backport it to DataObjects2 (it's need renaming, as a change like this is likely to break existing scripts) AFAIR the principle is * insert() - will only use sequence keys if set to determine return value * update() / delete() / find()=?SELECT? / setFrom() - will use keys if defined (the new generator will drop support for automatically creating key arrays (or it may only make commented out. suggestions..) ... - will fall back to sequenceKeys if no keys defined. If you have a look at the current code for all this, it's horrifically complex, so I want to try and make this as simple (and predicatable as possible in the future..) Regards Alan On Wed, 2005-02-02 at 19:32 +0100, Olivier Guilyardi wrote: > Hi, > > I have the following MySQL table : > > create table facture ( > status enum ('pending','validated') not null, > id int not null auto_increment, > currency char (3) not null, > is_index_synced bit not null, > primary key (status,id), > ); > > As you can see, the primary key is made of several columns : status and id. > That means, for example that there can be two rows with an id of 123, given > that one has a status of 'pending' and the other a status of 'validated'. > > The id field is auto-incrementing. MySQL handles all of that pretty smartly. > I've been thinking a lot about the application design, and using a single > column primary key is much less handy. > > DB_DataObject does not seem to be able to support such keys. Until now > I've been pretty successful hacking around the problem, but with the > update() method it becomes quite dangerous, since DB_DO will > perform : > > UPDATE facture SET ... WHERE id = 123; > > when it should be : > > UPDATE facture SET ... WHERE id = 123 and status = 'pending'; > > Of course, I'm about to overload update(), but I feel like there > may be some situation where my tables could get corrupted. > > Is there any plan to support multiple columns indexes ? > > ref : > http://dev.mysql.com/doc/mysql/en/multiple-column-indexes.html > > -- > og

« previous php.pear.general (#17373) next »