Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c13934de99 | ||
|
|
ba11a936db | ||
|
|
5343034768 | ||
|
|
880f15ac6f | ||
|
|
a46601fe03 | ||
|
|
022c39e791 |
@@ -13,7 +13,7 @@ if [ "${GO}" != "go" ]; then
|
|||||||
fi;
|
fi;
|
||||||
|
|
||||||
BASE="/storage/var/www/html/developers/clemens/core_data/";
|
BASE="/storage/var/www/html/developers/clemens/core_data/";
|
||||||
SOURCE="${BASE}php_libraries/trunk/"
|
SOURCE="${BASE}php_libraries/master/"
|
||||||
TARGET="${BASE}composer-packages/CoreLibs-Composer-All/"
|
TARGET="${BASE}composer-packages/CoreLibs-Composer-All/"
|
||||||
|
|
||||||
rsync ${DRY_RUN}-Plzvrupt --stats --delete ${SOURCE}4dev/tests/ ${TARGET}test/phpunit/
|
rsync ${DRY_RUN}-Plzvrupt --stats --delete ${SOURCE}4dev/tests/ ${TARGET}test/phpunit/
|
||||||
|
|||||||
@@ -5141,9 +5141,9 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
INSERT INTO table_with_primary_key (
|
INSERT INTO table_with_primary_key (
|
||||||
row_int, row_numeric, row_varchar, row_varchar_literal
|
row_int, row_numeric, row_varchar, row_varchar_literal
|
||||||
) VALUES (
|
) VALUES (
|
||||||
-- comment 1
|
-- comment 1 かな
|
||||||
$1, $2,
|
$1, $2,
|
||||||
-- comment 2
|
-- comment 2 -
|
||||||
$3
|
$3
|
||||||
-- comment 3
|
-- comment 3
|
||||||
, $4
|
, $4
|
||||||
@@ -5152,6 +5152,23 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
'count' => 4,
|
'count' => 4,
|
||||||
'convert' => false
|
'convert' => false
|
||||||
],
|
],
|
||||||
|
'comment in update' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
UPDATE table_with_primary_key SET
|
||||||
|
row_int =
|
||||||
|
-- COMMENT 1
|
||||||
|
$1,
|
||||||
|
row_numeric =
|
||||||
|
$2 -- COMMENT 2
|
||||||
|
,
|
||||||
|
row_varchar -- COMMENT 3
|
||||||
|
= $3
|
||||||
|
WHERE
|
||||||
|
row_varchar = $4
|
||||||
|
SQL,
|
||||||
|
'count' => 4,
|
||||||
|
'convert' => false,
|
||||||
|
],
|
||||||
// Note some are not set
|
// Note some are not set
|
||||||
'a complete set of possible' => [
|
'a complete set of possible' => [
|
||||||
'query' => <<<SQL
|
'query' => <<<SQL
|
||||||
@@ -5168,6 +5185,17 @@ final class CoreLibsDBIOTest extends TestCase
|
|||||||
SQL,
|
SQL,
|
||||||
'count' => 12,
|
'count' => 12,
|
||||||
'convert' => false,
|
'convert' => false,
|
||||||
|
],
|
||||||
|
// all the same
|
||||||
|
'all the same numbered' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
UPDATE table_with_primary_key SET
|
||||||
|
row_int = $1::INT, row_numeric = $1::NUMERIC, row_varchar = $1
|
||||||
|
WHERE
|
||||||
|
row_varchar = $1
|
||||||
|
SQL,
|
||||||
|
'count' => 1,
|
||||||
|
'convert' => false,
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
2
4dev/tests/Language/locale_other/.gitignore
vendored
Normal file
2
4dev/tests/Language/locale_other/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
*
|
||||||
|
!.gitignore
|
||||||
@@ -56,7 +56,24 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
$decrypted,
|
$decrypted,
|
||||||
'Class call',
|
'Class call',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test encrypt/decrypt produce correct output
|
||||||
|
*
|
||||||
|
* @covers ::generateRandomKey
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerEncryptDecryptSuccess
|
||||||
|
* @testdox encrypt/decrypt indirect $input must be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEncryptDecryptSuccessIndirect(string $input, string $expected): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
// test indirect
|
// test indirect
|
||||||
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
||||||
$decrypted = SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
$decrypted = SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||||
@@ -65,7 +82,24 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
$decrypted,
|
$decrypted,
|
||||||
'Class Instance call',
|
'Class Instance call',
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test encrypt/decrypt produce correct output
|
||||||
|
*
|
||||||
|
* @covers ::generateRandomKey
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerEncryptDecryptSuccess
|
||||||
|
* @testdox encrypt/decrypt static $input must be $expected [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $expected
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEncryptDecryptSuccessStatic(string $input, string $expected): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
// test static
|
// test static
|
||||||
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
||||||
$decrypted = SymmetricEncryption::decryptKey($encrypted, $key);
|
$decrypted = SymmetricEncryption::decryptKey($encrypted, $key);
|
||||||
@@ -114,13 +148,51 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
$crypt = new SymmetricEncryption($key);
|
$crypt = new SymmetricEncryption($key);
|
||||||
$encrypted = $crypt->encrypt($input);
|
$encrypted = $crypt->encrypt($input);
|
||||||
$this->expectExceptionMessage($exception_message);
|
$this->expectExceptionMessage($exception_message);
|
||||||
$crypt->setKey($key);
|
$crypt->setKey($wrong_key);
|
||||||
$crypt->decrypt($encrypted);
|
$crypt->decrypt($encrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test decryption with wrong key
|
||||||
|
*
|
||||||
|
* @covers ::generateRandomKey
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerEncryptFailed
|
||||||
|
* @testdox decrypt indirect with wrong key $input throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEncryptFailedIndirect(string $input, string $exception_message): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
$wrong_key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
// class instance
|
// class instance
|
||||||
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
$encrypted = SymmetricEncryption::getInstance($key)->encrypt($input);
|
||||||
$this->expectExceptionMessage($exception_message);
|
$this->expectExceptionMessage($exception_message);
|
||||||
SymmetricEncryption::getInstance($wrong_key)->decrypt($encrypted);
|
SymmetricEncryption::getInstance($wrong_key)->decrypt($encrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test decryption with wrong key
|
||||||
|
*
|
||||||
|
* @covers ::generateRandomKey
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerEncryptFailed
|
||||||
|
* @testdox decrypt static with wrong key $input throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testEncryptFailedStatic(string $input, string $exception_message): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
$wrong_key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
// class static
|
// class static
|
||||||
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
$encrypted = SymmetricEncryption::encryptKey($input, $key);
|
||||||
@@ -190,6 +262,56 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
SymmetricEncryption::decryptKey($encrypted, $key);
|
SymmetricEncryption::decryptKey($encrypted, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test invalid key provided to decrypt or encrypt
|
||||||
|
*
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerWrongKey
|
||||||
|
* @testdox wrong key indirect $key throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testWrongKeyIndirect(string $key, string $exception_message): void
|
||||||
|
{
|
||||||
|
$enc_key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
|
// class instance
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::getInstance($key)->encrypt('test');
|
||||||
|
// we must encrypt valid thing first so we can fail with the wrong key
|
||||||
|
$encrypted = SymmetricEncryption::getInstance($enc_key)->encrypt('test');
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::getInstance($key)->decrypt($encrypted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test invalid key provided to decrypt or encrypt
|
||||||
|
*
|
||||||
|
* @covers ::encrypt
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerWrongKey
|
||||||
|
* @testdox wrong key static $key throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $key
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testWrongKeyStatic(string $key, string $exception_message): void
|
||||||
|
{
|
||||||
|
$enc_key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
|
// class static
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::encryptKey('test', $key);
|
||||||
|
// we must encrypt valid thing first so we can fail with the wrong key
|
||||||
|
$encrypted = SymmetricEncryption::encryptKey('test', $enc_key);
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::decryptKey($encrypted, $key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Undocumented function
|
* Undocumented function
|
||||||
*
|
*
|
||||||
@@ -232,6 +354,49 @@ final class CoreLibsSecuritySymmetricEncryptionTest extends TestCase
|
|||||||
$this->expectExceptionMessage($exception_message);
|
$this->expectExceptionMessage($exception_message);
|
||||||
SymmetricEncryption::decryptKey($input, $key);
|
SymmetricEncryption::decryptKey($input, $key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerWrongCiphertext
|
||||||
|
* @testdox too short ciphertext indirect $input throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testWrongCiphertextIndirect(string $input, string $exception_message): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
|
||||||
|
// class instance
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::getInstance($key)->decrypt($input);
|
||||||
|
|
||||||
|
// class static
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::decryptKey($input, $key);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @covers ::decrypt
|
||||||
|
* @dataProvider providerWrongCiphertext
|
||||||
|
* @testdox too short ciphertext static $input throws $exception_message [$_dataName]
|
||||||
|
*
|
||||||
|
* @param string $input
|
||||||
|
* @param string $exception_message
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testWrongCiphertextStatic(string $input, string $exception_message): void
|
||||||
|
{
|
||||||
|
$key = CreateKey::generateRandomKey();
|
||||||
|
// class static
|
||||||
|
$this->expectExceptionMessage($exception_message);
|
||||||
|
SymmetricEncryption::decryptKey($input, $key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// __END__
|
// __END__
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ $log = new CoreLibs\Logging\Logging([
|
|||||||
'log_per_date' => true,
|
'log_per_date' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
$PAGE_NAME = 'TEST CLASS: DB CONVERT PLACEHOLDER';
|
$PAGE_NAME = 'TEST CLASS: DB CONVERT PLACEHOLDER';
|
||||||
print "<!DOCTYPE html>";
|
print "<!DOCTYPE html>";
|
||||||
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
print "<html><head><title>" . $PAGE_NAME . "</title></head>";
|
||||||
|
|||||||
@@ -53,6 +53,9 @@ if (($dbh = $db->dbGetDbh()) instanceof \PgSql\Connection) {
|
|||||||
} else {
|
} else {
|
||||||
print "NO DB HANDLER<br>";
|
print "NO DB HANDLER<br>";
|
||||||
}
|
}
|
||||||
|
// REGEX for placeholder count
|
||||||
|
print "Placeholder regex: <pre>" . CoreLibs\DB\Support\ConvertPlaceholder::REGEX_LOOKUP_PLACEHOLDERS . "</pre>";
|
||||||
|
|
||||||
// turn on debug replace for placeholders
|
// turn on debug replace for placeholders
|
||||||
$db->dbSetDebugReplacePlaceholder(true);
|
$db->dbSetDebugReplacePlaceholder(true);
|
||||||
|
|
||||||
@@ -62,53 +65,94 @@ $db->dbExec("TRUNCATE test_foo");
|
|||||||
$uniqid = \CoreLibs\Create\Uids::uniqIdShort();
|
$uniqid = \CoreLibs\Create\Uids::uniqIdShort();
|
||||||
$binary_data = $db->dbEscapeBytea(file_get_contents('class_test.db.php') ?: '');
|
$binary_data = $db->dbEscapeBytea(file_get_contents('class_test.db.php') ?: '');
|
||||||
$query_params = [
|
$query_params = [
|
||||||
$uniqid,
|
$uniqid, // test
|
||||||
true,
|
true, // some_bool
|
||||||
'STRING A',
|
'STRING A', // string_a
|
||||||
2,
|
2, // number_a
|
||||||
2.5,
|
2.5, // numeric_a
|
||||||
1,
|
1, // smallint
|
||||||
date('H:m:s'),
|
date('H:m:s'), // some_internval
|
||||||
date('Y-m-d H:i:s'),
|
date('Y-m-d H:i:s'), // some_timestamp
|
||||||
json_encode(['a' => 'string', 'b' => 1, 'c' => 1.5, 'f' => true, 'g' => ['a', 1, 1.5]]),
|
json_encode(['a' => 'string', 'b' => 1, 'c' => 1.5, 'f' => true, 'g' => ['a', 1, 1.5]]), // json_string
|
||||||
null,
|
null, // null_var
|
||||||
'{"a", "b"}',
|
'{"a", "b"}', // array_char_1
|
||||||
'{1,2}',
|
'{1,2}', // array_int_1
|
||||||
'{"(array Text A, 5, 8.8)","(array Text B, 10, 15.2)"}',
|
'{"(array Text A, 5, 8.8)","(array Text B, 10, 15.2)"}', // array_composite
|
||||||
'("Text", 4, 6.3)',
|
'("Text", 4, 6.3)', // composite_item
|
||||||
$binary_data
|
$binary_data, // some_binary
|
||||||
|
date('Y-m-d'), // some_date
|
||||||
|
date('H:i:s'), // some_time
|
||||||
|
'{"c", "d", "e"}', // array_char_2
|
||||||
|
'{3,4,5}', // array_int_2
|
||||||
|
12345667778818, // bigint
|
||||||
|
1.56, // numbrer_real
|
||||||
|
3.75, // number_double
|
||||||
|
124.5, // numeric_3
|
||||||
|
\CoreLibs\Create\Uids::uuidv4() // uuid_var
|
||||||
];
|
];
|
||||||
|
|
||||||
$query_insert = <<<SQL
|
$query_insert = <<<SQL
|
||||||
INSERT INTO test_foo (
|
INSERT INTO test_foo (
|
||||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
-- row 1
|
||||||
some_time, some_timestamp, json_string, null_var,
|
test, some_bool, string_a, number_a, numeric_a, smallint_a,
|
||||||
|
-- row 2
|
||||||
|
some_internval, some_timestamp, json_string, null_var,
|
||||||
|
-- row 3
|
||||||
array_char_1, array_int_1,
|
array_char_1, array_int_1,
|
||||||
|
-- row 4
|
||||||
array_composite,
|
array_composite,
|
||||||
|
-- row 5
|
||||||
composite_item,
|
composite_item,
|
||||||
some_binary
|
-- row 6
|
||||||
|
some_binary,
|
||||||
|
-- row 7
|
||||||
|
some_date, some_time,
|
||||||
|
-- row 8
|
||||||
|
array_char_2, array_int_2,
|
||||||
|
-- row 9
|
||||||
|
bigint_a, number_real, number_double, numeric_3,
|
||||||
|
-- row 10
|
||||||
|
uuid_var
|
||||||
) VALUES (
|
) VALUES (
|
||||||
|
-- row 1
|
||||||
$1, $2, $3, $4, $5, $6,
|
$1, $2, $3, $4, $5, $6,
|
||||||
|
-- row 2
|
||||||
$7, $8, $9, $10,
|
$7, $8, $9, $10,
|
||||||
|
-- row 3
|
||||||
$11, $12,
|
$11, $12,
|
||||||
|
-- row 4
|
||||||
$13,
|
$13,
|
||||||
|
-- row 5
|
||||||
$14,
|
$14,
|
||||||
$15
|
-- row 6
|
||||||
|
$15,
|
||||||
|
-- row 7
|
||||||
|
$16, $17,
|
||||||
|
-- row 8
|
||||||
|
$18, $19,
|
||||||
|
-- row 9
|
||||||
|
$20, $21, $22, $23,
|
||||||
|
-- row 10
|
||||||
|
$24
|
||||||
)
|
)
|
||||||
RETURNING
|
RETURNING
|
||||||
test_foo_id,
|
test_foo_id, number_serial, identity_always, identitiy_default, default_uuid,
|
||||||
test, some_bool, string_a, number_a, number_a_numeric, smallint_a,
|
test, some_bool, string_a, number_a, numeric_a, smallint_a,
|
||||||
some_time, some_timestamp, json_string, null_var,
|
some_internval, some_timestamp, json_string, null_var,
|
||||||
array_char_1, array_int_1,
|
array_char_1, array_int_1,
|
||||||
array_composite,
|
array_composite,
|
||||||
composite_item,
|
composite_item,
|
||||||
some_binary
|
some_binary,
|
||||||
|
some_date,
|
||||||
|
array_char_2, array_int_2,
|
||||||
|
bigint_a, number_real, number_double, numeric_3,
|
||||||
|
uuid_var
|
||||||
SQL;
|
SQL;
|
||||||
$status = $db->dbExecParams($query_insert, $query_params);
|
$status = $db->dbExecParams($query_insert, $query_params);
|
||||||
echo "<b>*</b><br>";
|
echo "<b>*</b><br>";
|
||||||
echo "INSERT ALL COLUMN TYPES: "
|
echo "INSERT ALL COLUMN TYPES: "
|
||||||
. Support::printToString($query_params) . " |<br>"
|
. Support::printToString($query_params) . " |<br>"
|
||||||
. "QUERY: " . $db->dbGetQuery() . " |<br>"
|
. "QUERY: <pre>" . $db->dbGetQuery() . "</pre> |<br>"
|
||||||
. "PRIMARY KEY: " . Support::printToString($db->dbGetInsertPK()) . " |<br>"
|
. "PRIMARY KEY: " . Support::printToString($db->dbGetInsertPK()) . " |<br>"
|
||||||
. "RETURNING EXT: <pre>" . print_r($db->dbGetReturningExt(), true) . "</pre> |<br>"
|
. "RETURNING EXT: <pre>" . print_r($db->dbGetReturningExt(), true) . "</pre> |<br>"
|
||||||
. "RETURNING RETURN: <pre>" . print_r($db->dbGetReturningArray(), true) . "<pre> |<br>"
|
. "RETURNING RETURN: <pre>" . print_r($db->dbGetReturningArray(), true) . "<pre> |<br>"
|
||||||
@@ -146,6 +190,16 @@ SQL,
|
|||||||
'params' => [],
|
'params' => [],
|
||||||
'direction' => 'pg',
|
'direction' => 'pg',
|
||||||
],
|
],
|
||||||
|
'numbers' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
SELECT test, string_a, number_a
|
||||||
|
FROM test_foo
|
||||||
|
WHERE
|
||||||
|
foo = $1 AND bar = $1 AND foobar = $2
|
||||||
|
SQL,
|
||||||
|
'params' => [\CoreLibs\Create\Uids::uniqIdShort(), 'string A-1', 1234],
|
||||||
|
'direction' => 'pdo',
|
||||||
|
],
|
||||||
'a?' => [
|
'a?' => [
|
||||||
'query' => <<<SQL
|
'query' => <<<SQL
|
||||||
INSERT INTO test_foo (
|
INSERT INTO test_foo (
|
||||||
@@ -172,6 +226,18 @@ SQL,
|
|||||||
],
|
],
|
||||||
'direction' => 'pg',
|
'direction' => 'pg',
|
||||||
],
|
],
|
||||||
|
'select, compare $' => [
|
||||||
|
'query' => <<<SQL
|
||||||
|
SELECT string_a
|
||||||
|
FROM test_foo
|
||||||
|
WHERE
|
||||||
|
number_a >= $1 OR number_a <= $2 OR
|
||||||
|
number_a > $3 OR number_a < $4
|
||||||
|
OR number_a = $5 OR number_a <> $6
|
||||||
|
SQL,
|
||||||
|
'params' => [1, 2, 3, 4, 5, 6],
|
||||||
|
'direction' => 'pg'
|
||||||
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
$db->dbSetConvertPlaceholder(true);
|
$db->dbSetConvertPlaceholder(true);
|
||||||
@@ -184,11 +250,12 @@ foreach ($test_queries as $info => $data) {
|
|||||||
// . "<br>";
|
// . "<br>";
|
||||||
if ($db->dbCheckQueryForSelect($query)) {
|
if ($db->dbCheckQueryForSelect($query)) {
|
||||||
$row = $db->dbReturnRowParams($query, $params);
|
$row = $db->dbReturnRowParams($query, $params);
|
||||||
print "[$info] SELECT: " . Support::prAr($row) . "<br>";
|
print "<b>[$info]</b> SELECT: " . Support::prAr($row) . "<br>";
|
||||||
} else {
|
} else {
|
||||||
$db->dbExecParams($query, $params);
|
$db->dbExecParams($query, $params);
|
||||||
}
|
}
|
||||||
print "[$info] " . Support::printAr($db->dbGetPlaceholderConverted()) . "<br>";
|
print "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
||||||
|
print "<b>[$info]</b> " . Support::printAr($db->dbGetPlaceholderConverted()) . "<br>";
|
||||||
echo "<hr>";
|
echo "<hr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,22 +270,29 @@ SQL,
|
|||||||
['string A-1']
|
['string A-1']
|
||||||
))
|
))
|
||||||
) {
|
) {
|
||||||
print "RES: " . Support::prAr($res) . "<br>";
|
print "<b>RES</b>: " . Support::prAr($res) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
||||||
|
echo "<hr>";
|
||||||
|
|
||||||
print "CursorExt: " . Support::prAr($db->dbGetCursorExt(<<<SQL
|
print "CursorExt: " . Support::prAr($db->dbGetCursorExt(<<<SQL
|
||||||
SELECT test, string_a, number_a
|
SELECT test, string_a, number_a
|
||||||
FROM test_foo
|
FROM test_foo
|
||||||
WHERE string_a = ?
|
WHERE string_a = ?
|
||||||
SQL, ['string A-1']));
|
SQL, ['string A-1']));
|
||||||
|
echo "<hr>";
|
||||||
|
|
||||||
|
// ERROR BELOW: missing params
|
||||||
$res = $db->dbReturnRowParams(<<<SQL
|
$res = $db->dbReturnRowParams(<<<SQL
|
||||||
SELECT test, string_a, number_a
|
SELECT test, string_a, number_a
|
||||||
FROM test_foo
|
FROM test_foo
|
||||||
WHERE string_a = $1
|
WHERE string_a = $1
|
||||||
SQL, []);
|
SQL, []);
|
||||||
print "PL: " . Support::PrAr($db->dbGetPlaceholderConverted()) . "<br>";
|
print "PL: " . Support::PrAr($db->dbGetPlaceholderConverted()) . "<br>";
|
||||||
|
print "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
||||||
|
echo "<hr>";
|
||||||
|
|
||||||
|
// ERROR BELOW: LIKE cannot have placeholder
|
||||||
echo "dbReturn read LIKE: <br>";
|
echo "dbReturn read LIKE: <br>";
|
||||||
while (
|
while (
|
||||||
is_array($res = $db->dbReturnParams(
|
is_array($res = $db->dbReturnParams(
|
||||||
@@ -232,6 +306,7 @@ SQL,
|
|||||||
) {
|
) {
|
||||||
print "RES: " . Support::prAr($res) . "<br>";
|
print "RES: " . Support::prAr($res) . "<br>";
|
||||||
}
|
}
|
||||||
|
print "ERROR: " . $db->dbGetLastError(true) . "<br>";
|
||||||
|
|
||||||
print "</body></html>";
|
print "</body></html>";
|
||||||
$db->log->debug('DEBUGEND', '==================================== [END]');
|
$db->log->debug('DEBUGEND', '==================================== [END]');
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ HTML;
|
|||||||
$test_files = [
|
$test_files = [
|
||||||
'class_test.db.php' => 'Class Test: DB',
|
'class_test.db.php' => 'Class Test: DB',
|
||||||
'class_test.db.types.php' => 'Class Test: DB column type convert',
|
'class_test.db.types.php' => 'Class Test: DB column type convert',
|
||||||
'class_test.db.query-placeholder.php' => 'Class Test: DB query placeholder convert',
|
'class_test.db.query-placeholder.php' => 'Class Test: DB placeholder queries',
|
||||||
'class_test.db.dbReturn.php' => 'Class Test: DB dbReturn',
|
'class_test.db.dbReturn.php' => 'Class Test: DB dbReturn',
|
||||||
'class_test.db.single.php' => 'Class Test: DB single query tests',
|
'class_test.db.single.php' => 'Class Test: DB single query tests',
|
||||||
'class_test.db.convert-placeholder.php' => 'Class Test: DB convert placeholder',
|
'class_test.db.convert-placeholder.php' => 'Class Test: DB convert placeholder',
|
||||||
|
|||||||
@@ -1332,7 +1332,6 @@ class IO
|
|||||||
*/
|
*/
|
||||||
private function __dbCheckQueryParams(string $query, array $params): bool
|
private function __dbCheckQueryParams(string $query, array $params): bool
|
||||||
{
|
{
|
||||||
// $this->log->debug('DB QUERY PARAMS REGEX', ConvertPlaceholder::REGEX_LOOKUP_PLACEHOLDERS);
|
|
||||||
$placeholder_count = $this->__dbCountQueryParams($query);
|
$placeholder_count = $this->__dbCountQueryParams($query);
|
||||||
$params_count = count($params);
|
$params_count = count($params);
|
||||||
if ($params_count != $placeholder_count) {
|
if ($params_count != $placeholder_count) {
|
||||||
|
|||||||
@@ -18,17 +18,20 @@ class ConvertPlaceholder
|
|||||||
// NOTE some combinations are allowed, but the query will fail before this
|
// NOTE some combinations are allowed, but the query will fail before this
|
||||||
/** @var string split regex, entries before $ group */
|
/** @var string split regex, entries before $ group */
|
||||||
private const PATTERN_QUERY_SPLIT =
|
private const PATTERN_QUERY_SPLIT =
|
||||||
',|' // for ',' mostly in INSERT
|
'\?\?|' // UNKNOWN: double ??, is this to avoid something?
|
||||||
. '[(<>=]|' // general set for (, <, >, = in any query with any combination
|
. '[\(,]|' // for ',' and '(' mostly in INSERT or ANY()
|
||||||
. '(?:[\(,]\s*\-\-[\s\w]*)\r?\n|' // a comment that starts after a ( or ,
|
. '[<>=]|' // general set for <, >, = in any query with any combination
|
||||||
. '\^@|' // text search for start from text with ^@
|
. '\^@|' // text search for start from text with ^@
|
||||||
. '\|\||' // concats two elements
|
. '\|\||' // concats two elements
|
||||||
. '&&|' // array overlap
|
. '&&|' // array overlap
|
||||||
. '\-\|\-|' // range overlap
|
. '\-\|\-|' // 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
|
||||||
/** @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
|
||||||
|
* anything that starts with -- and ends with a line break but any character that is not line break inbetween */
|
||||||
|
private const PATTERN_COMMENT = '(?:\-\-[^\r\n]*?\r?\n)*\s*';
|
||||||
/** @var string parts to ignore in the SQL */
|
/** @var string parts to ignore in the SQL */
|
||||||
private const PATTERN_IGNORE =
|
private const PATTERN_IGNORE =
|
||||||
// digit -> ignore
|
// digit -> ignore
|
||||||
@@ -45,6 +48,7 @@ class ConvertPlaceholder
|
|||||||
/** @var string replace regex for named (:...) entries */
|
/** @var string replace regex for named (:...) entries */
|
||||||
public const REGEX_REPLACE_NAMED = '/'
|
public const REGEX_REPLACE_NAMED = '/'
|
||||||
. '(' . self::PATTERN_ELEMENT . ')'
|
. '(' . self::PATTERN_ELEMENT . ')'
|
||||||
|
. self::PATTERN_COMMENT
|
||||||
. '('
|
. '('
|
||||||
. self::PATTERN_IGNORE
|
. self::PATTERN_IGNORE
|
||||||
. self::PATTERN_NAMED
|
. self::PATTERN_NAMED
|
||||||
@@ -53,6 +57,7 @@ class ConvertPlaceholder
|
|||||||
/** @var string replace regex for question mark (?) entries */
|
/** @var string replace regex for question mark (?) entries */
|
||||||
public const REGEX_REPLACE_QUESTION_MARK = '/'
|
public const REGEX_REPLACE_QUESTION_MARK = '/'
|
||||||
. '(' . self::PATTERN_ELEMENT . ')'
|
. '(' . self::PATTERN_ELEMENT . ')'
|
||||||
|
. self::PATTERN_COMMENT
|
||||||
. '('
|
. '('
|
||||||
. self::PATTERN_IGNORE
|
. self::PATTERN_IGNORE
|
||||||
. self::PATTERN_QUESTION_MARK
|
. self::PATTERN_QUESTION_MARK
|
||||||
@@ -61,6 +66,7 @@ class ConvertPlaceholder
|
|||||||
/** @var string replace regex for numbered ($n) entries */
|
/** @var string replace regex for numbered ($n) entries */
|
||||||
public const REGEX_REPLACE_NUMBERED = '/'
|
public const REGEX_REPLACE_NUMBERED = '/'
|
||||||
. '(' . self::PATTERN_ELEMENT . ')'
|
. '(' . self::PATTERN_ELEMENT . ')'
|
||||||
|
. self::PATTERN_COMMENT
|
||||||
. '('
|
. '('
|
||||||
. self::PATTERN_IGNORE
|
. self::PATTERN_IGNORE
|
||||||
. self::PATTERN_NUMBERED
|
. self::PATTERN_NUMBERED
|
||||||
@@ -71,6 +77,7 @@ class ConvertPlaceholder
|
|||||||
// prefix string part, must match towards
|
// prefix string part, must match towards
|
||||||
// seperator for ( = , ? - [and json/jsonb in pg doc section 9.15]
|
// seperator for ( = , ? - [and json/jsonb in pg doc section 9.15]
|
||||||
. self::PATTERN_ELEMENT
|
. self::PATTERN_ELEMENT
|
||||||
|
. self::PATTERN_COMMENT
|
||||||
// match for replace part
|
// match for replace part
|
||||||
. '(?:'
|
. '(?:'
|
||||||
// ignore parts
|
// ignore parts
|
||||||
|
|||||||
@@ -49,7 +49,11 @@ class SymmetricEncryption
|
|||||||
*/
|
*/
|
||||||
public static function getInstance(string|null $key = null): self
|
public static function getInstance(string|null $key = null): self
|
||||||
{
|
{
|
||||||
if (empty(self::$instance)) {
|
// new if no instsance or key is different
|
||||||
|
if (
|
||||||
|
empty(self::$instance) ||
|
||||||
|
self::$instance->key != $key
|
||||||
|
) {
|
||||||
self::$instance = new self($key);
|
self::$instance = new self($key);
|
||||||
}
|
}
|
||||||
return self::$instance;
|
return self::$instance;
|
||||||
@@ -130,7 +134,7 @@ class SymmetricEncryption
|
|||||||
*/
|
*/
|
||||||
private function encryptData(string $message, ?string $key): string
|
private function encryptData(string $message, ?string $key): string
|
||||||
{
|
{
|
||||||
if (empty($this->key) || $key === null) {
|
if ($key === null) {
|
||||||
throw new \UnexpectedValueException('Key not set');
|
throw new \UnexpectedValueException('Key not set');
|
||||||
}
|
}
|
||||||
$key = $this->createKey($key);
|
$key = $this->createKey($key);
|
||||||
|
|||||||
Reference in New Issue
Block a user