January 15, 2010, 10:45am
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?
January 15, 2010, 11:45am
I think you’re looking for CDbExpression. It’s usage is described in
January 15, 2010, 11:51am
Maybe like this:
$model->user_id = new CDbExpression('USERS_SEQ.nextval');
But I think sequence+trigger is still efficient
January 15, 2010, 12:24pm
Works as a charm! Thanks. To be honest i was looking for the CDbExpression but had hole in my brain today
When i redirect page after saving it (normal procedure)like this:
it redirects me to url:
so the $model instance took the string as the PK.
i`ll try to find workaround for that
January 15, 2010, 12:56pm
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.
January 15, 2010, 2:26pm
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.
January 17, 2010, 8:51pm
well, yes. I
m also for triggers, although im not oracle master
It`s just a friend of mine, told me, that with larger tables, performance issues can appear.