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 untrusted user: Robot
GPG Key ID: 14DECD44E7E1BB95
5 changed files with 77 additions and 12 deletions

View File

@ -14,9 +14,11 @@
abstract Database #Orange { abstract Database #Orange {
# $db # $db
# string $table # string $table
# string $dateFormat
+ __construct() + __construct()
# quote(mixed $value) : mixed # quote(mixed $value) : mixed
# getTable(string $table) : string # getTable(string $table) : string
# getDateFormat() : string
} }
note right of Database::__construct note right of Database::__construct
@ -40,6 +42,13 @@ core component as needed
return: string return: string
end note 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 @enduml
``` ```

View File

@ -38,6 +38,14 @@ abstract class Database
*/ */
protected string $table; protected string $table;
/**
* Date format to return
*
* @var string
* @since 5.0.2
*/
protected string $dateFormat = 'Y-m-d H:i:s';
/** /**
* Constructor * Constructor
* *
@ -62,23 +70,32 @@ abstract class Database
**/ **/
protected function quote($value) 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'; return 'NULL';
} }
if (is_numeric($value)) 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)) if (filter_var($value, FILTER_VALIDATE_INT))
{ {
return (int) $value; return (int) $value;
} }
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
if (filter_var($value, FILTER_VALIDATE_FLOAT))
{ {
return (float) $value; 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'; return $value ? 'TRUE' : 'FALSE';
} }
@ -86,10 +103,10 @@ abstract class Database
// For date and datetime values // For date and datetime values
if ($value instanceof \DateTime) 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); return $this->db->quote($value);
} }
@ -111,5 +128,16 @@ abstract class Database
return $table; 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; protected string $table;
/**
* Date format to return
*
* @var string
* @since 5.0.2
*/
protected string $dateFormat = 'Y-m-d H:i:s';
/** /**
* Constructor * Constructor
* *
@ -37,23 +45,32 @@
**/ **/
protected function quote($value) 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'; return 'NULL';
} }
if (is_numeric($value)) 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)) if (filter_var($value, FILTER_VALIDATE_INT))
{ {
return (int) $value; return (int) $value;
} }
elseif (filter_var($value, FILTER_VALIDATE_FLOAT))
if (filter_var($value, FILTER_VALIDATE_FLOAT))
{ {
return (float) $value; 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'; return $value ? 'TRUE' : 'FALSE';
} }
@ -61,10 +78,10 @@
// For date and datetime values // For date and datetime values
if ($value instanceof \DateTime) 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); return $this->db->quote($value);
} }
@ -86,3 +103,14 @@
return $table; 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) if ($row->getRowIndex() === $targetRow)
{ {
$cellIterator = $row->getCellIterator(); $cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false); $cellIterator->setIterateOnlyExistingCells(true);
foreach ($cellIterator as $cell) foreach ($cellIterator as $cell)
{ {
$headers[$cell->getColumn()] = $cell->getValue(); $headers[$cell->getColumn()] = $cell->getValue();

View File

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