When trying to save changes to the index Fields settings, I keep getting the following error:

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'ourdbname.search_api_db_resource_index_body_summary' doesn't exist: ALTER TABLE search_api_db_resource_index_body_summary CONVERT TO CHARACTER SET 'utf8' COLLATE 'utf8_bin'; Array ( ) in SearchApiDbService->createFieldTable() (line 207 of /var/www/sitename/sites/all/modules/contrib/search_api_db/service.inc).

I believe the error is because the table prefix is not being included? It's missing in the error message, and I would guess that $name needs to be adjusted to include prefixes in the code below (line 207 of service.inc)? I really don't understand this well enough to be sure, but if I manually append the prefix we're using for this database to $name, the errors seem to go away:

switch ($db_driver) {
      case 'mysql':
        db_query("ALTER TABLE {$name} CONVERT TO CHARACTER SET 'utf8' COLLATE 'utf8_bin'")->execute();
        break;
CommentFileSizeAuthor
#1 1976708-search_api_db-1.patch526 byteshefox

Comments

hefox’s picture

Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new526 bytes

It's due to how string replacement with double quoted strings is done. To php, {$name} is what it replaces with $name (it's for more complicated variable like {$name->key} and such)

So need {" . $name . "} or {{$name}}

Putting it as major as it causes fatal errors, though only when using table prefixes.... like when running simpletests!

This module could do with some index simpletests :)

andypost’s picture

Status: Needs review » Reviewed & tested by the community

makes sense

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

OK, I feel stupid now. Thanks a lot for spotting the problem and providing a patch!

Committed.

Status: Fixed » Closed (fixed)

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