"Could not obtain last nid."

I'm getting this message when trying to build main index 1 after defining specific content types in module settings. After looking on the code I found that string in sphinxsearch.module:

$condition .= ' = \'%s\'';

without any t(....) after that or smth.

Attaching a patch with fix for this.

Comments

markus_petrux’s picture

t() is not reqyured here because it's a literal to build a SQL statement.

$condition .= ' = \'%s\'';

Is equivalent to:

$condition .= " = '%s'";

Which is a fault on my side for not following Drupal conding standards here, but the statement should work. You would get a PHP error if that was not the case.

Theorically, the error "Could not obtain last nid." would mean that you don't have any node with enabled content types in your site. Is that possible?

Can you see any other error in the watchdog next to this one?

markus_petrux’s picture

Status: Needs review » Postponed (maintainer needs more info)
markus_petrux’s picture

Anther thing you could try is passing an explicit value for last_nid when invoking the XMLPipe command. See docs/README-XMLPIPE.txt for examples.

valcker’s picture

StatusFileSize
new853 bytes

The problem is not in following drupal standards, but in replacing %s with content type. For example, if I've chosen only one content type 'article', the following condition will be true:

if (count($enabled_node_types) == 1) {

So, if we will print out sql query on line 91(sphinxsearch.xmlpipe.in), we will see something like that:

'SELECT nid FROM {node} WHERE status = 1 AND type='%s' ORDER BY nid DESC LIMIT 1'

'%s' was not replaced by content type name.

Yes, my patch is not good, because basically, we can replace the whole:

if (count($enabled_node_types) == 1) {
  $condition .= t('= "!type"', array('!type' => $enabled_node_types[0]));
}
else {
  $types = array();
  foreach ($enabled_node_types as $type) {
    $types[] = "'". db_escape_string($type) ."'";
  }
   $condition .= 'IN ('. implode(', ', $types) .')';
}

with just:

$types = array();
foreach ($enabled_node_types as $type) {
  $types[] = "'". db_escape_string($type) ."'";
}
$condition .= 'IN ('. implode(', ', $types) .')';

Even if there is only 1 item in node_types array, we will get next sql code: 'IN ('article',)', which is just fine.

Tell me if I'm wrong, but I just can't find a place were you replace '%s' with real value.

markus_petrux’s picture

StatusFileSize
new506 bytes

Oh, I see.

Even if there is only 1 item in node_types array, we will get next sql code: 'IN ('article',)', which is just fine.

I tend to use this kind of optimization since I have sometimes found RDMS that work differently with IN() conditions. It doesn't add too much clutter to the code, so I would prefer to keep the original form.

I'm attaching a new patch as I will commit to CVS. I'll do that when I have the time since I'll be adding a new parameter for tagadelic blocks to select the method to build URLs, so tag clouds can link to taxonomy related pages, or to start a new search dialog with predefined filters for each term in the cloud. This will affect tagadelic/faceted search funcion arguments.

Thanks for the report :)

valcker’s picture

Agree, leaving only one "IN()" is too much. Thanks for reaction and for the module :)

markus_petrux’s picture

Status: Postponed (maintainer needs more info) » Reviewed & tested by the community

You're welcome.

I expect to have some time later today, and it will probably ends in me releasing 5.x-1.1 with the above mentioned changes.

markus_petrux’s picture

Status: Reviewed & tested by the community » Fixed

There we go. This fix has been included in 5.x-1.1, along a few changes/additions.

http://drupal.org/cvs?commit=137641

markus_petrux’s picture

Status: Fixed » Closed (fixed)