Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors when trying to query tables with lower cased names #743

Open
BARNZ opened this issue Dec 11, 2022 · 2 comments
Open

Errors when trying to query tables with lower cased names #743

BARNZ opened this issue Dec 11, 2022 · 2 comments

Comments

@BARNZ
Copy link

BARNZ commented Dec 11, 2022

Summary of problem or feature request

The database I'm trying to connect to has a table named like this: "vwInt_dimProject". When I try to query this table with the query builder it auto-capitalises the table name resulting in "VWINT_DIMPROJECT" which gives me the following error:

select * from VWINT_DIMPROJECT

ORA-00942: table or view does not exist

Code snippet of problem

Simple model defined like this:

image

I have traced the problem down to this line here:

https://github.com/yajra/laravel-oci8/blob/9.x/src/Oci8/Query/Grammars/OracleGrammar.php#L275

If I comment out this Str::upper statement then everything works fine.

Perhaps we can have a way to disable this line? Or make it respect the PDO::ATTR_CASE setting?

System details

  • Operating System
  • PHP Version: 8.1
  • Laravel Version: 9
  • Laravel-OCI8 Version: 9.2
@yajra
Copy link
Owner

yajra commented Dec 13, 2022

Thank you for reporting, I think this is a valid concern when working with an existing database.

I think PDO::ATTR_CASE is for the column casing and I currently use lowercase, thus making that config contradicts the current setup. Maybe we can add another config for the wrapping?

I will review this further when I got the chance. Please do not hesitate to submit a PR if you can.

@hpacleb
Copy link
Contributor

hpacleb commented Dec 13, 2022

As a temporary workaround I would suggest overriding the getTable method and adding DB::raw to your model.

    public function getTable()
    {
        return DB::raw('"' . ($this->table ?? Str::snake(Str::pluralStudly(class_basename($this)))) . '"');
    }

EDIT: This would only work for table names though, the query builder would still be broken once columns with Natural Case is used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants