Move current table property from PDOStatement to Database class
- Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1533036354
This commit is contained in:
parent
28185c12fc
commit
ce2abcdbca
|
@ -80,6 +80,8 @@ class Database
|
||||||
protected $dbaDefinition;
|
protected $dbaDefinition;
|
||||||
/** @var ViewDefinition */
|
/** @var ViewDefinition */
|
||||||
protected $viewDefinition;
|
protected $viewDefinition;
|
||||||
|
/** @var string|null */
|
||||||
|
private $currentTable;
|
||||||
|
|
||||||
public function __construct(IManageConfigValues $config, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition)
|
public function __construct(IManageConfigValues $config, DbaDefinition $dbaDefinition, ViewDefinition $viewDefinition)
|
||||||
{
|
{
|
||||||
|
@ -503,7 +505,7 @@ class Database
|
||||||
*/
|
*/
|
||||||
public function p(string $sql)
|
public function p(string $sql)
|
||||||
{
|
{
|
||||||
|
$this->currentTable = null;
|
||||||
$this->profiler->startRecording('database');
|
$this->profiler->startRecording('database');
|
||||||
$stamp1 = microtime(true);
|
$stamp1 = microtime(true);
|
||||||
|
|
||||||
|
@ -973,8 +975,8 @@ class Database
|
||||||
switch ($this->driver) {
|
switch ($this->driver) {
|
||||||
case self::PDO:
|
case self::PDO:
|
||||||
$columns = $stmt->fetch(PDO::FETCH_ASSOC);
|
$columns = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||||
if (!empty($stmt->table) && is_array($columns)) {
|
if (!empty($this->currentTable) && is_array($columns)) {
|
||||||
$columns = $this->castFields($stmt->table, $columns);
|
$columns = $this->castFields($this->currentTable, $columns);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case self::MYSQLI:
|
case self::MYSQLI:
|
||||||
|
@ -1520,8 +1522,8 @@ class Database
|
||||||
|
|
||||||
$result = $this->p($sql, $condition);
|
$result = $this->p($sql, $condition);
|
||||||
|
|
||||||
if (($this->driver == self::PDO) && !empty($result) && is_string($table)) {
|
if ($this->driver == self::PDO && !empty($result)) {
|
||||||
$result->table = $table;
|
$this->currentTable = $table;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|
Loading…
Reference in a new issue