0

I have a node with three fields that I need to concatenate into a single computed field: title, icon, and track. Track is a term reference to a taxonomy term, and icon is a field attached to the taxonomy.

In my computed code, I'm using this:

$tmp = field_get_items('node', $entity, 'field_track_term');
$track_tax = taxonomy_term_load($tmp[0]['tid']);
$field_items = field_get_items('taxonomy_term', $track_tax, 'field_track_icon');
// Get the first item (fields can have multiple items so field_get_items always returns an array)
$first_item = array_shift($field_items);
// Get the URI
$uri = $first_item['uri'];

$icon_vars = array(
   'path' => file_create_url($uri),
   'attributes' => array(
      'class' => array('session_list_track_logo')
   )
);
$icon_img = theme_image($icon_vars);

$sess_num_tmp = field_get_items('node', $entity, 'field_session_number');
$sess_num = $sess_num_tmp[0]['safe_value'];
$sess_title =  $entity->title;

$entity_field[0]['value'] =  $icon_img . " " . $sess_num . " | " . $sess_title;

I've set it to save to the database, field type text, no size limit. What I'm trying to save to the database is a string that looks like this:

<img class="session_list_track_logo" src="http://example.com/sites/default/files/track_icon/shopper_marketing_best_practices.png"
 /> A22 | In-Home Insights that Drive In-Store Purchase Decisions

When I try to save a node, I get the following error:

Notice: Undefined index: safe_value in eval() (line 18 of /home/www/expo/sites/all/modules/contrib/computed_field/computed_field.module(466) : eval()'d code).

PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_computed_label_value' at row 1: INSERT INTO {field_revision_field_computed_label} (entity_type, entity_id, revision_id, bundle, delta, language, field_computed_label_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 163 [:db_insert_placeholder_2] => 163 [:db_insert_placeholder_3] => session [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => | The Path to Purchase Begins At-Home: In-Home Insights that Drive In-Store Purchase Decisions ) in field_sql_storage_field_storage_write() (line 449 of /home/www/expo/modules/field/modules/field_sql_storage/field_sql_storage.module). The website encountered an unexpected error. Please try again later.

(Note that the image string is included in the query shown after the db_insert_placeholder_6 line; I just can't get SO to format it correctly inside a blockquote.)

I'm not too worried about the first part of the error; I'm obviously just not getting at the session number correctly. What I'm unsure of is what's causing the PDOException error. It says the data is too long for the column. I've double-checked in the database, and the column is definitely set to text with no size limit.

So why would the simple string that shows up later in the error be too long to save?

Just out of curiosity, I set the computed code to do nothing but this:

$entity_field[0]['value'] = $entity->title;

I got the same error.

2 Answers 2

0

I encountered a "PDOException: SQLSTATE[22001]" error which kept giving a blank white screen of death error. After some 2 hours or so, I sussed out that the error stemmed from my creating of a Mini Panel and giving the machine name what I thought was reasonable but the SQL DB didn't like it the length. The length I gave was just 5 words with underscores, some 35 characters but it would stop me viewing any of the Admin/blocks. Once I disabled the Mini Panel in question, everything then worked fine.

I hope this helps others not to lose such valuable time in projects.

0

I encountered a similar error on my current project and fixed it by adjusting the size of the related field.

Try using PhpMyAdmin to view the 'field_computed_label_value' table and then select the structure tab. It will list the type as varchar(###) where ### = the character limit for the string.

Try increasing the size of the type for the field value by selecting the 'change' icon for the value row and then adjusting its length.

Remember to back-up before trying this in case it does not solve our problem.

3
  • I tried that, in both the field_data_field_computed_label table and the field_revisions_field_computed_label tables. I no longer get the error, but it still doesn't appear to save anything to the field_computed_label_value column, even though I error_logged the value and it's correct.
    – EmmyS
    Jun 14, 2012 at 22:11
  • And I just tried adding the computed field to the view, just on the off chance that something WAS saved that I couldn't see. It allowed me to add the field, but nothing is showing up in the view - not even the label I created in the view's field config.
    – EmmyS
    Jun 15, 2012 at 14:40
  • The problem in your comments appears to be another question. If you haven't fixed it, go ahead and ask, but include the code that saves it to the database so the full life of the data item is being viewed.
    – Ashlar
    Jun 18, 2012 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.