PMCORE-495

This commit is contained in:
Julio Cesar Laura Avendaño
2019-12-24 15:14:24 -04:00
parent 2d37bb8919
commit 35793bb510
2 changed files with 104 additions and 27 deletions

View File

@@ -545,3 +545,34 @@ function updateUserLastLogin($userLog, $keyLastLogin = 'LOG_INIT_DATE')
}
}
/**
* Return raw query with the bindings replaced
*
* @param \Illuminate\Database\Eloquent\Builder $queryObject
* @return string
*/
function toSqlWithBindings(Illuminate\Database\Eloquent\Builder $queryObject) {
// Get some values from the object
$bindings = $queryObject->getBindings();
$originalQuery = $queryObject->toSql();
// If not exist bindings, return the original query
if (empty($bindings)) {
return $originalQuery;
}
// Initializing another variables
$queryParts = explode('?', $originalQuery);
$pdo = $queryObject->getConnection()->getPdo();
$query = '';
// Walking the parts of the query replacing the bindings
foreach ($queryParts as $index => $part) {
if ($index < count($queryParts) - 1) {
$query .= $part . $pdo->quote($bindings[$index]);
}
}
// Return query
return $query;
}