Hi,
In my project I use the following code to get the raw SQL out of a query builder. This worked great in Phalcon 1.3.4 but throws an error in 2.0.0.
<?php
/**
* @param \Phalcon\Mvc\Model\Query\Builder $builder
*/
public function dumpSqlBeforeExecute ( $builder )
{
$db = $this->getDI()->get('db');
$intermediate = $builder->getQuery()->parse();
$sqlVariables = $builder->getQuery()->getBindParams();
$dialect = $db->getDialect();
$sql = $dialect->select($intermediate);
if( is_array( $sqlVariables ) ) {
foreach ( $sqlVariables as $key => $value ) {
if ( !is_numeric( $value ) ) $value = '"' . $value . '"';
$sqlVariables[ ':' . $key ] = $value;
unset( $sqlVariables[ $key ] );
}
$keys = array_keys( $sqlVariables );
$query = str_replace( $keys , $sqlVariables , $sql );
} else {
$query = $sql;
}
return $query
}
The error thrown:
Notice: Undefined index: 0 in phalcon/db/dialect.zep on line 364 in /www/app/myModule/src/MyModule/Service/QueryService.php on line 28
Should I follow another approach to get this result in 2.0.0. or is this a bug (that I should report?)