Yii Framework Forum: Relation Search Fail With Oracle - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Relation Search Fail With Oracle Rate Topic: -----

#1 User is offline   because of love 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-June 13

Posted 05 August 2013 - 11:17 PM

I have a File table ,and a Admin table.
and the relation of Admin model is :
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'Admin' => array(self::BELONGS_TO, 'ADMIN', 'ADMIN_ID')
);
}

it means every file is created by a admin.
in my admin table I have a name column beside username and password.

and i want to search file by the administrator's name.

so I follow the step on Searching and sorting by related model in CGridView


it is a great toturial.

but it fail with CDbCommand can not excute SQL statement: SQLSTATE[HY000]: General error: 904 OCIStmtExecute: ORA-00904: "ADMIN"."NAME": Identifier is invalid
(ext\pdo_oci\oci_statement.c:148). The SQL statement executed was: SELECT COUNT(DISTINCT "t"."FILE_ID") FROM "HOUSE_FILE" "t" LEFT OUTER JOIN "HOUSE_ADMIN" "Admin" ON ("t"."ADMIN_ID"="Admin"."ADMIN_ID") WHERE (Admin.NAME LIKE :ycp0)

I think it is caused by the oracle database,
oracle take all table name and table alas name without Double quotes as upper case.

so it take Admin.NAME as ADMIN.NAME , but the Alias is "HOUSE_ADMIN" "Admin" "Admin",
consequently, it said "ADMIN"."NAME": Identifier is invalid.

I know the cause, and I know this issue can be fixed by add double quotes to Admin in Admin.NAME , unfortunately I do not how to add.

If somebody can help me ,I am so gratitude.
0

#2 User is offline   because of love 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 26-June 13

Posted 06 August 2013 - 03:11 AM

Yes ,I find out the solution!
just add these code which render the table name and column name with double quotation in the beginning of CDbCriteria compare function .
$column_split_array = explode('.', $column);



		if(count($column_split_array) > 1)
		{

			foreach ($column_split_array as $key => $column_split) {
			 	$column_split_array[$key] = '"'.$column_split.'"';
			 } 
			$column =  implode('.', $column_split_array);
		}


0

#3 User is offline   wawan_blitar 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 16-September 14

Posted 28 July 2015 - 09:31 PM

I'm so sorry if my bad english... can you show me the complete code in search function please, because I have same problem and I don't know where that code must be placed. I got error message that I don't have $column... help me please...
0

#4 User is offline   ikramadjissa 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 31
  • Joined: 22-June 15

Posted 02 August 2015 - 05:26 PM

In order to avoid oracle problems, try not to use Upper case in your db script (transform them to lower case) by using sql developper.
exemple :
if you have a table called ADMIN rename it "admin". Same thing for the attributs of you table. For exemple if you have USER_NAME in ADMIN table transform it to "user_name". dont forget to use the " ".
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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