There seem to be some amazon items doing wll, title keyword spamming :), like this one. An insert will fail because of this.

Failed to insert item into amazon_item table: Message = SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'title' at row 1, query= INSERT INTO {amazon_item} (asin, salesrank, detailpageurl, lowestpriceamount, lowestpricecurrencycode, lowestpriceformattedprice, amazonpriceamount, amazonpricecurrencycode, amazonpriceformattedprice, binding, brand, label, manufacturer, mpn, productgroup, producttypename, publisher, studio, title, customerreviews_iframe, timestamp) 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, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17, :db_insert_placeholder_18, :db_insert_placeholder_19, :db_insert_placeholder_20) fields=
Array
(
    [asin] => B004GXQOM0
    [salesrank] => 379
    [detailpageurl] => http://www.amazon.de/INSTAR%C2%AE-Kamerapositonen-eingebautem-Lautsprecher-Internetadresse/dp/B004GXQOM0%3FSubscriptionId%3DAKIAIZ3SNFMUDTWUMZ5Q%26tag%3Dwlan-kamera0b-21%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3DB004GXQOM0
    [lowestpriceamount] => 10499
    [lowestpricecurrencycode] => EUR
    [lowestpriceformattedprice] => EUR 104,99
    [amazonpriceamount] => 10499
    [amazonpricecurrencycode] => EUR
    [amazonpriceformattedprice] => EUR 104,99
    [binding] => Misc.
    [brand] => INSTAR®
    [label] => INSTAR Deutschland GmbH
    [manufacturer] => INSTAR Deutschland GmbH
    [mpn] => 10044
    [productgroup] => Home Improvement
    [producttypename] => TOOLS
    [publisher] => INSTAR Deutschland GmbH
    [studio] => INSTAR Deutschland GmbH
    [title] => Original INSTAR® IN-3011 (schwarz) steuerbare Pan Tilt WLAN IP Kamera mit max. 15 festen Kamerapositonen, eingebautem Motor, Mikrofon, Lautsprecher, Alarm IO Ein/Ausgang sowie mit IR Nachtsicht. Ganz neu jetzt mit Internetadresse auf deutschen Servern / Geräusch Erkennung / Cloud Recording Aufnahme in der Cloud / erweiterbar mit Weitwinkel Objektiven und IR Cut Filter / kompatibel mit MAC, Windows, Linux, Android, iOS...
    [customerreviews_iframe] => http://www.amazon.de/reviews/iframe?akid=AKIAIZ3SNFMUDTWUMZ5Q&alinkCode=xm2&asin=B004GXQOM0&atag=wlan-kamera0b-21&exp=2013-03-13T22%3A11%3A52Z&v=2&sig=TmONCaJnGx%2F7%2FXAETOM7bAKFL4CwMkIoNAonJMv5uh4%3D
    [timestamp] => 1363126305
)

Suggested solution

Cutting the title variable:

$db_item['title'] = substr($db_item['title'], 0 ,254);

Adding that after 635 of the amazon.module

$db_item = array_intersect_key($item, $item_keys);
$db_item['title'] = substr($db_item['title'], 0 ,254);
CommentFileSizeAuthor
#2 amazon-1941256-2.patch1.38 KBgrahl

Comments

cuteapoot’s picture

Just a quick note since I was just researching whether Drupal has a specific way of limiting the length of node titles: you should probably use drupal_substr() instead of just substr(). If users are using UTF-8 or some other multibyte text encoding, substr() could return erroneous results because it counts by bytes rather than characters. drupal_substr() calls mb_substr() if it's available, or does some other Drupal Stuff if it's not, and makes sure the result is based off of characters and not bytes.

I may be completely wrong about most of that since I just barely learned that drupal_substr() exists, but I'm sure it's what should be used in this case.

grahl’s picture

StatusFileSize
new1.38 KB

Sadly, title is not the only field affected by this. Attached is a patch which includes all fields from amazon_item from which I am presuming problems can arise, I personally have observed problems with label and manufacturer.

This is a rather ugly patch which puts a band-aid on the problem. Ideally, one should check what Amazon's limitations are and align the database schema with it (I presume putting in everything as 'text' instead of 'varchar' would work but that again is probably not ideal.)

Kiendeleo’s picture

I am getting similar log entries, is this something that is being fixed??

marcoka’s picture

did you read what we wrote here? you can fix it yourself. the module is pretty much not really maintained.

Rhino-new’s picture

Hey all. I had the same issue, but in "brand", so grahl is correct in that it affects more fields, and now I finally know why cron was failing on Amazon :D Was this patch atteched to the dev version of the module?

Failed to insert item into amazon_item table: Message = SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'brand' at row 1, query= INSERT INTO {amazon_item} etc etc etc

xenophyle’s picture

For future reference, there doesn't seem to be a documented size limit for these fields returned by Amazon:
docs.aws.amazon.com/AWSECommerceService/latest/DG/CHAP_response_elements.html

smitty’s picture

I had similar log entries, applied the patch and now the messages seem to be gone. So I also would suggest to commit it.

But I found a similar message for the edition-field, which is not covered by the patch:

Failed to insert item into amazon table: Message = SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'edition' at row 1, query= INSERT INTO {amazon_book} (asin, isbn, ean, edition, numberofpages, publicationdate) 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) fields=

Array
(
  [asin] => 3943413098
  [isbn] => 3943413098
  [ean] => 9783943413090
  [edition] => 1., Wenn Menschen, die zu viel wissen, sterben, dann gibt es eine Geschichte, die es Wert ist, erzählt zu werden.»Die Sonnendiebe« ist so eine Geschichte, und die Mutter der Autorin war eines ihrer Opfer - eine Insiderin, die bei der US-Marine in genau jene Geoengineering-Programme involviert war, die uns heute in weiten Teilen der Welt den Himmel verschleiern.Cara St. Louis-Farrelli hat einen Roman erschaffen, der messerscharf an der Realität entlang schneidet: Fiktion, die Lücken füllt, dort wo das Militär se
  [numberofpages] => 380
  [publicationdate] => 2013-07-15
)

This message is about the amazon_book-table, which is filled by the amazon-media_module. So I inserted the following code in function amazon_media_amazon_item_insert (file: amazon_media.module) between "$db_item = array_intersect_key($item, $item_keys[$table]['fields']);" and "try {":

  if (isset($db_item['edition'])) {
    $db_item['edition'] = drupal_substr($db_item['edition'], 0, 128);
  }

Hope this helps.

smitty’s picture

Same problem with participant in amazon.module

   if (isset($item_participant['participant'])) {
     $item_participant['participant'] = drupal_substr($item_participant['participant'], 0, 128);
   }

By the way: 128 Characters for participant might be a little less for this field. Change the database?