I am trying to fetch the views preview SQL query. I could get the query and convert it into string. But it couldn't be executed directly on MySQL directly. The following is the code.

function step_views_pre_execute(\Drupal\views\ViewExecutable $view) {
  if ($view->id() == 'feedback') {
    $query = (string)$view->build_info['query'];
    echo $query;
  }
}

The result query is given below
SELECT node_field_data.created AS node_field_data_created, node_field_data.nid AS nid FROM {node_field_data} node_field_data WHERE (node_field_data.status = :db_condition_placeholder_0) AND (node_field_data.type IN (:db_condition_placeholder_1)) ORDER BY node_field_data_created DESC

The

:db_condition_placeholder_1

is not recognized and for some other views table name inside

{ }

such as {node_field_data} is also not recognized in MySQL query executor directly.

How can I overcome this?

Comments