diff --git a/system/Commands/Database/ShowTableInfo.php b/system/Commands/Database/ShowTableInfo.php index c5b67407b17b..736c7ab994dd 100644 --- a/system/Commands/Database/ShowTableInfo.php +++ b/system/Commands/Database/ShowTableInfo.php @@ -292,9 +292,12 @@ private function showFieldMetaData(string $tableName): void CLI::table($this->tbody, $thead); } - private function setYesOrNo(bool $fieldValue): string + /** + * @param bool|int|string|null $fieldValue + */ + private function setYesOrNo($fieldValue): string { - if ($fieldValue) { + if ((bool) $fieldValue) { return CLI::color('Yes', 'green'); } diff --git a/system/Database/BaseConnection.php b/system/Database/BaseConnection.php index 6d92965f0b94..eac85ef56d50 100644 --- a/system/Database/BaseConnection.php +++ b/system/Database/BaseConnection.php @@ -1006,10 +1006,10 @@ public function getConnectDuration(int $decimals = 6): string * insert the table prefix (if it exists) in the proper position, and escape only * the correct identifiers. * - * @param array|string $item - * @param bool $prefixSingle Prefix a table name with no segments? - * @param bool $protectIdentifiers Protect table or column names? - * @param bool $fieldExists Supplied $item contains a column name? + * @param array|int|string $item + * @param bool $prefixSingle Prefix a table name with no segments? + * @param bool $protectIdentifiers Protect table or column names? + * @param bool $fieldExists Supplied $item contains a column name? * * @return array|string * @phpstan-return ($item is array ? array : string) @@ -1030,6 +1030,9 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro return $escapedArray; } + // If you pass `['column1', 'column2']`, `$item` will be int because the array keys are int. + $item = (string) $item; + // This is basically a bug fix for queries that use MAX, MIN, etc. // If a parenthesis is found we know that we do not need to // escape the data or add a prefix. There's probably a more graceful diff --git a/system/Database/BaseUtils.php b/system/Database/BaseUtils.php index d26bde154e02..a3d878ad7f3c 100644 --- a/system/Database/BaseUtils.php +++ b/system/Database/BaseUtils.php @@ -212,7 +212,11 @@ public function getCSVFromResult(ResultInterface $query, string $delim = ',', st $line = []; foreach ($row as $item) { - $line[] = $enclosure . str_replace($enclosure, $enclosure . $enclosure, $item ?? '') . $enclosure; + $line[] = $enclosure . str_replace( + $enclosure, + $enclosure . $enclosure, + (string) $item + ) . $enclosure; } $out .= implode($delim, $line) . $newline; @@ -244,7 +248,7 @@ public function getXMLFromResult(ResultInterface $query, array $params = []): st $xml .= $tab . '<' . $element . '>' . $newline; foreach ($row as $key => $val) { - $val = (! empty($val)) ? xml_convert($val) : ''; + $val = (! empty($val)) ? xml_convert((string) $val) : ''; $xml .= $tab . $tab . '<' . $key . '>' . $val . '' . $newline; } diff --git a/system/Database/Postgre/Builder.php b/system/Database/Postgre/Builder.php index e9763089a90f..d4be734b5bb0 100644 --- a/system/Database/Postgre/Builder.php +++ b/system/Database/Postgre/Builder.php @@ -355,11 +355,11 @@ protected function _upsertBatch(string $table, array $keys, array $values): stri // autoincrement identity field must use DEFAULT and not NULL // this could be removed in favour of leaving to developer but does make things easier and function like other DBMS foreach ($constraints as $constraint) { - $key = array_search(trim($constraint, '"'), $fieldNames, true); + $key = array_search(trim((string) $constraint, '"'), $fieldNames, true); if ($key !== false) { foreach ($values as $arrayKey => $value) { - if (strtoupper($value[$key]) === 'NULL') { + if (strtoupper((string) $value[$key]) === 'NULL') { $values[$arrayKey][$key] = 'DEFAULT'; } } diff --git a/system/Database/SQLSRV/Connection.php b/system/Database/SQLSRV/Connection.php index f1a9fb0b433a..9e00329b72ce 100755 --- a/system/Database/SQLSRV/Connection.php +++ b/system/Database/SQLSRV/Connection.php @@ -190,7 +190,7 @@ protected function _escapeString(string $str): string */ public function insertID(): int { - return $this->query('SELECT SCOPE_IDENTITY() AS insert_id')->getRow()->insert_id ?? 0; + return (int) ($this->query('SELECT SCOPE_IDENTITY() AS insert_id')->getRow()->insert_id ?? 0); } /**