No necesita parches ni ganchos.
// Run the view.
$view = views_get_view('frontpage');
$view->set_display('page');
$view->pre_execute();
$view->execute();
/* Magic Below Here */
// Get query from the view.
$query = $view->query->query();
// Format SelectQueryInterface into a string.
$string = (string) $query;
// Replace arguments.
$arguments = $query->arguments();
if (!empty($arguments) && is_array($arguments)) {
foreach ($arguments as $placeholder => &$value) {
if (is_string($value)) {
$value = "'$value'";
}
}
$string = strtr($string, $arguments);
}
// Format the query string for more readable output.
$string = str_replace(array(' {', "\n{"), ' ', $string);
$string = str_replace(array('} ', "}\n"), ' AS ', $string);
$string = str_replace(', ', ",\n ", $string);
$string = str_replace(' AND ', "\n AND ", $string);
$string = str_replace(' ON ', "\n ON ", $string);
$string = str_replace('SELECT ', "SELECT\n ", $string);
$string = str_replace('ORDER BY ', "ORDER BY\n ", $string);
// echo $string;
echo str_replace(' ', ' ', nl2br($string));
Da esto como salida
SELECT
node.sticky AS node_sticky,
node.created AS node_created,
node.nid AS nid,
'frontpage:page' AS view_name
FROM node AS node
WHERE (( (node.promote <> 0)
AND (node.status = 1) ))
ORDER BY
node_sticky DESC,
node_created DESC
LIMIT 10 OFFSET 0