civicrm/civicrm-core — pull request #1705 by ravishnair (2013-09-27 12:41:03+00:00)
Title: -- fix for CRM-13417

----------------------------------------
* CRM-13417: Dedupe Rule Creation error trapping fails on length selections for substrings of numeric fields or out of range numbers for text fields
http://issues.civicrm.org/jira/browse/CRM-13417

The fatal error that was coming up was
"Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or
the storage engine doesn't support unique prefix keys, 1089".
This is a mysql error that comes up when prefix indexes with a specified length are created for non-string column i.e. column with datatypes date,int,tinyint,etc. So, when user enters length for the fields with these datatypes, mysql error occurs which is because of "the used key part isn't a string" part of the error. The other bug in case of varchar and text datatypes was that when user enters the length greater than the length(CHARACTER_MAXIMUM_LENGTH) of the column, it will generate the same error as above while creating the index. This time the error would be because of "the used length is longer than the key part".

This fix will check for the datatypes of the column. As per http://dev.mysql.com/doc/refman/5.6/en/create-index.html, prefix indexes with length are only supported by datatypes 'char', 'varchar', 'binary', 'varbinary', 'text', 'blob'. So, if user has entered the length and the datatype of the field is not one of these dataTypes, $length would be made equal to NULL. And for the other bug, if user enters a value greater than the length(CHARACTER_MAXIMUM_LENGTH) of the column, $length will be assigned the value equal to 'CHARACTER_MAXIMUM_LENGTH'.