I received the following SQL message when navigating to a view containing a list of the users flagged nodes. Please let me know if you need any further information, I will leave the database untouched for a while.
user warning: Unknown column 'flag_content_fav_bookmark.vbid' in 'field list' query: SELECT DISTINCT(node.nid), photos.nid AS photos_nid, users.name AS users_name, users.uid AS users_uid, flag_content_fav_bookmark.vbid AS flag_content_fav_bookmark_vbid, votingapi_cache_vote_percent_average.value AS votingapi_cache_vote_percent_average_value FROM node node LEFT JOIN flag_content flag_content_fav_bookmark ON node.nid = flag_content_fav_bookmark.content_id AND flag_content_fav_bookmark.fid = '2' INNER JOIN photos photos ON node.nid = photos.nid INNER JOIN users users ON node.uid = users.uid LEFT JOIN votingapi_cache votingapi_cache_vote_percent_average ON node.nid = votingapi_cache_vote_percent_average.content_id AND votingapi_cache_vote_percent_average.content_type = 'node' AND votingapi_cache_vote_percent_average.value_type = 'percent' AND votingapi_cache_vote_percent_average.tag = 'vote' AND votingapi_cache_vote_percent_average.function = 'average' WHERE (flag_content_fav_bookmark.uid IS NOT NULL) AND (flag_content_fav_bookmark.uid = 1) LIMIT 0, 10 in /var/www/drupal/includes/database.mysql.inc on line 172.

Comments

CoolDreamZ’s picture

Title: SQL error after upgrade from 5.x-1.4 » SQL error after migration from views bookmarks 5.x-1.4
mooffie’s picture

flag_content_fav_bookmark.vbid

Views tries to pull-in a "vbid" field. In "Views Bookmark 1.4" there's indeed a "vbid" field: it's the "Bookmark: Ops for Bookmarks" field. CoolDreamZ, do you parhaps remember if you had these "Ops" on your view? ("Ops" are the bookmark/unbookmark links).

This field was later renamed, in "Views Bookmark dev", to "ops".

So you should have first gotten rid of this "vbid" field by upgrading to "Views Bookmark dev", before migrating to Flag. Of course I don't blame you for not doing this ;-)

Hmmm....

Nate, I think there are three options here:

  1. We could release a "Views Bookmark 1.5" and tell people to upgrade to it before migrating to Flag; or:
  2. Since we can't guarantree our migration code doesn't fail, we can give our users general instructions for fixing problems: "If your view generates SQL errors, go to its edit page; Open all fieldsets: if a field/filter didn't migrate correctly you'll see an empty line in stead. Simply delete this field/filter and insert it anew."

    CoolDreamZ, could you try to apply these "general instructions for fixing problems" and report back? (But perhaps Nate would want to ask you some questions first. So it's better to wait a bit.)

    or:

  3. In flag_views_bookmark_update_views() we could rename all "vbid" fields to "ops", by changing:
    foreach ($view->$view_portion as $delta => $individual_piece) {
    

    to:

    foreach ($view->$view_portion as $delta => $individual_piece) {
      if (isset($individual_piece['field']) && $individual_piece['field'] == 'vbid') {
        $view->{$view_portion}[$delta]['field'] = 'ops';
        $view_changed = TRUE;
      }
    

    (code not tested.)

I'm in favor of option #2, the "general instructions". But I also think we should release a "Views Bookmark 1.5".

mooffie’s picture

CoolDreamZ, could you try to apply these "general instructions for fixing problems" and report back? (But perhaps Nate would want to ask you some questions first. So it's better to wait a bit.)

But already you can execute half of these instruction: go to you view's edit page and see if you have 'empty' line(s) in the fields or filters or arguments sections. You should see only one such line: where your "Ops" field used to be. Let me know if that's what you see. Don't yet modify your view.

mooffie’s picture

I have two new ideas:

1. You should be able to export your view. Please do that, paste it to pastebin.com, and paste here the link.

2. You can clone your view and apply the "general instruction" to the clone.

CoolDreamZ’s picture

Thanks for a quick response. Yes, that indeed seems to be the problem. Here is the exported view, I will try the fixes later (this is on my dev site not a live site).

  $view = new stdClass();
  $view->name = 'Favorites';
  $view->description = 'List of my Favorites';
  $view->access = array (
  0 => '2',
);
  $view->view_args_php = '';
  $view->page = TRUE;
  $view->page_title = 'Favorites';
  $view->page_header = '';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = '';
  $view->page_empty_format = '1';
  $view->page_type = 'table';
  $view->url = 'myfavorites';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '10';
  $view->menu = TRUE;
  $view->menu_title = 'Favorites';
  $view->menu_tab = FALSE;
  $view->menu_tab_weight = '0';
  $view->menu_tab_default = FALSE;
  $view->menu_tab_default_parent = NULL;
  $view->menu_tab_default_parent_type = 'tab';
  $view->menu_parent_tab_weight = '0';
  $view->menu_parent_title = '';
  $view->sort = array (
  );
  $view->argument = array (
  );
  $view->field = array (
    array (
      'tablename' => 'photos',
      'field' => 'nid',
      'label' => 'Photo',
      'handler' => 'views_handler_photo_preview',
      'options' => 'small',
    ),
    array (
      'tablename' => 'node',
      'field' => 'view',
      'label' => '',
      'options' => 'Details',
    ),
    array (
      'tablename' => 'users',
      'field' => 'name',
      'label' => 'Created by',
      'sortable' => '1',
    ),
    array (
      'tablename' => 'flag_content_fav_bookmark',
      'field' => 'vbid',
      'label' => 'Remove Favorite',
    ),
    array (
      'tablename' => 'votingapi_cache_vote_percent_average',
      'field' => 'value',
      'label' => 'Rating',
      'handler' => 'fivestar_views_widget_compact_handler',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'flag_content_fav_bookmark',
      'field' => 'uid',
      'operator' => 'IS NOT',
      'options' => '',
      'value' => '***CURRENT_USER***',
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(photos, node, users, flag_content_fav_bookmark, votingapi_cache_vote_percent_average);
  $views[$view->name] = $view;
CoolDreamZ’s picture

Sorry, forgot to use pastebin.com !

CoolDreamZ’s picture

I removed the original field from the view and added the "Flag: Ops for fav bookmark" field instead. I now get a new SQL error:

user warning: Unknown column 'flag_types_.type' in 'field list' query: SELECT DISTINCT(node.nid), photos.nid AS photos_nid, users.name AS users_name, users.uid AS users_uid, flag_types_.type AS flag_types__type, flag_ops_fav_bookmark.uid AS flag_ops_fav_bookmark_ops, votingapi_cache_vote_percent_average.value AS votingapi_cache_vote_percent_average_value FROM node node LEFT JOIN flag_content flag_content_fav_bookmark ON node.nid = flag_content_fav_bookmark.content_id AND flag_content_fav_bookmark.fid INNER JOIN photos photos ON node.nid = photos.nid INNER JOIN users users ON node.uid = users.uid LEFT JOIN flag_content flag_ops_fav_bookmark ON node.nid = flag_ops_fav_bookmark.content_id AND flag_ops_fav_bookmark.fid AND flag_ops_fav_bookmark.uid = '1' LEFT JOIN votingapi_cache votingapi_cache_vote_percent_average ON node.nid = votingapi_cache_vote_percent_average.content_id AND votingapi_cache_vote_percent_average.content_type = 'node' AND votingapi_cache_vote_percent_average.value_type = 'percent' AND votingapi_cache_vote_percent_average.tag = 'vote' AND votingapi_cache_vote_percent_average.function = 'average' WHERE (flag_content_fav_bookmark.uid IS NOT NULL) AND (flag_content_fav_bookmark.uid = 1) LIMIT 0, 10 in /var/www/drupal/includes/database.mysql.inc on line 172.
CoolDreamZ’s picture

I also get the same (new) SQL error if I create the view from scratch (but without re-creating the bookmark/flag type)

mooffie’s picture

array (
'tablename' => 'flag_content_fav_bookmark',
'field' => 'vbid',
'label' => 'Remove Favorite',
),

Yes, so it was the Ops field. I'll probably open a separate issue.

I now get a new SQL error

(I'm investigating this.)

mooffie’s picture

CoolDreamZ,

The short answer: clearing Views' cache will probably solve this problem (there's a 'clear' button at ?q=admin/build/views/tools).

let us know if it doesn't solve your problem.

I also get the same (new) SQL error if I create the view from scratch (but without re-creating the bookmark/flag type)

(I'm cusrious if you meant to say: "It only happens to existing flags. New flags work alright." I assume it's not what you meant to say.)

The long answer:

That's an interesting problem. Your first query in this issue has:

LEFT JOIN flag_content flag_content_fav_bookmark
ON node.nid = flag_content_fav_bookmark.content_id
  AND flag_content_fav_bookmark.fid = '2' 

But your current one has:

LEFT JOIN flag_content flag_content_fav_bookmark
ON node.nid = flag_content_fav_bookmark.content_id
  AND flag_content_fav_bookmark.fid 

The current one is missing the final " = '2'". On the one hand $flag->name is known ('fav_bookmark'), but on the other hand $flag->fid (2) isn't known. That's weird. That's what eventually leads to the 'flag_types_.type' problem as well. I can't think of an explanation for this, and for the meantime I'll assume this is something users of this module aren't likely to encounter. (If the 'clear' button doesn't solve your problem, I'll change my mind.)

mooffie’s picture

It turns out most of what I wrote in comment #2 wasn't correct:

This module *does* know to migrate the Ops pseudo field from VB 1.4. It's just that there was a typo that prevented this migration from hapenning. I fixed this.

mooffie’s picture

Status: Active » Postponed (maintainer needs more info)

So the only problem left here is the "new SQL error" (comment #7). I'm marking this "needs more info": I need to know if the "clear cache" button solves it.

CoolDreamZ’s picture

Status: Postponed (maintainer needs more info) » Active
StatusFileSize
new613 bytes
new35.38 KB

1. Clearing views cache did not solve the problem
2. Error #7 was when I edited the existing view and removed/replaced the flag ops
2. #8 was a new view using the existing flag. I had not tried creating a new flag.

I have now tried creating a new flag and get this SQL error, I also attach a screenshot and HTML dump (tarball) of the {flags} table
user warning: Column count doesn't match value count at row 1 query: INSERT INTO flags (fid, content_type, name, title, flag_short, flag_long, flag_message, unflag_short, unflag_long, unflag_message, roles, global, teaser, node_form) VALUES (3, 'node', 'newflag', 'New Flag', 'flag', 'flag this', 'flagged', 'unflag', 'unflag this', 'unflagged', '2', 0, 'a:3:{s:12:\"show_on_page\";i:1;s:14:\"show_on_teaser\";i:1;s:12:\"show_on_form\";i:0;}') in /var/www/drupal/includes/database.mysql.inc on line 172.

mooffie’s picture

user warning: Column count doesn't match value count at row 1 query

This has been fixed already, here. Sorry for the bother. I've asked Nate about creating a 'dev' release to solve this problem.

===

So we're left with error #7.

Error #7 was when I edited the existing view and removed/replaced the flag ops

1. It doesn't happen on new views?

2. Could you give me the output of the following command?

views_load_cache();
$table_data = _views_get_tables();
print_r( $table_data['flag_content_fav_bookmark'] );

This will tell us exactly how Views sees this table.

(You seem like a 'power user', that's why I feel I can ask you to execute some code. The 'devel' module makes this simple. But it's ok if you can answer only my first question.)

CoolDreamZ’s picture

Q1 -yes, #7 happens on new views (see #8 above)

Q2 - happy to run the PHP code. (Thanks for the "power user" :-) I do have devel installed however, after hunting around, I can't see where to enter/execute the code. I am also running the Eclipse IDE and zend debugger.

mooffie’s picture

I do have devel installed however, after hunting around, I can't see where to enter/execute the code.

Devel has an 'Execute php' block you can enable and put, e.g., in your footer. Go to the the blocks administration page and enable this block there (I don't remember the block's name but it won't be hard to recognize it).

CoolDreamZ’s picture

StatusFileSize
new3.66 KB

Thanks, found the block (was called "Execute PHP"). I have attached the output.

mooffie’s picture

Thanks for the output.

Array
(
    [name] => flag_content
    ...
            [extra] => Array
                (
                    [fid] => 
                )
   ...
   [filters] => Array
        (
            [uid] => Array
                (
                    [name] => Flag: Fav Bookmark
                    ...
                    [fid] => 

That's what I suspected: the 'fid' slots are all empty. It's a mystery, because other properties of the flag, e.g. $flag->title (which is "Fav Bookmark"), do get seen.

Could you please give me the output of the following code?

print_r( flag_views_tables() );
CoolDreamZ’s picture

StatusFileSize
new20.44 KB

I have attached the output requested

mooffie’s picture

Thanks. That new output shows that the problem isn't in Views but in the database.

I have a good guess: the table 'flag_types' doesn't contain the node-types this flag applies to.

Could you please give me the output of "SELECT * FROM flag_types" ? If my guess is correct, we won't see there records whose 'fid' column equals '2'.

CoolDreamZ’s picture

You are correct. There are only three rows:

FID type
1 story
1 forum
3 photo

mooffie’s picture

Status: Active » Fixed

OK, I think we've finished here.

The module could not load flags that weren't associated with some node-type. That caused your problem(s). I fixed that.

You'll now (after downloading the 'dev' version) be able to edit this 'Fav Bookmark' flag: the first thing you should do is to associate it with some node-type(s), because this module can't handle 'orphan' flags.

The next thing you should do is clear Views' cache (there's a 'clear' button at ?q=admin/build/views/tools).

This should fix all your problems. If it doesn't, re-open this issue.

Notes:

  1. You'll have to download the 'dev' version, as it contains the latest fixes. But the server packages it only once in a while (once a day?), so you'll have to wait a few hours (or download via CVS).
  2. I don't know what caused that flag to be saved without associated node-types in the first place. I'll assume it was a problem derived from bugs already fixed.

Thanks a lot for your feedback, you've helped to make the module better.

CoolDreamZ’s picture

All working fine now, thanks :-)
I think the problem with the flag not being associated *may* be because I deleted one of the two node types originally associated with the flag before I migrated, the other node type was still defined.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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