Update 2024-10-16 10:35:01

This commit is contained in:
Robot 2024-10-16 22:35:05 +02:00
parent ab9fb353ba
commit 9eba4b338f
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
5 changed files with 77 additions and 12 deletions

View File

@ -14,9 +14,11 @@
abstract Database #Orange {
# $db
# string $table
# string $dateFormat
+ __construct()
# quote(mixed $value) : mixed
# getTable(string $table) : string
# getDateFormat() : string
}
note right of Database::__construct
@ -39,6 +41,13 @@ core component as needed
since: 3.2.0
return: string
end note
note right of Database::getDateFormat
Get the date format to return in the quote
since: 5.0.2
return: string
end note
@enduml
```

View File

@ -38,6 +38,14 @@ abstract class Database
*/
protected string $table;
/**
* Date format to return
*
* @var string
* @since 5.0.2
*/
protected string $dateFormat = 'Y-m-d H:i:s';
/**
* Constructor
*
@ -62,23 +70,32 @@ abstract class Database
**/
protected function quote($value)
{
if ($value === null) // hmm the null does pose an issue (will keep an eye on this)
if ($value === null)
{
return 'NULL';
}
if (is_numeric($value))
{
// If the value is a numeric string (e.g., "0123"), treat it as a string to preserve the format
if (is_string($value) && ltrim($value, '0') !== $value)
{
return $this->db->quote($value);
}
if (filter_var($value, FILTER_VALIDATE_INT))
{
return (int) $value;
}
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
if (filter_var($value, FILTER_VALIDATE_FLOAT))
{
return (float) $value;
}
}
elseif (is_bool($value)) // not sure if this will work well (but its correct)
// Handle boolean values
if (is_bool($value))
{
return $value ? 'TRUE' : 'FALSE';
}
@ -86,10 +103,10 @@ abstract class Database
// For date and datetime values
if ($value instanceof \DateTime)
{
return $this->db->quote($value->format('Y-m-d H:i:s'));
return $this->db->quote($value->format($this->getDateFormat()));
}
// For other data types, just escape it
// For other types of values, quote as string
return $this->db->quote($value);
}
@ -110,6 +127,17 @@ abstract class Database
}
return $table;
}
/**
* Get the date format to return in the quote
*
* @return string
* @since 5.0.2
**/
protected function getDateFormat(): string
{
return $this->dateFormat;
}
}

View File

@ -13,6 +13,14 @@
*/
protected string $table;
/**
* Date format to return
*
* @var string
* @since 5.0.2
*/
protected string $dateFormat = 'Y-m-d H:i:s';
/**
* Constructor
*
@ -37,23 +45,32 @@
**/
protected function quote($value)
{
if ($value === null) // hmm the null does pose an issue (will keep an eye on this)
if ($value === null)
{
return 'NULL';
}
if (is_numeric($value))
{
// If the value is a numeric string (e.g., "0123"), treat it as a string to preserve the format
if (is_string($value) && ltrim($value, '0') !== $value)
{
return $this->db->quote($value);
}
if (filter_var($value, FILTER_VALIDATE_INT))
{
return (int) $value;
}
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
if (filter_var($value, FILTER_VALIDATE_FLOAT))
{
return (float) $value;
}
}
elseif (is_bool($value)) // not sure if this will work well (but its correct)
// Handle boolean values
if (is_bool($value))
{
return $value ? 'TRUE' : 'FALSE';
}
@ -61,10 +78,10 @@
// For date and datetime values
if ($value instanceof \DateTime)
{
return $this->db->quote($value->format('Y-m-d H:i:s'));
return $this->db->quote($value->format($this->getDateFormat()));
}
// For other data types, just escape it
// For other types of values, quote as string
return $this->db->quote($value);
}
@ -85,4 +102,15 @@
}
return $table;
}
/**
* Get the date format to return in the quote
*
* @return string
* @since 5.0.2
**/
protected function getDateFormat(): string
{
return $this->dateFormat;
}

View File

@ -54,7 +54,7 @@ final class Header
if ($row->getRowIndex() === $targetRow)
{
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
$cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $cell)
{
$headers[$cell->getColumn()] = $cell->getValue();

View File

@ -29,7 +29,7 @@
if ($row->getRowIndex() === $targetRow)
{
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false);
$cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $cell)
{
$headers[$cell->getColumn()] = $cell->getValue();