----------------------------------------
* CRM-19222: Data too long on export including custom field
https://issues.civicrm.org/jira/browse/CRM-19222
switch ($query->_fields[$field]['data_type']) {
case 'String':
- $length = empty($query->_fields[$field]['text_length']) ? 255 : $query->_fields[$field]['text_length'];
+ // May be option labels, which could be up to 512 characters
+ $length = max(512, CRM_Utils_Array::value('text_length', $query->_fields[$field]));
$sqlColumns[$fieldName] = "$fieldName varchar($length)";
break;