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

_processForeignKeys | Identifier name is too long #5046

Closed
sandrocantagallo opened this issue Aug 31, 2021 · 11 comments
Closed

_processForeignKeys | Identifier name is too long #5046

sandrocantagallo opened this issue Aug 31, 2021 · 11 comments
Labels
database Issues or pull requests that affect the database layer

Comments

@sandrocantagallo
Copy link

Describe the bug
using a table name and a fairly long column name exceeds the limit of 64 characters

CodeIgniter 4 version
"codeigniter4/framework": "^4"

vendor\codeigniter4\framework\system\Database\Forge.php

protected function _processForeignKeys

Line: 1298 -> $nameIndex = $table . '_' . $field . '_foreign';

Possible Fix:

$lenght_nameIndex = strlen($nameIndex);

if ($lenght_nameIndex > 64) {
	$character_to_remove = $lenght_nameIndex-64;
	$nameIndex  = substr($nameIndex, $character_to_remove, 64);
}
@sandrocantagallo sandrocantagallo added the bug Verified issues on the current code behavior or pull requests that will fix them label Aug 31, 2021
@paulbalandan
Copy link
Member

In the first place, why would you name your table and/or fields too long?

@sandrocantagallo
Copy link
Author

In the first place, why would you name your table and/or fields too long?

cause I can do it?

@paulbalandan
Copy link
Member

I'm not trying to be rude or something. I'm asking a genuine question. If there exists a limitation of 64 characters then developers should be wary of that and try to limit their wordings of their used DB identifiers.

@kenjis
Copy link
Member

kenjis commented Sep 3, 2021

Why more than 64 characters?

@sandrocantagallo
Copy link
Author

Why more than 64 characters?

Mysql Limit: https://dev.mysql.com/doc/refman/8.0/en/identifier-length.html

@sandrocantagallo
Copy link
Author

I'm not trying to be rude or something. I'm asking a genuine question. If there exists a limitation of 64 characters then developers should be wary of that and try to limit their wordings of their used DB identifiers.

how the name of an index is generated by a method of a framework should check if the generated name is legal and possibly modify it to make it legal.

there are several reasons why the limit can be reached:

  • use of table prefixes chosen by the user.
  • talkative developer

the truth is that the naming of an index is arbitrary regardless of how the table and the field are named

in many frameworks these names are not dynamically generated like on Forge but the developer can choose it.

Maybe that's the right way to go

@kenjis
Copy link
Member

kenjis commented Sep 3, 2021

@sandrocantagallo
We support:

  • MySQL (5.1+) via the MySQLi driver
  • PostgreSQL via the Postgre driver
  • SQLite3 via the SQLite3 driver
  • MSSQL via the SQLSRV driver (version 2005 and above only)

And want to support Oracle #2487, too.

@najdanovicivan
Copy link
Contributor

Might be related to #5075

@kenjis kenjis added the database Issues or pull requests that affect the database layer label Sep 23, 2021
@ytetsuro
Copy link
Contributor

Oracle 12.1 is only 30 characters.
Therefore, if you want to put in a limit of 64 characters or not, I think it is preferable to do it per driver.

@kenjis
Copy link
Member

kenjis commented Sep 25, 2021

Oracle 12.1 is only 30 bytes.

@kenjis kenjis removed the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 6, 2022
@kenjis
Copy link
Member

kenjis commented Jan 6, 2022

This is not a bug.
It is possible to specify an identifier that always exceeds the character limit. Also, in implementations such as how many characters are used from the beginning, there is a possibility that the keys will be duplicated.

#5075 would resolve the issue.

@kenjis kenjis closed this as completed Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Issues or pull requests that affect the database layer
Projects
None yet
Development

No branches or pull requests

5 participants