database icon indicating copy to clipboard operation
database copied to clipboard

`Utopia\Database\Adapter::getIntLimit()` is not enforced

Open kodumbeats opened this issue 4 years ago • 1 comments

Each adapter must implement the getIntLimit() method, but it isn't enforced due to how we interpret $size for integer attributes.

In the case of strings, $size is pretty obvious - the length of the string. However, for integers (and before BIGINT), we just set $size = 0, so this check in createAttribute() would never actually prevent PDO from throwing the database exception:

https://github.com/utopia-php/database/blob/af512b7a00cc7c6e30fa03efbc5fd7e77a93e2df/src/Database/Database.php#L433-L437

Options to enforce int limit:

  • Check values for getIntLimit() as a filter when creating/updating documents
  • Get PDO error codes when size is exceeded and throw a custom Utopia\Database exception

kodumbeats avatar Dec 15 '21 21:12 kodumbeats

I think there is another Issue here the size is the length of the coumn , like size 6 = 100000 digits for unsigned value. while getIntLimit refferst to the value of he int not the length...

like string 64 meaning 64 chars length.

fogelito avatar Apr 18 '22 12:04 fogelito