Hello!

When I try to visit the newly created index page, I get this error:

user warning: Table 'db.vocabulary' doesn't exist query: SELECT * FROM vocabulary in /public_html/drupal/sites/all/modules/index/includes/index.entity.inc on line 30.

I excluded my database name and the full path if that's ok..

I'm guessing here but maybe this is because I have set a prefix for my database (drupal_) and the module isn't aware of this?

Thanks.

Comments

xano’s picture

Prefixing shouldn't cause any problems. It seems like {vocabulary} really doesn't exist. Do you have Taxonomy.module installed? Index doesn't yet check if data types are actually provided when displaying the index add form, which means you can add terms, vocabularies, comments etc even if Taxonomy or Comment aren't even installed.

jussi’s picture

mysql> show tables;
+-----------------------------------------------+
| Tables_in_db                                  |
+-----------------------------------------------+
...
| drupal_vocabulary                             |
...
+-----------------------------------------------+
81 rows in set (0.02 sec)

Taxonomy is definitely installed and configured. I've got this error on two Drupal installations but maybe this is just a case of me not understanding how Index's interface works. :-) I'll mess with it some more.

xano’s picture

The UI should work without giving you any kind of trouble. If it does, it's a bug in Index.

jussi’s picture

Okay, had a go with differents types of indexes:

Comments: user warning: Table ''db.comments' doesn't exist query: SELECT * FROM comments in [path excluded]/www/drupal-6.16/sites/all/modules/index/includes/index.entity.inc on line 30.

Content: seems to work.

Content types: user warning: Table 'db.node_type' doesn't exist query: SELECT * FROM node_type in [path excluded]/www/drupal-6.16/sites/all/modules/index/includes/index.entity.inc on line 30.

Rules: seems to work.

Terms: seems to work.

Users: seems to work.

Vocabularies: user warning: Table 'db.vocabulary' doesn't exist query: SELECT * FROM vocabulary in [path excluded]/www/drupal-6.16/sites/all/modules/index/includes/index.entity.inc on line 30.

Real puzzling! Luckily I'm not in too much of a trouble here, currently Vocabulary Index does its job "good enough" for me. I was curious if the same could be achieved with Index while also possibly fixing couple of anooyances.

xano’s picture

Status: Active » Postponed (maintainer needs more info)

Can you provide setp-by-step instructions on how to reproduce these errors using a clean installation of Drupal 6.x-dev and Index 6.x-1.x-dev?

esteewhy’s picture

Hello.

The root cause of this (mis)behaviour is because at ./includes/index.entity.inc:74 variable $table is enclosed in a curly braces within a double-quotes, so, under PHP rules, curly braces are interpreted as a part of variable-expansion syntax, thus are not present in the final string. In turn, this leads to ignoring table prefix entirely.

The fix is to escape curly braces by doubling them (id est: "SELECT * FROM {{$table}}"). This is trivial, so no patch, sorry.

BTW, the same pattern (variable within a single curly braces within a double quotes) is repeating several more times, so beware.

esteewhy’s picture

..Also, function index_entity_count_node() contains a bug, which leads to incorrect query if "tid" were passed as a key. One can easily spot this just inspecting the code: there'll be something like:

SELECT COUNT(*) as count, n.tid as value FROM {node} n ...  GROUP BY n.tid

which, of course, is incorrect (trying to get "tid" from a {node} table).

The fix is not a rocket science, here's a possible refactured code (sorry, too lazy for patching):

function index_entity_count_node(index $index, $key, array $values) {
  $table = 'n';
  $counts = array();
  
  $query_join = '';
  
  // Get nodes by TID.
  if ($key == 'tid') {
    $query_join = ' LEFT JOIN {term_node} tn ON tn.vid = n.vid';
    $table = 'tn';
  }
  
  $query = "SELECT COUNT(*) as count, $table.$key as value FROM {node} n";
  $query .= $query_join;

  $conditions = array($key => $values);
  if ($index->language() != INDEX_LANGUAGE_NEUTRAL) {
    $conditions['language'] = array($index->language());
  }
  $result = db_query($query . index_entity_query_conditions($conditions, $table) . " GROUP BY $table.$key");
  while ($count_data = db_fetch_array($result)) {
    $counts[$count_data['value']] = $count_data['count'];
  }

  return $counts;
}