Bug on OCI , Oracle Active Record Support on Yii 1.0.5

I'm currently working in a project that use Oracle with Yii. I tried the OCI support on Active Record with Oracle and get some problem to make it working.

1.In CDbCommandBuilder there is a function called createInCondition($table,$columnName,$values,$prefix=null) where in this function there is a looping like this

The '&' character before $value variable make the value of $value changed. I have the primary key on Oracle table with NUMBER(16) data type and this make ActiveRecord can't find the record on database by it's Pk. After I remove the '&' character the Active Record can find the record on database by it's pk.

  1. We can not use the '_' character in createUpdateCommand function as a variable. The current function generate update query that have some variable like _p0,_p1,_p2, The code was like this

… In Oracle the '' character has identified as invalid character every time I try to update my record. So I extend createUpdateCommand function in COciCommandBuilder and remove the '' character and it's work. The code will become like this

Please verify that this is a bug on Yii Oracle Active Record.

Hi tyohan!

Quote

1.In CDbCommandBuilder there is a function called createInCondition($table,$columnName,$values,$prefix=null) where in this function there is a looping like this

The '&' character before $value variable make the value of $value changed. I have the primary key on Oracle table with NUMBER(16) data type and this make ActiveRecord can't find the record on database by it's Pk. After I remove the '&' character the Active Record can find the record on database by it's pk.

I had the same problem once, but now it works. Not sure, but seems a PHP version problem.

Reading PHP manuals, it says that if you use a foreach like foreach($values as &$value) and you alter the $value variable, you'll set the internal pointer of $values. So, $values[0] will not work.

However, remove the & is not a good idea, since the foreach objective is to alter the array. Instead this, copy the array to another array, as below:

This will not affect the original array.

Quote

2. We can not use the '_' character in createUpdateCommand function as a variable. The current function generate update query that have some variable like _p0,_p1,_p2, The code was like this

… In Oracle the '' character has identified as invalid character every time I try to update my record. So I extend createUpdateCommand function in COciCommandBuilder and remove the '' character and it's work. The code will become like this

I haven't understand very well: this happens in any kind of update? I have fields with '_' character and it works fine. Could you give more details?

  1. I guess this is not related with the & usage. It is probably about identifying the PHP type of "NUMBER(16)" column type. Most likely, the typecast() call changes the value to a string while Oracle expects an integer.

  2. I'm not sure about this. Why would underscore in parameter placeholders affect SQL execution?

Oh, Thank you Rick and Qiang for your response.

For the first case I will follow the Qiang solution. I change the typecast function so if it's a integer it will return the value without changed.

For the second case. I'm using Oracle Express that I think was a 10g version on Windows and Zend Community Server for web server. Using the code from CRUD console command, if I have underscore character before the variables in createUpdateCommand function my application will throw error from Oracle like invalid character. But if I remove the underscore my update function will save the record without error. So I think it will be because underscore character.

Just want to comment about Rick's post

Quote

I have fields with '_' character and it works fine

I mean the underscore character on variable. On update query the generated sql will something like this

that’s only an example but I mean it will throw an error because there is underscore character on our variable

Quote

:_p0

That’s strange. Could you create a SQL command with parameter “:P_0” and see if it works?

Hi!

I have the same problem. The underscore at the beginning is a problem for oracle.

I’ve created a SQL command with parameter “:P_0” and it works right.

Thanks. I fixed this. I also fixed the issue about NUMBER (Yii should treat it as integer or double, but there was a bug about this detection).

Thanks Smartin for inform that underscore on the middle can works fine. Thank you also for Qiang for fixed it.