2008年9月9日星期二

Re: [fw-db] Zend DB Table and Oracle

oops, I didn't notice I replied off list, my bad. 

Yea I have the sequence name setup in the  table class, and I still kept my oracle trigger for the sequence and it's working fine.

On Tue, Sep 9, 2008 at 1:10 AM, mikaelkael <perraud.mickael@orange.fr> wrote:
Oops, sorry.
I make confusion with my own extension of Zend_Db_Table_Abstract which, in case of an Oracle adapter and a $_sequence == true, automatically modify to $_sequence = $table_Name . '_SEQ'
I will not reply before going to bed in the future :-) .
Mickael.

Bill Karwin a écrit :


mikaelkael wrote:
 
You must have a sequence on Oracle if you want retrieve a "SOFTWARE_ID"
like an auto_increment field of MySQL.
My remember is that sequence must be name: $_tableName . '_SEQ'
You don't need to name the Oracle sequence by any convention.

You do need to specify the name of the sequence in your Table class
definition, e.g.:

 class Software extends Zend_Db_Table_Abstract
 {
   protected $_sequence = 'software_id_seq';
 }

That's just an example.  Replace 'software_id_seq' with the name of the
sequence you define in the database to populate the software_id column.

If you don't specify the $_sequence attribute to the name of the sequence,
Zend_Db_Table's default behavior is more like MySQL's AUTO_INCREMENT
functionality.  It assumes it can fetch the last generated id value after
the insert.

But if you use Oracle and you specify the sequence name as a string as shown
above, Zend_Db_Table fetches a new id value from the sequence _before_ the
insert.

Regardless of whether you use MySQL or Oracle, after you call $row->save()
the primary key column in this row should be populated with the generated
value.

Regards,
Bill Karwin
 



没有评论: