Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e59b63791 | ||
|
|
9c7b3cea83 | ||
|
|
26af6a07f4 | ||
|
|
b7c6d4b478 | ||
|
|
9936fc04da | ||
|
|
1e0dfa2106 | ||
|
|
3af6f6a8f0 | ||
|
|
1e793c0d16 |
@@ -4,7 +4,7 @@ CREATE OR REPLACE FUNCTION set_edit_generic()
|
|||||||
RETURNS TRIGGER AS
|
RETURNS TRIGGER AS
|
||||||
$$
|
$$
|
||||||
DECLARE
|
DECLARE
|
||||||
random_length INT = 12; -- that should be long enough
|
random_length INT = 25; -- that should be long enough
|
||||||
BEGIN
|
BEGIN
|
||||||
IF TG_OP = 'INSERT' THEN
|
IF TG_OP = 'INSERT' THEN
|
||||||
NEW.date_created := 'now';
|
NEW.date_created := 'now';
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ use PHPUnit\Framework\TestCase;
|
|||||||
*/
|
*/
|
||||||
final class CoreLibsConvertByteTest extends TestCase
|
final class CoreLibsConvertByteTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -24,7 +23,31 @@ final class CoreLibsConvertByteTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function byteProvider(): array
|
public function byteProvider(): array
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* 0: input string
|
||||||
|
* 1: default flags
|
||||||
|
* 2: BYTE_FORMAT_SI
|
||||||
|
* 3: BYTE_FORMAT_NOSPACE
|
||||||
|
* 4: BYTE_FORMAT_ADJUST
|
||||||
|
* 5: BYTE_FORMAT_SI | BYTE_FORMAT_NOSPACE
|
||||||
|
*/
|
||||||
return [
|
return [
|
||||||
|
'string number' => [
|
||||||
|
0 => '1024',
|
||||||
|
1 => '1 KB',
|
||||||
|
2 => '1.02 KiB',
|
||||||
|
3 => '1KB',
|
||||||
|
4 => '1.00 KB',
|
||||||
|
5 => '1.02KiB',
|
||||||
|
],
|
||||||
|
'invalud string number' => [
|
||||||
|
0 => '1024 MB',
|
||||||
|
1 => '1024 MB',
|
||||||
|
2 => '1024 MB',
|
||||||
|
3 => '1024 MB',
|
||||||
|
4 => '1024 MB',
|
||||||
|
5 => '1024 MB',
|
||||||
|
],
|
||||||
'negative number' => [
|
'negative number' => [
|
||||||
0 => -123123123,
|
0 => -123123123,
|
||||||
1 => '-117.42 MB',
|
1 => '-117.42 MB',
|
||||||
|
|||||||
@@ -113,7 +113,10 @@ final class CoreLibsCreateEmailTest extends TestCase
|
|||||||
'日本語カタカナパ',
|
'日本語カタカナパ',
|
||||||
'ISO-2022-JP',
|
'ISO-2022-JP',
|
||||||
true,
|
true,
|
||||||
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8=?=" <test@test.com>'
|
// was ok php 8.1
|
||||||
|
// '"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8=?=" <test@test.com>'
|
||||||
|
// below ok php 8.1.12, 2022/12/9
|
||||||
|
'"=?ISO-2022-JP?B?GyRCRnxLXDhsGyhCPz8/Pz8/?=" <test@test.com>'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -124,6 +127,11 @@ final class CoreLibsCreateEmailTest extends TestCase
|
|||||||
* @dataProvider encodeEmailNameProvider
|
* @dataProvider encodeEmailNameProvider
|
||||||
* @testdox encode email $email, name $name, encoding $encoding, folding $kv_folding will be $expected [$_dataName]
|
* @testdox encode email $email, name $name, encoding $encoding, folding $kv_folding will be $expected [$_dataName]
|
||||||
*
|
*
|
||||||
|
* @param string $email
|
||||||
|
* @param string|null $name
|
||||||
|
* @param string|null $encoding
|
||||||
|
* @param bool|null $kv_folding
|
||||||
|
* @param string $expected
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testEncodeEmailName(
|
public function testEncodeEmailName(
|
||||||
|
|||||||
@@ -1189,7 +1189,13 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$expected,
|
$expected,
|
||||||
$db->dbEscapeBytea($input)
|
$db->dbEscapeBytea($input),
|
||||||
|
'Assert error to bytea'
|
||||||
|
);
|
||||||
|
$this->assertEquals(
|
||||||
|
$input,
|
||||||
|
$db->dbUnescapeBytea($expected),
|
||||||
|
'Assert error from bytes'
|
||||||
);
|
);
|
||||||
|
|
||||||
$db->dbClose();
|
$db->dbClose();
|
||||||
|
|||||||
@@ -50,21 +50,22 @@ print '<div><h1>' . $PAGE_NAME . '</h1></div>';
|
|||||||
$byte = 254779258;
|
$byte = 254779258;
|
||||||
$string = '242.98 MB';
|
$string = '242.98 MB';
|
||||||
// static
|
// static
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
|
print "S::BYTE TO (calls as var): $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
|
||||||
print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
||||||
|
print "S::BYTE FROM: $string: " . Byte::stringByteFormat($string) . "<br>";
|
||||||
//
|
//
|
||||||
$byte = 314572800;
|
$byte = 314572800;
|
||||||
$string = '300 MB';
|
$string = '300 MB';
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_SI) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST) . "<br>";
|
||||||
print "S::BYTE TO: $byte: "
|
print "S::BYTE TO: $byte: "
|
||||||
. $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST | Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
. Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_ADJUST | Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
||||||
print "S::BYTE TO: $byte: " . $byte_class::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
print "S::BYTE TO: $byte: " . Byte::humanReadableByteFormat($byte, Byte::BYTE_FORMAT_NOSPACE) . "<br>";
|
||||||
print "S::BYTE FROM: $string: " . $byte_class::stringByteFormat($string) . "<br>";
|
print "S::BYTE FROM: $string: " . Byte::stringByteFormat($string) . "<br>";
|
||||||
|
|
||||||
// *** BYTES TEST ***
|
// *** BYTES TEST ***
|
||||||
$bytes = [
|
$bytes = [
|
||||||
|
|||||||
@@ -112,10 +112,11 @@ if (defined('LAYOUT')) {
|
|||||||
}
|
}
|
||||||
// set table width
|
// set table width
|
||||||
$table_width = '100%';
|
$table_width = '100%';
|
||||||
|
$ADMIN_STYLESHEET = 'edit.css';
|
||||||
// define all needed smarty stuff for the general HTML/page building
|
// define all needed smarty stuff for the general HTML/page building
|
||||||
$HEADER['CSS'] = CSS;
|
$HEADER['CSS'] = CSS;
|
||||||
$HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
$HEADER['DEFAULT_ENCODING'] = DEFAULT_ENCODING;
|
||||||
|
/** @phpstan-ignore-next-line because ADMIN_STYLESHEET can be null */
|
||||||
$HEADER['STYLESHEET'] = $ADMIN_STYLESHEET ?? ADMIN_STYLESHEET;
|
$HEADER['STYLESHEET'] = $ADMIN_STYLESHEET ?? ADMIN_STYLESHEET;
|
||||||
|
|
||||||
if ($form->my_page_name == 'edit_order') {
|
if ($form->my_page_name == 'edit_order') {
|
||||||
|
|||||||
@@ -26,13 +26,16 @@ class Byte
|
|||||||
* Source Idea: SOURCE: https://programming.guide/worlds-most-copied-so-snippet.html
|
* Source Idea: SOURCE: https://programming.guide/worlds-most-copied-so-snippet.html
|
||||||
*
|
*
|
||||||
* The class itself hast the following defined
|
* The class itself hast the following defined
|
||||||
* BYTE_FORMAT_NOSPACE [1] turn off spaces between number and extension
|
* BYTE_FORMAT_NOSPACE [1] turn off spaces between number and suffix
|
||||||
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
|
* BYTE_FORMAT_ADJUST [2] use sprintf to always print two decimals
|
||||||
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
|
* BYTE_FORMAT_SI [3] use si standard 1000 instead of bytes 1024
|
||||||
* To use the constant from outside use class::CONSTANT
|
* To use the constant from outside use class::CONSTANT
|
||||||
*
|
*
|
||||||
* @param string|int|float $bytes bytes as string int or pure int
|
* @param string|int|float $bytes bytes as string int or pure int
|
||||||
* @param int $flags bitwise flag with use space turned on
|
* @param int $flags bitwise flag with use space turned on
|
||||||
|
* BYTE_FORMAT_NOSPACE: no space between number and suffix
|
||||||
|
* BYTE_FORMAT_ADJUST: sprintf adjusted two 2 decimals
|
||||||
|
* BYTE_FORMAT_SI: use 1000 instead of 1024
|
||||||
* @return string converted byte number (float) with suffix
|
* @return string converted byte number (float) with suffix
|
||||||
*/
|
*/
|
||||||
public static function humanReadableByteFormat($bytes, int $flags = 0): string
|
public static function humanReadableByteFormat($bytes, int $flags = 0): string
|
||||||
@@ -62,7 +65,7 @@ class Byte
|
|||||||
// si or normal
|
// si or normal
|
||||||
$unit = $si ? 1000 : 1024;
|
$unit = $si ? 1000 : 1024;
|
||||||
// always positive
|
// always positive
|
||||||
$abs_bytes = $bytes == PHP_INT_MIN ? PHP_INT_MAX : abs($bytes);
|
$abs_bytes = $bytes == PHP_INT_MIN ? PHP_INT_MAX : abs((float)$bytes);
|
||||||
// smaller than unit is always B
|
// smaller than unit is always B
|
||||||
if ($abs_bytes < $unit) {
|
if ($abs_bytes < $unit) {
|
||||||
return $bytes . 'B';
|
return $bytes . 'B';
|
||||||
@@ -110,6 +113,7 @@ class Byte
|
|||||||
*
|
*
|
||||||
* @param string|int|float $number any string or number to convert
|
* @param string|int|float $number any string or number to convert
|
||||||
* @param int $flags bitwise flag with use space turned on
|
* @param int $flags bitwise flag with use space turned on
|
||||||
|
* BYTE_FORMAT_SI: use 1000 instead of 1024
|
||||||
* @return string|int|float converted value or original value
|
* @return string|int|float converted value or original value
|
||||||
*/
|
*/
|
||||||
public static function stringByteFormat($number, int $flags = 0)
|
public static function stringByteFormat($number, int $flags = 0)
|
||||||
|
|||||||
@@ -1481,19 +1481,29 @@ class IO
|
|||||||
* @param string $string string to escape
|
* @param string $string string to escape
|
||||||
* @return string escaped string
|
* @return string escaped string
|
||||||
*/
|
*/
|
||||||
public function dbEscapeIdentifier($string): string
|
public function dbEscapeIdentifier(string $string): string
|
||||||
{
|
{
|
||||||
return $this->db_functions->__dbEscapeIdentifier($string);
|
return $this->db_functions->__dbEscapeIdentifier($string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* escape data for writing to bytea type column field
|
* escape data for writing to bytea type column field
|
||||||
* @param string $bytea bytea to escape
|
* @param string $data data to escape to bytea
|
||||||
* @return string escaped bytea
|
* @return string escaped bytea string
|
||||||
*/
|
*/
|
||||||
public function dbEscapeBytea($bytea)
|
public function dbEscapeBytea(string $data): string
|
||||||
{
|
{
|
||||||
return $this->db_functions->__dbEscapeBytea($bytea);
|
return $this->db_functions->__dbEscapeBytea($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unescape bytea data back to normal binrary data
|
||||||
|
* @param string $bytea bytea data stream
|
||||||
|
* @return string binary data string
|
||||||
|
*/
|
||||||
|
public function dbUnescapeBytea(string $bytea): string
|
||||||
|
{
|
||||||
|
return $this->db_functions->__dbUnescapeBytea($bytea);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1811,6 +1821,7 @@ class IO
|
|||||||
|
|
||||||
// if cursor exists ...
|
// if cursor exists ...
|
||||||
if ($this->cursor_ext[$query_hash]['cursor']) {
|
if ($this->cursor_ext[$query_hash]['cursor']) {
|
||||||
|
/** @phpstan-ignore-next-line claims this is always false, but can be true */
|
||||||
if ($first_call === true) {
|
if ($first_call === true) {
|
||||||
$this->cursor_ext[$query_hash]['log'][] = 'First call';
|
$this->cursor_ext[$query_hash]['log'][] = 'First call';
|
||||||
// count the rows returned (if select)
|
// count the rows returned (if select)
|
||||||
|
|||||||
@@ -559,15 +559,26 @@ class PgSQL implements \CoreLibs\DB\SQL\SqlInterface\SqlFunctions
|
|||||||
/**
|
/**
|
||||||
* wrapper for pg_escape_byte
|
* wrapper for pg_escape_byte
|
||||||
*
|
*
|
||||||
* @param string $bytea bytea data stream
|
* @param string $data data stream
|
||||||
* @return string escaped bytea string
|
* @return string escaped bytea string
|
||||||
*/
|
*/
|
||||||
public function __dbEscapeBytea(string $bytea): string
|
public function __dbEscapeBytea(string $data): string
|
||||||
{
|
{
|
||||||
if ($this->dbh === false || is_bool($this->dbh)) {
|
if ($this->dbh === false || is_bool($this->dbh)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
return pg_escape_bytea($this->dbh, $bytea);
|
return pg_escape_bytea($this->dbh, $data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* unescape bytea data from postgesql
|
||||||
|
*
|
||||||
|
* @param string $bytea Bytea data stream
|
||||||
|
* @return string Unescaped bytea data
|
||||||
|
*/
|
||||||
|
public function __dbUnescapeBytea(string $bytea): string
|
||||||
|
{
|
||||||
|
return pg_unescape_bytea($bytea);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -211,13 +211,21 @@ interface SqlFunctions
|
|||||||
*/
|
*/
|
||||||
public function __dbEscapeIdentifier(string $string): string;
|
public function __dbEscapeIdentifier(string $string): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param string $data
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function __dbEscapeBytea(string $data): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param string $bytea
|
* @param string $bytea
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __dbEscapeBytea(string $bytea): string;
|
public function __dbUnescapeBytea(string $bytea): string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
|
|||||||
Reference in New Issue
Block a user