Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1: SELECT aip.participant AS participant, aip.asin AS asin
FROM 
{amazon_item_participant} aip
WHERE  (asin IN  ()) ; Array
(
)
in views_handler_field_amazon_participant->pre_render() (line 61 of /home/ospi/public_html/sites/all/modules/amazon/includes/views_handler_field_amazon_participant.inc).

I am getting the above error when trying to include the All Participants field in an View. None of the other fields (that I've tried) are causing any issues.

Comments

rfay’s picture

Status: Active » Postponed (maintainer needs more info)
StatusFileSize
new104.01 KB

I'm unable to recreate this. Have you run update.php? Can you recreate this using the view provided with the Amazon Example feature and adding "all participants" to it? This also could be related to a specific ASIN you're using - perhaps you can figure that out.

Perhaps you could attach an export of the view you're using (or a feature (see Features module), if it's not based on the example view + content type)

Attached is a screenshot of a working view.

gmak’s picture

StatusFileSize
new3.11 KB

Something is strange. I'm also getting the following error when I try to use the Feature Example that comes with the module:

Notice: Undefined index: detailpageurl in views_handler_field->get_value() (line 337...

This error repeats 4 times.

On the 'All Participants' issue, I have a attached a feature dump of the view.

Hope we can figure this out.

rfay’s picture

Status: Postponed (maintainer needs more info) » Active
rfay’s picture

Sorry, you'll have to include the content type in the feature; I can't use this as it is.

If you could also provide at least a few of the ASINs that you're using, that would be useful, since it may be related to the ASIN you're using.

If you want to provide me a database, you can attach the database dump or send it to me or send me a dropbox link - randy at randyfay.com

gmak’s picture

StatusFileSize
new5.42 KB

Sorry. That was the first time I'd ever tried to create a feature.

Attached is the field, content-type, and view.

Here are some of ASIN's I'm using:

0415571936
0631181776
0747597480

The issue happens with all of these.

Thanks

rfay’s picture

StatusFileSize
new65.95 KB

Sorry, your view doesn't have any fields and doesn't have the relationship that would be required.

Could you please start with the Amazon Example view and demonstrate this problem using that? Documentation on how to create a view and the necessary relationships is at http://drupal.org/node/595464

I've attached a screenshot of what your view looks like.

gmak’s picture

StatusFileSize
new20.76 KB
new264.66 KB

There must be something wrong with the way I setup the feature, because my view definitely has fields (see attached).

I'll try with the example as well.

gmak’s picture

Working with the Example View:

1. I add a piece of content using the Amazon Example content type.
2. I visit /amazon_example_view and get: Notice: Undefined index: detailpageurl in views_handler_field->get_value() (line 337 of /home/ospi/public_html/sites/all/modules/views/handlers/views_handler_field.inc)., but the view displays OK.
3. I edit the amazon example view, adding the All Participants field and get the same SQL error at the start of this issue.

rfay’s picture

StatusFileSize
new137.5 KB

Hmm. Well, that's what I did originally, and it worked fine. I just did it again, making sure I had at least one of your examples. See the attached.

Are you using a recent version of views? Have you run update.php? Can you recreate this problem on a fresh install?

gmak’s picture

Amazon - 7.x-1.x-dev
Views - 7.x-3.x-dev

According to both Drupal installation (7.4) and Drush, there are no database updates pending.

gmak’s picture

OK, a bit more.

I've done a clean install of D7.4. I have not enabled any of the core modules other than those that are activated on initial installation. In addition, I have installed:

Amazon 7.x-1.x-dev
Views 7.x-3.x-dev
CTools 7.x-1.0-beta1
Features 7.x-1.0-beta3
Strongarm 7.x-2.0-beta2
Views 7.x-3.x-dev

1. Add Amazon Example content (using ASIN 0631181776)
2. Upon submitting the content creation form, I get Notice: Undefined index: detailpageurl in views_handler_field->get_value() (line 337 of /home/ospi/public_html/testbed/sites/all/modules/views/handlers/views_handler_field.inc).
3. Visiting /amazon_example_view, shows the content.
4. Edit the view, adding the All Participants field, throws the error:
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '))' at line 1: SELECT aip.participant AS participant, aip.asin AS asin FROM {amazon_item_participant} aip WHERE (asin IN ()) ; Array ( ) in views_handler_field_amazon_participant->pre_render() (line 61 of /home/ospi/public_html/testbed/sites/all/modules/amazon/includes/views_handler_field_amazon_participant.inc)

rfay’s picture

Well, send me the database of the clean install you did. See #4.

gmak’s picture

StatusFileSize
new2.83 MB

Here you go.

rfay’s picture

StatusFileSize
new64.03 KB

Installed your database. Added a field to the view. Worked fine. Result is attached.

What version of mysql are you using, and on what platform?

BTW, the detailpageurl thing is something we've spent a lot of time on but haven't successfully nailed. Not related.

rfay’s picture

When you select "All participants", it then gives the option of not showing all participants. At each point I've been just keeping the default "all participants". Is that the same as what you're doing?

gmak’s picture

Mysql Server Version 5.1.49-3
Mysql Client Version 5.1.49
PHP Version 5.3.3-7+squeeze3
OS Debian 6

gmak’s picture

I've not been changing any of the default settings for the All Participants field.

rfay’s picture

Aha! My sandbox hadn't had a views update for awhile. With the views update, I get the error! Yay.

rfay’s picture

This is the code that fails:

  function pre_render($values) {
    $this->field_alias = $this->aliases['asin'];
    $this->items = array();

    $asins = array();
    foreach ($values as $result) {
      $asin = $this->get_value($result);
      if (!empty($asin)) {
        $asins[] = $asin;
      }
    }

    $query = db_select('amazon_item_participant', 'aip')
      ->condition('asin', $asins, 'IN');

    if ($this->options['participant_type'] != '**ALL**') {
      $query = $query->condition('type', $this->options['participant_type']);
    }
    $query->fields('aip', array('participant', 'asin'));

    $results = $query->execute();

    while ($record = $results->fetchAssoc()) {
      $this->items[$record['asin']][] = check_plain($record['participant']);
    }
  }

The reason it fails is that

      $asin = $this->get_value($result);

returns array(0).

So something has shifted again in how Views does these things. I'll ask dereine for the magic incantation.

rfay’s picture

gmak’s picture

What a relief! I was getting to that point where I was beginning to think that I'd got some really obscure, undiagnosable, (and almost certainly silly) configuration issue.

Please let me know when there is a fix.

And, thanks for such rapid assistance!

timb’s picture

I ran into this today also. Glad to see that someone is already on it.

rfay’s picture

Conversation with merlinofchaos:

<merlinofchaos> rfay: Replace $this->get_value() with parent::get_value() -- that's the quick fix.
Oh wait
<merlinofchaos> Add TRUE as a 3rd arg to get_value
<merlinofchaos> $this->get_value($result, NULL, TRUE)
<merlinofchaos> Does basically the same thing.

<merlinofchaos> rfay: So the longer fix is actually that you would serve your userbase well if you updated the list to allow advanced rendering.

<merlinofchaos> To do that, you need to 1) look at the prerender_list handler. To work with advanced rendering, it needs a 'render_item' method. For backward compatibility, we didn't *require* allowing this.
* dmitrig01 (~dmitrig01@drupal.org/user/47566/view) has joined #drupal-views
* dmitrig01 has quit (Client Quit)
<merlinofchaos> Allowing advanced rendering means that rewrites will happen per each item in the list, rather than on the whole set.
<rfay> merlinofchaos, can you point me to an example that does something similar?
<merlinofchaos> rfay: user roles
<merlinofchaos> rfay: What's awesome here is that you'll implement a render_item method that probably is a one liner
<merlinofchaos> And then you'll eliminate some code from your prerender
<merlinofchaos> rfay: And if there's subsidiary data that's not normally available, you can make it available as 'self tokens'
<rfay> OK, cool.
<rfay> "Self tokens"!
<merlinofchaos> rfay: Yeah. What it means is that you fill $this->items with arrays of data, rather than rendered data
<merlinofchaos> And when they rewrite, they can use the tokens that you provide.
<merlinofchaos> So like the user roles one allows the role name and the rid as tokens

<rfay> merlinofchaos, sadly, neither of the quick fixes seems to get me out of hell. The 3-arg get_value() and the parent::get_value() both leave me with the same #fail. 
<merlinofchaos> ...it should absolutely not return an array in that case, though.

Unfortunately, I tried the two quick fixes with no luck.

gmak’s picture

Any news on this one?

rfay’s picture

I haven't gotten back to it, but #23 has the blueprint. Patches are welcome.

cwithout’s picture

I started a patch for this today. So far, I've eliminated the SQL error and am getting the names of the participants appearing in Views. I still have yet to test the tokens things that merlin described.

No more time to work on it today, but I just wanted to post the status so somebody else doesn't waste their time duplicating the work in the mean time. Should be ready tomorrow (unless something comes up that keeps me from it). If the token thing doesn't work, I'll probably post the patch without it, since it doesn't seem to be something necessary but additional functionality that the other field handlers in this module may not have either.

rfay’s picture

Great! You can assign it to yourself in that case... Thanks for your effort!

cwithout’s picture

Assigned: Unassigned » cwithout
Status: Active » Needs review
StatusFileSize
new2.39 KB

Here's the patch to fix the error and show All Participants in views. I think merlin was speaking in general about reducing the code in pre_render, because there's not a lot there. At least not any more than for user roles. I added a conditional check but there was nothing I could see that could be removed.

This also includes the self tokens. I set it to have name and type as self tokens. Technically, I think that could be considered adding a feature, but it's a fairly small change, so I included it with the bug fix. If I need to split it into seperate patches, I can do that.

I didn't find a lot of info on self tokens, but it appears you can use them in the "rewrite results" for the field itself. You cant' use them as tokens in other fields.

rfay’s picture

Wow, it applies, it works on a casual test! Thanks for the great work.

I would appreciate if you'd take the tokens out and add a new feature request that does all the views fields; It doesn't seem to make sense to do it just here right now - I'm sure open to having them everywhere. And, of course, we have an issue open about adding token support back in.

rfay’s picture

And @dereine says it looks fine! So wow, congratulations, and thanks.

cwithout’s picture

No problem, but after further looking over views handlers, I don't think the change for the self tokens would be applicable to any of this module's fields but this one. The only fields that use it in Views are the ones that extend views_handler_field_prerender_list.

Also, it appears Views employs its own token system that's unrelated to the other Token issue, which doesn't affect the views field handler. All the fields currently have functional Views tokens. They don't need any changes.

Do you still want me to open a separate issue for it, since it would only apply to this field?

rfay’s picture

@cristinawithout, if you think this is an appropriate feature addition, and that it only goes with this field, I'm OK with it. Thanks!

cwithout’s picture

Cool. I did a double check and confirmed the only views handlers using self tokens are those extending views_handler_field_prerender_list. So it doesn't apply to the rest of the fields.

For use reference, an example for self tokens would be if you want to not just display the name of the participant, but the participant type (author, actor, etc).

  • Add the field "Amazon: All participants".
  • Under "Rewrite Results", check "Rewrite the output of this field", then enter something like "[participants_all-name]: [participants_all-type]".

For ASIN B004QOB8QG the output for "[participants_all-name]: [participants_all-type]" would look like:

Matt Smith: actor, Karen Gillan: actor

Or setting the rewrite to "[participants_all-name] ([participants_all-type])" would look like:

Matt Smith (actor), Karen Gillan (actor)

rfay’s picture

I am just waiting for one of the users who was bothered by this to test and RTBC it :-)

rfay’s picture

Status: Needs review » Fixed

Committed: b9ce422

Would appreciate if you could document the self-tokens by adding a little note to the documentation page

You are very welcome here. Thanks so much for taking this one on.

If you use Amazon module and would be interested in becoming a comaintainer, please let me know. It's pretty easy to arrange :-)

gmak’s picture

I can confirm that All Participants is now working. Thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.