diff --git a/src/cl.php b/src/cl.php index 1144709..9e25be3 100644 --- a/src/cl.php +++ b/src/cl.php @@ -33,7 +33,9 @@ class cl { */ static final function first(?iterable $iterable, $default=null) { if (is_array($iterable)) { - return $iterable[array_key_first($iterable)]; + $key = array_key_first($iterable); + if ($key === null) return $default; + return $iterable[$key]; } if (is_iterable($iterable)) { foreach ($iterable as $value) { @@ -49,7 +51,9 @@ class cl { */ static final function last(?iterable $iterable, $default=null) { if (is_array($iterable)) { - return $iterable[array_key_last($iterable)]; + $key = array_key_last($iterable); + if ($key === null) return $default; + return $iterable[$key]; } $value = $default; if (is_iterable($iterable)) { diff --git a/src/db/CapacitorChannel.php b/src/db/CapacitorChannel.php index d7846c6..0a38167 100644 --- a/src/db/CapacitorChannel.php +++ b/src/db/CapacitorChannel.php @@ -151,6 +151,7 @@ class CapacitorChannel { return $serial !== null? unserialize($serial): null; } + const SERIAL_DEFINITION = "mediumtext"; const SUM_DEFINITION = "varchar(40)"; final function sum(?string $serial, $value=null): ?string { diff --git a/src/db/CapacitorStorage.php b/src/db/CapacitorStorage.php index 5be8f83..7a2c4d6 100644 --- a/src/db/CapacitorStorage.php +++ b/src/db/CapacitorStorage.php @@ -30,7 +30,7 @@ abstract class CapacitorStorage { const PRIMARY_KEY_DEFINITION = null; const COLUMN_DEFINITIONS = [ - "item__" => "text", + "item__" => CapacitorChannel::SERIAL_DEFINITION, "item__sum_" => CapacitorChannel::SUM_DEFINITION, "created_" => "datetime", "modified_" => "datetime",