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

Long column names break select query (Oracle) #11577

Open
marcelowzd opened this issue Aug 19, 2024 · 1 comment
Open

Long column names break select query (Oracle) #11577

marcelowzd opened this issue Aug 19, 2024 · 1 comment

Comments

@marcelowzd
Copy link

marcelowzd commented Aug 19, 2024

Bug Report

When using "find" method from symfony in columns with long names, the query built can start with an underscore, which creates an error in oracle database.

I'm currently using Symfony 7.1 with the following composer packages related to doctrine:
"doctrine/dbal": "^3",
"doctrine/doctrine-bundle": "^2.12",
"doctrine/doctrine-migrations-bundle": "^3.3",
"doctrine/orm": "^3.2",

Oracle database version is 12c (12.1.0.2.0)

Summary

It's not possible to retrieve any records from a table/entity where column names are too large.

Current behaviour

While trying to find any record, an error is shown.

How to reproduce

Create a simple entity called "test" with just one field of type string which will be managed by doctrine;
Register a field with the following example:
#[ORM\Column(name: "SN_PERMITE_FECHA_XPT_ANATOMIA", length: 1, options: ["fixed" => true, "default" => "N"])]
private ?string $permiteFechaContaAnatomia = null;
In any controller, insert the repository for this entity and use $repository->bind(id: 1);
After accessing the controller, doctrine will create the following query:
SELECT t0.SN_PERMITE_FECHA_XPT_ANATOMIA AS _PERMITE_FECHA_XPT_ANATOMIA_19 FROM ORIGEM.TEST t0 WHERE t0.ID = ?
The error will be shown.

Doctrine breaks the name of the field at the start (removing the SN) because it will reach the maximum length of the name, but by doing so it leaves the underscore which oracle doesn't support as the start character of an alias. I don't know if this is an oracle only problem though.

I can't rename the column, as the database is already old and the application which uses it is not ours.

I didn't find the set of classes that build the query as of the time i'm opening this issue, but my plan is to either add a double " or check for the underscore as the first character.

@marcelowzd
Copy link
Author

As a workaround, i created a CustomQuoteStrategy and registered it as the default while using Oracle database.
It changes the method getColumnAlias inside DefaultQuoteStrategy to remove the first character if it is an underscore.

while(str_starts_with($columnName, "_")){
$columnName = substr($columnName, 1, strlen($columnName));
}

Not sure if it is an optimal solution though, but i'm registering it here in case it helps in solving the problem because it worked in my case.

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

No branches or pull requests

1 participant