Welcome, Guest
Username: Password: Remember me

TOPIC: Install Error - Unique Values In Table - Fails at SQL

Install Error - Unique Values In Table - Fails at SQL 23 Sep 2012 07:03 #3873

  • BTB300
  • BTB300's Avatar
  • Offline
  • Moderator
  • Posts: 415
  • Thank you received: 132
  • Karma: 47
Hi
I have a custom user details table that has two fields (username and email) that are defined as needing to be unique

The error => JInstaller: :Install: Error SQL DB function failed with error number 1071
Specified key was too long; max key length is 1000 bytes

This is not really a J-Cook Issue but its related to MySql Limits and UTF-8 encoding!!!

From my understanding (please correct me if i am wrong) in UTF-8 it takes 3 bytes to store one character this would then explain why the above error is encountered with the following fields defined as unique

`username` VARCHAR(150) + `email` VARCHAR(255) = (150 x 3) + (255 x 3) = 1215 bytes

THE WORKAROUND:
Reduce the allowed length of the unique strings

THE FORMULA
(uniqueStringLength1 x 3) + (uniqueString2Length2 x 3) +( uniqueString3Length3 x 3) + .... >= 1000

I Have confirmed that cook will build without error using the following for unique values for my situation
`username` VARCHAR(78) + `email` VARCHAR(255) = (78 x 3) + (255 x 3) = 999 bytes

As indicated above this is not a cook issue but related to the limits of MySql and UTF-8 Encoding

The reason i placed it in the new tickets is to suggest that the unique value option possibly be handled at the component level (validation for instance) rather than at the database level to allow more than one unique field per table

Regards
BTB300
Last Edit: 23 Sep 2012 07:12 by BTB300.
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Install Error - Unique Values In Table - Fails at SQL 25 Sep 2012 18:06 #3987

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 987
  • Karma: 140
This is a VERY good catch.

Well, the builder cannot reduce anything without asking the user.
All it can do is making a global check before to build.

I am about to create a validator for the builder, which check the integrity of the project before to build.
So, I will include your advice.

Karma +1
Coding is now a piece of cake
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy
Time to create page: 0.077 seconds

Get Started