Oracle oci8 autoincrement primary key problem

Talk about working with different database types

Moderators: ne_moj, zewa, vadimako, ne_moj, zewa, vadimako

fatihakbas
Newbie
Newbie
Posts: 2
Joined: May 6th, '10, 13:45

Oracle oci8 autoincrement primary key problem

Postby fatihakbas » May 6th, '10, 14:58

PHP DataGrid requires autoincrement primary key on tables.
Instead of mysql autoincrement, oracle has sequence. PHP DataGrid Pro version 6.0.7 uses following code to find primary key id
But it is not worked on oracle 10g and as I know, there is no any table as CONTROL.

Line 5004 : if($this->dbHandler->phptype == "oci8"){ $sql .= "(SELECT CONTROL.next_id_operador FROM CONTROL), "; }

Here is my first solution.

Create a simple sequence:
CREATE SEQUENCE yourtable_sequence ;


if($this->dbHandler->phptype == "oci8"){ $sql .= "(SELECT “ .$this->tblName. “_sequence.nextval from dual), "; }

Second and more simple solution.

Create a sequence and put it on table trigger as below :

http://www.lifeaftercoffee.com/2006/02/ ... in-oracle/

comment following sql primary key generation lines from datagrid.class.php

Line 4989 : if($this->dbHandler->phptype == "oci8"){ $sql .= strtoupper($this->primaryKey).", "; }
Line 5004 : if($this->dbHandler->phptype == "oci8"){ $sql .= "(SELECT CONTROL.next_id_operador FROM CONTROL), "; }

administrator
Site Admin
Site Admin
Posts: 5981
Joined: Jan 7th, '09, 23:18
Contact:

Re: Oracle oci8 autoincrement primary key problem

Postby administrator » May 16th, '10, 12:25

Try to replace

Code: Select all

if($this->dbHandler->phptype == "oci8"){ $sql .= "(SELECT CONTROL.next_id_operador FROM CONTROL), "; }


with

Code: Select all

if($this->dbHandler->phptype == "oci8"){ $sql .= "(SELECT ".$this->tblName.".".$this->primaryKey." FROM ".$this->tblName."), "; }


Return to “Databases: different types implementation”