سؤال

I am trying to migrate one of my Laravel project to Oracle Database (11g). I installed this package to communicate with the database. Everything seems to working If I write queries, but the automatic query builder makes invalid queries. Like: The registration uses this validation to post:

$validator = Validator::make(Input::all(),array(
            'createInputEmail'          => 'required|email|unique:User,email|max:254',
            'createInputDisplayName'    => 'max:24|min:4|alpha_num',
            'createInputPassword1'      => 'required|max:60',
            'createInputPassword2'      => 'required|same:createInputPassword1'
        ));

The problem here is the unique check. I get this error:

oci_execute(): ORA-00903: invalid table name (SQL: select count(*) as aggregate from User where email = asd@asd.sd) 

If I copy this query to SQL Developer to test and apply quotes to the table name it works. So a correct query:

select count(*) as aggregate from "User" where email = asd@asd.sd;

//dont worry about the unquoted email address

I can't put quotes to the rules when I am defining the validator, because it gets escaped.

I tried:

'required|email|unique:\'User\',email|max:254',
'required|email|unique:\"User\",email|max:254',
'required|email|unique:"User",email|max:254',
'required|email|unique:""User"",email|max:254', <-- the first 2 got escaped, last 2 didn't
'required|email|unique:'User',email|max:254',
هل كانت مفيدة؟

المحلول

That's an interesting case. For most Oracle Developer there's a standard to make all table name plurals (users vs user). That would help you to avoid this issue.

Basically, your problem is not just the quotes, you are using an Oracle Reserverd Words: User. More information about Oracle Reserverd Words here: http://docs.oracle.com/cd/B19306_01/em.102/b40103/app_oracle_reserved_words.htm

If you are the responsible to design the database do the following ASAP:

  1. Avoid using Oracle Reserved Words as table name.
  2. Keep table name as plural, to avoid that particular case.

If the database cannot be altered, you will have to keep looking for a workaround to this issue.


I have a workaround in mind that you need to test it, edit your model User.php and change the table name to include the quotes.

protected $name = '"User"';

I have tested and the quotes appeared in the generated SQL query but it fails to execute because I'm using MySQL and all table name are wrapped with `.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top