I managed to print a string using __toString() magic method, but in this string I see placeholders (for conditions params), and it doesn't work as SQL query.
I checked documentation of this object, and also looked in google, but couldn't find a working answer.
Basing on question's comments (thanks @Scuzzy for inspiration) I wrote some simple piece of code to convert
SelectQuery
object:Usage of this code is now simple (if you only have
SelectQuery
object somewhere):I was thinking about extending original
SelectQuery
object, and provide method to get SQL code, but Drupal'sdb_select
function returnsSelectQuery
, so I will have to either changedb_select
function or cast returned object toExportableSelectQuery
.Also this is not probably best solution I could write, but assuming limit of time and purpose it solved my problem just fine.
If you wish to get SQL from for example "EntityFieldQyery", you may use something like this
Add tag to query
Implement hook "query_TAG_alter"
The solution based on Carlos comment