Wrong SQL patterns in amazon_item_lookup_from_db

I get this error

PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens: SELECT * from {amazon_item} WHERE asin IN (:asins_0141390123, asins_B0050JKPN8, asins_B005KG60V2, asins_0873642481) AND timestamp > :timestamp; Array ( [timestamp] => 1333143603 [asins_0141390123] => 0141390123 [asins_B0050JKPN8] => B0050JKPN8 [asins_B005KG60V2] => B005KG60V2 [asins_0873642481] => 0873642481 ) in amazon_item_lookup_from_db() (line 474 of /var/www/d7/drupal-7.12/sites/all/modules/amazon/amazon.module).

Comments

Anonymous’s picture

StatusFileSize
new241 bytes

The wrong sql patterns used.

Need to be like
amazon.module, line 472
$result = db_query('SELECT * from {amazon_item} WHERE asin IN (:asins) AND timestamp > :timestamp',
array(':asins' => $item_ids, ':timestamp' => $timestamp),
array(':fetch' => PDO::FETCH_ASSOC));

rfay’s picture

Please explain exactly what action you took to get this error. Are you using mysql? What ASIN were you querying?

Of course it seems odd that this is the first report of this unless there's something unusual about your installation.

Is it possible you haven't run update.php, or that your database is somehow damaged?

Anonymous’s picture

I wanted to say that. There is not used the Drupal 7 database posibilities. Yes, It works like in Drupal 6.
But you pass parameters in to query in a wrong way. Keys of parameters should be the same as in the query.
So we shoud use ":" like array(':asins' => .
There is a like "array('asins' => " It is wrong.

rfay’s picture

Status: Active » Postponed (maintainer needs more info)

Again, Please explain exactly what action you took to get this error. Are you using mysql? What ASIN were you querying?

Anonymous’s picture

I hae ported the module amazon_import to D7.
http://drupal.org/node/1437028#comment-5811614
It does not want to work until, I have not fixed it.
amazon_lookup .

rfay’s picture

Well, an actual patch is welcome, but it does seem like this might be an error in your module.

PGreenwald’s picture

StatusFileSize
new18.28 KB
new91.56 KB

Viktor made the module for me. Do you think the module can be changed to work with the amazon module? Right now it only works with the attached version of the amazon module and it gives several notices. It also does not work well with the Amazon Store module.

Thanks for your help.

rfay’s picture

Status: Postponed (maintainer needs more info) » Active

#7: We won't support random forks of Amazon module, sorry.

Anonymous’s picture

StatusFileSize
new74.21 KB

Hello.
I try to work as Drupal professional.
Please, correct me if I am wrong.
-----------------------------------------------------
In my own code I use this.

//We try to check existed items.  
  if ($lookup) {
    $products = amazon_item_lookup($items);
  }

And I receive this.

PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens: SELECT * from {amazon_item} WHERE asin IN (:asins_1590207238, asins_B0007XLNWY) AND timestamp > :timestamp; Array ( [timestamp] => 1334070552 [asins_1590207238] => 1590207238 [asins_B0007XLNWY] => B0007XLNWY ) in amazon_item_lookup_from_db() (line 474 of /var/www/d7/drupal-7.12/sites/all/modules/amazon/amazon.module).

rfay’s picture

Category: bug » support

I guess the question would be what's in $asins.

Since the module would not work in any way if this didn't work... I suspect you have a problem with your code.

Anonymous’s picture

Category: support » bug
StatusFileSize
new635 bytes

I have attached a git patch.

This is your variant.

$timestamp = REQUEST_TIME - variable_get('amazon_refresh_schedule', 86400);
    $result = db_query('SELECT * from {amazon_item} WHERE asin IN (:asins) AND timestamp > :timestamp',
      array('asins' => $item_ids, 'timestamp' => $timestamp),
      array('fetch' => PDO::FETCH_ASSOC));

Make the attention on ":". It does not determine the sql parameter. We can use any pointer to(@ - for an example).

Sorry.

Anonymous’s picture

StatusFileSize
new1.02 KB

I propose to use this construction in this part.
We work under Drupal 7, we need use the db_select.

rfay’s picture

Static queries with db_query() are perfectly acceptable in D7. http://drupal.org/node/310072

Anonymous’s picture

Ok, you are right.
Look over that articles, look how to use parameters right.
Try to find a difference between your code and the snippets in that article.

willvincent’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Active » Fixed

Commit patch from #12 to 7.x-1.x-dev branch.

willvincent’s picture

Caught a couple more that didn't make it in before the 7.x-1.1 release. :(

Here's a patch, and this has also been commit to 7.x-1.x-dev branch.

willvincent’s picture

Status: Fixed » Closed (fixed)