Yii Framework Forum: sequenceName and Oracle - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

sequenceName and Oracle Rate Topic: -----

#1 User is offline   piwer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-April 09

Posted 15 January 2010 - 05:45 AM

Hello,

Is there any other solution of using sequences in Oracle than Sequence + trigger?
afaik this is not efficient, and i would like pass just nextval to my PK like this:
$model->user_id = 'USERS_SEQ.nextval';

This should do. But if i do that, Yii passes a string to Oracle, and of course it throws an error.

I`ve found out that Yii has $sequenceName in db classes, but how to use that? Where to assign it?
0

#2 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 15 January 2010 - 06:45 AM

I think you're looking for CDbExpression. It's usage is described in http://www.yiiframew...creating-record
0

#3 User is offline   ricardograna 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 376
  • Joined: 31-March 09
  • Location:Manaus/AM - Brazil

Posted 15 January 2010 - 06:51 AM

Maybe like this:

$model->user_id = new CDbExpression('USERS_SEQ.nextval');


But I think sequence+trigger is still efficient
Yes, It Is!
0

#4 User is offline   piwer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-April 09

Posted 15 January 2010 - 07:24 AM

View Postricardograna, on 15 January 2010 - 06:51 AM, said:

Maybe like this:

$model->user_id = new CDbExpression('USERS_SEQ.nextval');


But I think sequence+trigger is still efficient

Works as a charm! Thanks. To be honest i was looking for the CDbExpression but had hole in my brain today :-)

but...
When i redirect page after saving it (normal procedure)like this:
$model->attributes=$_POST['vt_cust_m'];
$model->CUST_ID=new CDbExpression('VT_CUST_M_SEQ.nextval');
if($model->save())
	$this->redirect(array('view','id'=>$model->CUST_ID));

it redirects me to url:
http://localhost/vt/index.php?r=vt_cust_m/view&id=VT_CUST_M_SEQ.nextval


so the $model instance took the string as the PK.
i`ll try to find workaround for that :-)
0

#5 User is offline   piwer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-April 09

Posted 15 January 2010 - 07:56 AM

one more thing.. what about $sequenceName? i understand the mechanism is not implemented.. yet ? I read somewhere in Definitive Guide changelog:
Version 1.0.9 September 6, 2009
- Bug: Set sequenceName in Oracle tables to be empty string so that yiic model command generates correct validation rules for PK (Qiang)

some time ago, that if you want to use sequences u must set it .. somewhere, but i cannot find it now. Weird.
0

#6 User is offline   ricardograna 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 376
  • Joined: 31-March 09
  • Location:Manaus/AM - Brazil

Posted 15 January 2010 - 09:26 AM

Probably it will work. I checked schema implementation and I think it will work.


It is not as it wasn't implemented. It could not be automatically implemented, because Oracle doens't allow us to define a explicity connection between Tables and Sequences (as it is in Postgres), so there is no way to automatically catch the corresponding sequence for the table.

Then, I had to set sequenceName to NULL, otherwise, PK rules would not be Ok.



Anyway, I don't like to reference sequence names in my code, then I prefer triggers.
Yes, It Is!
0

#7 User is offline   piwer 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 14
  • Joined: 04-April 09

Posted 17 January 2010 - 03:51 PM

well, yes. I`m also for triggers, although i`m not oracle master :-)
It`s just a friend of mine, told me, that with larger tables, performance issues can appear.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users