0

I want to do some debugging with a db_insert query. I tried to use the addTag() method, but I got an error:

$query = db_insert('nodes') ->addTag('my query');

PHP Fatal error:  Call to undefined method InsertQuery_mysql::addTag()

Is there a way I can tag this query or otherwise make it available to hook_query_alter?

Edit This query is not giving me the expected results, and I want to know why. To see why, I need to see the query with its values. Looking in the documentation for InsertQuery_mysql, it appears there's no getArguments() method.

Is there any way to see the values that are being inserted?

6
  • According to the API page for the "InsertQuery_mysql" class (api.drupal.org/api/drupal/…) addTag() isn't a method in that class. Commented Aug 20, 2015 at 21:23
  • I want to see the actual SQL statement being sent to the server, in a way similar as to what's shown here: drupal.stackexchange.com/a/51338/1441 . Is there any way to do that?
    – user1359
    Commented Aug 20, 2015 at 21:33
  • Why cant you use solution from link? Just cast $query to string as said in link and print or log. Commented Aug 20, 2015 at 22:49
  • The Devel module should help you troubleshoot your queries. Commented Aug 20, 2015 at 23:55
  • 2
    It would be much easier to just enable mysql query logging...if not, look into Reflection - you can easily get the arguments out of that object
    – Clive
    Commented Aug 21, 2015 at 13:45

1 Answer 1

1

There are the children classes of Query:

  • class DeleteQuery implements QueryConditionInterface
  • class InsertQuery
  • class MergeQuery implements QueryConditionInterface
  • class SelectQuery implements SelectQueryInterface
  • class TruncateQuery
  • class UpdateQuery implements QueryConditionInterface

Only SelectQuery implements addTag method. However, if you realyl are creating query object just there, you wouldn't need a tag anyway. Tags are only useful for hook_query_alter, and you shouldn't need to alter query you just created.


Your best options, as far as I know them, are:

  1. Enable query log in your database
  2. Devel module with it's query display

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.