Re: RE: [PEAR] 2 newbie Qs: DB_DataObjects

From: Date: Wed, 15 Jun 2005 18:45:03 +0000
Subject: Re: RE: [PEAR] 2 newbie Qs: DB_DataObjects
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19641@lists.php.net to get a copy of this message
On 6/15/05, C.J. Mackie <cjmackie@princeton.edu> wrote: > Thanks Dan, Justin; Cast does work perfectly: now I just have to persuade > my group to use it. (And Justin, tx for the tip re: 'update()'. I picked > that up from a tutorial, and thought it was required.) > > I'm having trouble, though, reproducing the behavior you both say should > happen on inserts. My table has a primary key ('ID') with no > auto-increment, and a second, unique index on Email. Here's what I'm > finding: > > DB_DataObject::debugLevel(5); > $person = DB_DataObject::Factory('users'); > > $person->FName = "Dummy"; > $person->LName = "User"; > $person->Salutation = "Mr."; > $person->Email = "Dumuser@somewhere.edu"; > $person->Phone = "999.999.9999"; > $person->PostalAddress = "Address"; > $person->Password = md5('dummypass'); > $person->Type = 0; > $person->Active = TRUE; > > $person->fromValue('CreateDate',DB_DataObject_Cast::sql("NOW()")); > $ID = $person->insert(); > > produces: > > Users: Query Error: [db_error: message="DB Error: already exists" code=-5 > mode=return level=notice prefix="" info="INSERT INTO users (Password , Type > , Active , LName , FName , Salutation , Email , Phone , PostalAddress , > CreateDate ) VALUES ('4518bda19425be276817a3b3eeee82b8' , 0 , 1 , 'User' , > 'Dummy' , 'Mr.' , 'Dumuser3@somewhere.edu' , > '999.999.9999' , 'Address' , > '2005-06-15 13:05:17' ) [nativecode=1062 ** Duplicate entry '0' for key > 1]"] > > I can't see any sign that the query even attempts to set ID. The email > address is definitely unique. The query succeeds when I empty the table, but > fails if there is even one record in the table already. Emptying the table > resets the DB_DO internal sequence to '0', which isn't the documented > behavior for PEAR sequences, I believe? Also, the returned value $ID from > insert() is always '1', no matter what the actual value of ID in the table. Is there a tableName_seq table created? If not then the sequence isn't getting created. Sorry I can't really help you further as I haven't used DB sequences myself (I always use auto increment). However I know you can "fix" this by overriding sequenceKey() on the DO that's having troubles and having it return the "correct" values. Nope, I don't know what these are offhand. What order were your keys created in? Perhaps the email key was created before the ID key? Maybe try switching that? > > What am I missing? And is there a really good tutorial I can pick up > somewhere, to get myself up to speed more fully? > -- Justin Patrin

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