Call to undefined function db_result


// this errors - db_result
$count = db_result(db_query("SELECT COUNT(*) FROM {node} WHERE type = '%s'", $type));

// suggestion
$count = db_select('node')->condition('type', $type)->countQuery()->execute()->fetchField();

Fatal error: Call to undefined function _content_tablename() in /sites/all/modules/delete_all/delete_all.module on line 268
_content_tablename($type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE)

Is this something from D6 or a missing module?

Thanks!

Comments

hey_germano’s picture

Status: Active » Needs review
StatusFileSize
new573 bytes

I ran into the same thing, and this fix worked for me. db_result() is from D6 and not a part of D7.

Here's a patch of the change js suggested above.

coderintherye’s picture

Status: Needs review » Needs work

Ok, well I made the one liner change and committed it into dev. Thank you to both..

However, the specified error is coming from the call to _content_tablename in the quick delete function.

I think it needs a fairly complex replacement with something like http://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/functi...

If anyone wants to tackle it, I'll gladly accept patches.

funkeyrandy’s picture

is there any update here? i need to delete >100k nodes daily, and need fast way of doing it (<3h)
even with the above patches, quick delete does not work

thanks!

indydas’s picture

Issue summary: View changes

Still broken in 7x1.1 so it seems?

Fatal error: Call to undefined function db_result() delete_all.module on line 295.

elijah lynn’s picture

@indydas and anyone else with this error. The commit was http://cgit.drupalcode.org/delete_all/commit/?h=7.x-1.x&id=cea4afcd3c617... and was made after 7.x-1.1 and will be in 7.x-1.2. That being said, I applied the patch and am now getting a:

Notice: Undefined variable: type in delete_all_content_confirm_submit() (line 228 of /home/elijah/websites/example.com/docroot/profiles/publisher/modules/contrib/delete_all/delete_all.module).

http://cgit.drupalcode.org/delete_all/log/?h=7.x-1.x

elijah lynn’s picture

I also just downloaded 7.x-1.x-dev and it doesn't work either, same message as above. Definitely needs some love!

elijah lynn’s picture

While we are at it we should add Drush support for the 'quick' command too, I don't see it right now.

travisc’s picture

This module is currently broken for Drupal7. I suggest using VBO if you need to delete a large number of nodes at this time.

tezalsec’s picture

Would have liked some sort of message not to use the quick method on the project page for drupal 7.
Now it just looks like it's all fine and running. While the _content_tablename function isn't working for all 7 versions.
Spend 2 hours working with this module before I stumbled upon this page..

Thanks.

  • cea4afc committed on 8.x-1.x
    Issue #1580428 by js,HEY_GERMANO: proper count query
    
arne_hortell’s picture

delete-all.module, Row 307, still have the problem with _content_tablename

$tables[_content_tablename($type, CONTENT_DB_STORAGE_PER_CONTENT_TYPE)] = $nid_vid;

oxydog’s picture

Guys, I really need this feature to delete +- 7m nodes from a live web site. This was reported 4 years ago, surely someone must have a solution by now? After all, the project does state that it is "Actively Maintained"!

arne_hortell’s picture

As per question above, yes the _content_tablename is a D6 function.

This module seems no longer maintained.
I have tried everything with vbo and bulkdelete and others and its simply not realistic to delete LOTS of nodes.

Someone need to fix this issue in drupal.

arne_hortell’s picture

StatusFileSize
new5.11 KB

Here is the patch that finally solves this issue.

arne_hortell’s picture

Quick info

        $nids = db_select('node', 'n')
                ->fields('n', array('nid'))
                ->fields('n', array('type'))
                ->condition('n.type', $type)
                ->execute()
                ->fetchCol();

        $num_deleted = db_delete('node')
                ->condition('nid', $nids,'IN')
                ->execute();
arne_hortell’s picture

StatusFileSize
new722.43 KB

Sorry, this one is better.

arne_hortell’s picture

arne_hortell’s picture

StatusFileSize
new722.72 KB

Always something...
Now it should be drupal compliant but still faster than normal.

socialnicheguru’s picture

the last patch is a database dump.

hkirsman’s picture

Indeed, the last patch contains lots of other info including database dump @arne_hortell

hkirsman’s picture

Cleaned up the code from last patch

jeremib’s picture

@hkirsman that latest patch isn't working for me. Possible for you to just upload your full php file for drop in replacement?

Thanks!

hkirsman’s picture

Should work. Just did:

git clone --branch 7.x-1.x https://git.drupal.org/project/delete_all.git
cd delete_all
wget https://www.drupal.org/files/issues/delete_all-call_to_undefined_function_db_result-1580428-21.patch
patch -p1 < delete_all-call_to_undefined_function_db_result-1580428-21.patch
ñull’s picture

I followed #23 instructions to test the last patch. I choose to delete the seventy somthing node of one content type, but after clicking the button "Delete all content now" on the confirmation page "Are you sure you wish to delete content?" it does seem to be very quick at all. In fact I don't have the patience to wait that long for a response from a mysql query that only deletes a few nodes. Without response it is hard to tell what is wrong.

hkirsman’s picture

I tested roughly that it takes 10 seconds to delete 1000 nodes with the quick mode and 15 seconds to delete 1000 nodes with the normal mode. Actually I'm not quite sure if the quick is that quick at all, at least with PHP 7.2.

@ñull, I noticed there is this in the code:

        if (module_exists('search')) {
          search_reindex($nid, 'node');
        }

Could you disable that and try again? Other than that, I don't see why it could be so slow.

I went little-bit crazy with this. I would go even further but the scope of this issue is quite small. I fixed as much as I could, made UI more clearer.