Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paola ruby patch row #1

Merged
merged 2 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Illuminate/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ protected function run($query, $bindings, Closure $callback)
// then log the query, bindings, and execution time so we will report them on
// the event that the developer needs them. We'll log time in milliseconds.
$this->logQuery(
$query, $bindings, $this->getElapsedTime($start)
$query, $bindings, $this->getElapsedTime($start), $this->getRowCount($result)
);

return $result;
Expand Down Expand Up @@ -821,16 +821,17 @@ protected function isUniqueConstraintError(Exception $exception)
* @param string $query
* @param array $bindings
* @param float|null $time
* @param int|null $count
* @return void
*/
public function logQuery($query, $bindings, $time = null)
public function logQuery($query, $bindings, $time = null, $count = null)
{
$this->totalQueryDuration += $time ?? 0.0;

$this->event(new QueryExecuted($query, $bindings, $time, $this));
$this->event(new QueryExecuted($query, $bindings, $time, $this, $count));

if ($this->loggingQueries) {
$this->queryLog[] = compact('query', 'bindings', 'time');
$this->queryLog[] = compact('query', 'bindings', 'time', 'count');
}
}

Expand All @@ -845,6 +846,17 @@ protected function getElapsedTime($start)
return round((microtime(true) - $start) * 1000, 2);
}

/**
* Get the affected row count.
*
* @param mixed $result
* @return int|null
*/
protected function getRowCount($result)
{
return is_array($result) ? count($result) : (is_int($result) ? $result : null);
}

/**
* Register a callback to be invoked when the connection queries for longer than a given amount of time.
*
Expand Down
11 changes: 10 additions & 1 deletion src/Illuminate/Database/Events/QueryExecuted.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,30 @@ class QueryExecuted
*/
public $connectionName;

/**
* The affected row count.
*
* @var int
*/
public $count;

/**
* Create a new event instance.
*
* @param string $sql
* @param array $bindings
* @param float|null $time
* @param \Illuminate\Database\Connection $connection
* @param int|null $count
* @return void
*/
public function __construct($sql, $bindings, $time, $connection)
public function __construct($sql, $bindings, $time, $connection, $count)
{
$this->sql = $sql;
$this->time = $time;
$this->bindings = $bindings;
$this->connection = $connection;
$this->connectionName = $connection->getName();
$this->count = $count;
}
}