CodeIgniter4 icon indicating copy to clipboard operation
CodeIgniter4 copied to clipboard

_processForeignKeys | Identifier name is too long

Open sandrocantagallo opened this issue 3 years ago • 11 comments

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 avatar Aug 31 '21 11:08 sandrocantagallo

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

paulbalandan avatar Sep 02 '21 11:09 paulbalandan

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

cause I can do it?

sandrocantagallo avatar Sep 02 '21 13:09 sandrocantagallo

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.

paulbalandan avatar Sep 02 '21 14:09 paulbalandan

Why more than 64 characters?

kenjis avatar Sep 03 '21 04:09 kenjis

Why more than 64 characters?

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

sandrocantagallo avatar Sep 03 '21 07:09 sandrocantagallo

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

sandrocantagallo avatar Sep 03 '21 07:09 sandrocantagallo

@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.

kenjis avatar Sep 03 '21 08:09 kenjis

Might be related to #5075

najdanovicivan avatar Sep 11 '21 07:09 najdanovicivan

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.

ytetsuro avatar Sep 25 '21 09:09 ytetsuro

Oracle 12.1 is only 30 bytes.

kenjis avatar Sep 25 '21 10:09 kenjis

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 avatar Jan 06 '22 08:01 kenjis