Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ce1c72a0bc | ||
|
|
10319ef728 | ||
|
|
8d0036eaac | ||
|
|
d1e65c702e | ||
|
|
7248906da7 | ||
|
|
7f9a4dc04f | ||
|
|
10935214eb |
@@ -5196,6 +5196,27 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
SQL,
|
SQL,
|
||||||
'count' => 1,
|
'count' => 1,
|
||||||
'convert' => false,
|
'convert' => false,
|
||||||
|
],
|
||||||
|
'update with case' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
UPDATE table_with_primary_key SET
|
||||||
|
row_int = $1::INT,
|
||||||
|
row_varchar = CASE WHEN row_int = 1 THEN $2 ELSE 'bar'::VARCHAR END
|
||||||
|
WHERE
|
||||||
|
row_varchar = $3
|
||||||
|
SQL,
|
||||||
|
'count' => 3,
|
||||||
|
'convert' => false,
|
||||||
|
],
|
||||||
|
'select with case' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
SELECT row_int
|
||||||
|
FROM table_with_primary_key
|
||||||
|
WHERE
|
||||||
|
row_varchar = CASE WHEN row_int = 1 THEN $1 ELSE $2 END
|
||||||
|
SQL,
|
||||||
|
'count' => 2,
|
||||||
|
'convert' => false,
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,6 +174,26 @@ while (is_array($res = $db->dbReturnParams($query, [$query_value]))) {
|
|||||||
|
|
||||||
echo "<hr>";
|
echo "<hr>";
|
||||||
|
|
||||||
|
echo "<b>CASE part</b><br>";
|
||||||
|
$query = <<<SQL
|
||||||
|
UPDATE
|
||||||
|
test_foo
|
||||||
|
SET
|
||||||
|
some_timestamp = NOW(),
|
||||||
|
-- if not 1 set, else keep at one
|
||||||
|
smallint_a = (CASE
|
||||||
|
WHEN smallint_a <> 1 THEN $1
|
||||||
|
ELSE 1::INT
|
||||||
|
END)::INT
|
||||||
|
WHERE
|
||||||
|
string_a = $2
|
||||||
|
SQL;
|
||||||
|
echo "QUERY: <pre>" . $query . "</pre>";
|
||||||
|
$res = $db->dbExecParams($query, [1, 'foobar']);
|
||||||
|
print "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
||||||
|
|
||||||
|
echo "<hr>";
|
||||||
|
|
||||||
// test connectors: = , <> () for query detection
|
// test connectors: = , <> () for query detection
|
||||||
|
|
||||||
// convert placeholder tests
|
// convert placeholder tests
|
||||||
@@ -237,7 +257,7 @@ SQL,
|
|||||||
SQL,
|
SQL,
|
||||||
'params' => [1, 2, 3, 4, 5, 6],
|
'params' => [1, 2, 3, 4, 5, 6],
|
||||||
'direction' => 'pg'
|
'direction' => 'pg'
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
$db->dbSetConvertPlaceholder(true);
|
$db->dbSetConvertPlaceholder(true);
|
||||||
|
|||||||
@@ -363,11 +363,12 @@ class Session
|
|||||||
* set the auto write close flag
|
* set the auto write close flag
|
||||||
*
|
*
|
||||||
* @param bool $flag
|
* @param bool $flag
|
||||||
* @return void
|
* @return Session
|
||||||
*/
|
*/
|
||||||
public function setAutoWriteClose(bool $flag): void
|
public function setAutoWriteClose(bool $flag): Session
|
||||||
{
|
{
|
||||||
$this->auto_write_close = $flag;
|
$this->auto_write_close = $flag;
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -513,14 +514,15 @@ class Session
|
|||||||
*
|
*
|
||||||
* @param string $name array name in _SESSION
|
* @param string $name array name in _SESSION
|
||||||
* @param mixed $value value to set (can be anything)
|
* @param mixed $value value to set (can be anything)
|
||||||
* @return void
|
* @return Session
|
||||||
*/
|
*/
|
||||||
public function set(string $name, mixed $value): void
|
public function set(string $name, mixed $value): Session
|
||||||
{
|
{
|
||||||
$this->checkValidSessionEntryKey($name);
|
$this->checkValidSessionEntryKey($name);
|
||||||
$this->restartSession();
|
$this->restartSession();
|
||||||
$_SESSION[$name] = $value;
|
$_SESSION[$name] = $value;
|
||||||
$this->closeSessionCall();
|
$this->closeSessionCall();
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -577,16 +579,17 @@ class Session
|
|||||||
* unset one _SESSION entry 'name' if exists
|
* unset one _SESSION entry 'name' if exists
|
||||||
*
|
*
|
||||||
* @param string $name _SESSION key name to remove
|
* @param string $name _SESSION key name to remove
|
||||||
* @return void
|
* @return Session
|
||||||
*/
|
*/
|
||||||
public function unset(string $name): void
|
public function unset(string $name): Session
|
||||||
{
|
{
|
||||||
if (!isset($_SESSION[$name])) {
|
if (!isset($_SESSION[$name])) {
|
||||||
return;
|
return $this;
|
||||||
}
|
}
|
||||||
$this->restartSession();
|
$this->restartSession();
|
||||||
unset($_SESSION[$name]);
|
unset($_SESSION[$name]);
|
||||||
$this->closeSessionCall();
|
$this->closeSessionCall();
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -26,7 +26,9 @@ class ConvertPlaceholder
|
|||||||
. '&&|' // array overlap
|
. '&&|' // array overlap
|
||||||
. '\-\|\-|' // range overlap for array
|
. '\-\|\-|' // range overlap for array
|
||||||
. '[^-]-{1}|' // single -, used in JSON too
|
. '[^-]-{1}|' // single -, used in JSON too
|
||||||
. '->|->>|#>|#>>|@>|<@|@@|@\?|\?{1}|\?\||\?&|#-'; //JSON searches, Array searchs, etc
|
. '->|->>|#>|#>>|@>|<@|@@|@\?|\?{1}|\?\||\?&|#-|' // JSON searches, Array searchs, etc
|
||||||
|
. 'THEN|ELSE' // command parts (CASE)
|
||||||
|
;
|
||||||
/** @var string the main regex including the pattern query split */
|
/** @var string the main regex including the pattern query split */
|
||||||
private const PATTERN_ELEMENT = '(?:\'.*?\')?\s*(?:' . self::PATTERN_QUERY_SPLIT . ')\s*';
|
private const PATTERN_ELEMENT = '(?:\'.*?\')?\s*(?:' . self::PATTERN_QUERY_SPLIT . ')\s*';
|
||||||
/** @var string comment regex
|
/** @var string comment regex
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ class AsymmetricAnonymousEncryption
|
|||||||
* @return string
|
* @return string
|
||||||
* @throws \UnexpectedValueException key pair empty
|
* @throws \UnexpectedValueException key pair empty
|
||||||
* @throws \UnexpectedValueException invalid hex key pair
|
* @throws \UnexpectedValueException invalid hex key pair
|
||||||
* @throws \UnexpectedValueException key pair not correct size
|
* @throws \RangeException key pair not correct size
|
||||||
*/
|
*/
|
||||||
private function createKeyPair(
|
private function createKeyPair(
|
||||||
#[\SensitiveParameter]
|
#[\SensitiveParameter]
|
||||||
@@ -147,7 +147,7 @@ class AsymmetricAnonymousEncryption
|
|||||||
* @return string
|
* @return string
|
||||||
* @throws \UnexpectedValueException public key empty
|
* @throws \UnexpectedValueException public key empty
|
||||||
* @throws \UnexpectedValueException invalid hex key
|
* @throws \UnexpectedValueException invalid hex key
|
||||||
* @throws \UnexpectedValueException invalid key length
|
* @throws \RangeException invalid key length
|
||||||
*/
|
*/
|
||||||
private function createPublicKey(?string $public_key): string
|
private function createPublicKey(?string $public_key): string
|
||||||
{
|
{
|
||||||
@@ -256,13 +256,13 @@ class AsymmetricAnonymousEncryption
|
|||||||
* sets the private key for encryption
|
* sets the private key for encryption
|
||||||
*
|
*
|
||||||
* @param string $key_pair Key pair in hex
|
* @param string $key_pair Key pair in hex
|
||||||
* @return void
|
* @return AsymmetricAnonymousEncryption
|
||||||
* @throws \UnexpectedValueException key pair empty
|
* @throws \UnexpectedValueException key pair empty
|
||||||
*/
|
*/
|
||||||
public function setKeyPair(
|
public function setKeyPair(
|
||||||
#[\SensitiveParameter]
|
#[\SensitiveParameter]
|
||||||
string $key_pair
|
string $key_pair
|
||||||
) {
|
): AsymmetricAnonymousEncryption {
|
||||||
if (empty($key_pair)) {
|
if (empty($key_pair)) {
|
||||||
throw new \UnexpectedValueException('Key pair cannot be empty');
|
throw new \UnexpectedValueException('Key pair cannot be empty');
|
||||||
}
|
}
|
||||||
@@ -277,6 +277,7 @@ class AsymmetricAnonymousEncryption
|
|||||||
// check if valid
|
// check if valid
|
||||||
$this->createPublicKey($this->public_key);
|
$this->createPublicKey($this->public_key);
|
||||||
}
|
}
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -308,10 +309,10 @@ class AsymmetricAnonymousEncryption
|
|||||||
* extract the public key from the key pair
|
* extract the public key from the key pair
|
||||||
*
|
*
|
||||||
* @param string $public_key Public Key in hex
|
* @param string $public_key Public Key in hex
|
||||||
* @return void
|
* @return AsymmetricAnonymousEncryption
|
||||||
* @throws \UnexpectedValueException public key empty
|
* @throws \UnexpectedValueException public key empty
|
||||||
*/
|
*/
|
||||||
public function setPublicKey(string $public_key)
|
public function setPublicKey(string $public_key): AsymmetricAnonymousEncryption
|
||||||
{
|
{
|
||||||
if (empty($public_key)) {
|
if (empty($public_key)) {
|
||||||
throw new \UnexpectedValueException('Public key cannot be empty');
|
throw new \UnexpectedValueException('Public key cannot be empty');
|
||||||
@@ -320,6 +321,7 @@ class AsymmetricAnonymousEncryption
|
|||||||
$this->createPublicKey($public_key);
|
$this->createPublicKey($public_key);
|
||||||
$this->public_key = $public_key;
|
$this->public_key = $public_key;
|
||||||
sodium_memzero($public_key);
|
sodium_memzero($public_key);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -209,13 +209,13 @@ class SymmetricEncryption
|
|||||||
* set a new key for encryption
|
* set a new key for encryption
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return void
|
* @return SymmetricEncryption
|
||||||
* @throws \UnexpectedValueException key cannot be empty
|
* @throws \UnexpectedValueException key cannot be empty
|
||||||
*/
|
*/
|
||||||
public function setKey(
|
public function setKey(
|
||||||
#[\SensitiveParameter]
|
#[\SensitiveParameter]
|
||||||
string $key
|
string $key
|
||||||
) {
|
): SymmetricEncryption {
|
||||||
if (empty($key)) {
|
if (empty($key)) {
|
||||||
throw new \UnexpectedValueException('Key cannot be empty');
|
throw new \UnexpectedValueException('Key cannot be empty');
|
||||||
}
|
}
|
||||||
@@ -224,6 +224,7 @@ class SymmetricEncryption
|
|||||||
// set key
|
// set key
|
||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
sodium_memzero($key);
|
sodium_memzero($key);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user