Skip to content

Commit 2076d3b

Browse files
committed
Replace Grammar::getConnectionCount with compileConnectionCount
1 parent d41e33c commit 2076d3b

File tree

5 files changed

+11
-27
lines changed

5 files changed

+11
-27
lines changed

src/Illuminate/Database/Console/DatabaseInspectionCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ protected function getConnectionName(ConnectionInterface $connection, $database)
4343
*/
4444
protected function getConnectionCount(ConnectionInterface $connection)
4545
{
46-
return $connection->getQueryGrammar()->getConnectionCount();
46+
$query = $connection->getSchemaGrammar()->compileConnectionCount();
47+
48+
return $query ? $connection->scalar($query) : null;
4749
}
4850

4951
/**

src/Illuminate/Database/Query/Grammars/Grammar.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,9 +1568,9 @@ public function getBitwiseOperators()
15681568
/**
15691569
* Get the number of open connections for a database.
15701570
*
1571-
* @return int|null
1571+
* @return string|null
15721572
*/
1573-
public function getConnectionCount(): ?int
1573+
public function compileConnectionCount()
15741574
{
15751575
return null;
15761576
}

src/Illuminate/Database/Query/Grammars/MySqlGrammar.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -515,14 +515,8 @@ protected function wrapJsonBooleanSelector($value)
515515
return 'json_extract('.$field.$path.')';
516516
}
517517

518-
public function getConnectionCount(): ?int
518+
public function compileConnectionCount()
519519
{
520-
$result = $this->connection->selectOne('show status where variable_name = "threads_connected"');
521-
522-
if (! $result) {
523-
return null;
524-
}
525-
526-
return (int) $result['Value'];
520+
return 'show status where variable_name = "threads_connected"';
527521
}
528522
}

src/Illuminate/Database/Query/Grammars/PostgresGrammar.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -763,14 +763,8 @@ public function substituteBindingsIntoRawSql($sql, $bindings)
763763
return $query;
764764
}
765765

766-
public function getConnectionCount(): ?int
766+
public function compileConnectionCount()
767767
{
768-
$result = $this->connection->selectOne('select count(*) as "Value" from pg_stat_activity');
769-
770-
if (! $result) {
771-
return null;
772-
}
773-
774-
return (int) $result['Value'];
768+
return 'select count(*) as "Value" from pg_stat_activity';
775769
}
776770
}

src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -572,14 +572,8 @@ protected function wrapTableValuedFunction($table)
572572
return $table;
573573
}
574574

575-
public function getConnectionCount(): ?int
575+
public function compileConnectionCount()
576576
{
577-
$result = $this->connection->selectOne('select count(*) Value from sys.dm_exec_sessions where status = ?', ['running']);
578-
579-
if (! $result) {
580-
return null;
581-
}
582-
583-
return (int) $result['Value'];
577+
return 'select count(*) Value from sys.dm_exec_sessions where status = "running"';
584578
}
585579
}

0 commit comments

Comments
 (0)