php-sqlsrv/test/functional/pdo_sqlsrv/pdo_ae_bindColumn_pdoparam_binary_size.phpt

140 lines
6 KiB
Plaintext
Raw Normal View History

2018-02-27 22:38:49 +01:00
--TEST--
2018-03-03 01:34:47 +01:00
Test for retrieving encrypted data from binary types columns using PDO::bindColumn
2018-02-27 22:38:49 +01:00
--DESCRIPTION--
2018-03-03 01:34:47 +01:00
Test conversion from binary types column to output of PDO::PARAM types
With or without AE, conversion works if:
1. From any binary type column to PDO::PARAM_STR
2. From any binary type column to PDO::PARAM_LOB
2018-02-27 22:38:49 +01:00
--SKIPIF--
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
require_once("MsCommon_mid-refactor.inc");
require_once("AEData.inc");
$dataTypes = array("binary", "varbinary", "varbinary(max)");
$lengths = array(1, 8, 64, 512, 4000);
try {
$conn = connect("", array(), PDO::ERRMODE_SILENT);
foreach ($dataTypes as $dataType) {
2018-03-03 01:34:47 +01:00
$maxcol = strpos($dataType, "(max)");
foreach ($lengths as $m) {
if ($maxcol !== false) {
$typeFull = $dataType;
2018-02-27 22:38:49 +01:00
} else {
2018-03-03 01:34:47 +01:00
$typeFull = "$dataType($m)";
2018-02-27 22:38:49 +01:00
}
2018-03-03 01:34:47 +01:00
echo "\nTesting $typeFull:\n";
2018-02-27 22:38:49 +01:00
2018-03-03 01:34:47 +01:00
//create and populate table containing binary(m) or varbinary(m) columns
$tbname = "test_" . str_replace(array('(', ')'), '', $dataType) . $m;
$colMetaArr = array(new ColumnMeta($typeFull, "c_det"), new ColumnMeta($typeFull, "c_rand", null, "randomized"));
2018-02-27 22:38:49 +01:00
createTable($conn, $tbname, $colMetaArr);
2018-03-03 01:34:47 +01:00
$inputValues = array(str_repeat("d", $m), str_repeat("r", $m));
insertRow($conn, $tbname, array("c_det" => new BindParamOp(1, $inputValues[0], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY"),
"c_rand" => new BindParamOp(2, $inputValues[1], "PDO::PARAM_LOB", 0, "PDO::SQLSRV_ENCODING_BINARY")), "prepareBindParam");
2018-02-27 22:38:49 +01:00
2018-03-03 01:34:47 +01:00
// fetch by specifying PDO::PARAM_ types with PDO::bindColumn
2018-02-27 22:38:49 +01:00
$query = "SELECT c_det, c_rand FROM $tbname";
foreach ($pdoParamTypes as $pdoParamType) {
$det = "";
$rand = "";
$stmt = $conn->prepare($query);
$stmt->execute();
$stmt->bindColumn('c_det', $det, constant($pdoParamType));
$stmt->bindColumn('c_rand', $rand, constant($pdoParamType));
$row = $stmt->fetch(PDO::FETCH_BOUND);
2018-03-03 01:34:47 +01:00
// check the case when fetching as PDO::PARAM_BOOL, PDO::PARAM_NULL or PDO::PARAM_INT
// with or without AE: should not work
2018-02-27 22:38:49 +01:00
if ($pdoParamType == "PDO::PARAM_BOOL" || $pdoParamType == "PDO::PARAM_NULL" || $pdoParamType == "PDO::PARAM_INT") {
if (!is_null($det) || !is_null($rand)) {
2018-03-03 01:34:47 +01:00
echo "Retrieving $typeFull data as $pdoParamType should not be supported\n";
2018-02-27 22:38:49 +01:00
}
2021-07-29 00:45:04 +02:00
// check the case when fetching as PDO::PARAM_STR
2018-03-03 01:34:47 +01:00
// with or without AE: should work
2018-02-27 22:38:49 +01:00
} else {
2021-07-29 00:45:04 +02:00
if (PHP_VERSION_ID >= 80100 && $pdoParamType == "PDO::PARAM_LOB") {
// Starting with PHP 8.1 fetching as PDO::PARAM_LOB will return a resource obj
$det = fread($det, 8192);
$rand = fread($rand, 8192);
}
2018-03-14 00:15:42 +01:00
if (trim($det) == $inputValues[0] && trim($rand) == $inputValues[1]) {
2018-03-03 01:34:47 +01:00
echo "****Retrieving $typeFull data as $pdoParamType is supported****\n";
2018-02-27 22:38:49 +01:00
} else {
2018-03-03 01:34:47 +01:00
echo "Retrieving $typeFull data as $pdoParamType fails\n";
2018-02-27 22:38:49 +01:00
}
}
}
2018-03-03 01:34:47 +01:00
// cleanup
2018-02-27 22:38:49 +01:00
dropTable($conn, $tbname);
}
}
unset($stmt);
unset($conn);
} catch (PDOException $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Testing binary(1):
2018-03-03 01:34:47 +01:00
****Retrieving binary(1) data as PDO::PARAM_STR is supported****
****Retrieving binary(1) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing binary(8):
2018-03-03 01:34:47 +01:00
****Retrieving binary(8) data as PDO::PARAM_STR is supported****
****Retrieving binary(8) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing binary(64):
2018-03-03 01:34:47 +01:00
****Retrieving binary(64) data as PDO::PARAM_STR is supported****
****Retrieving binary(64) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing binary(512):
2018-03-03 01:34:47 +01:00
****Retrieving binary(512) data as PDO::PARAM_STR is supported****
****Retrieving binary(512) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing binary(4000):
2018-03-03 01:34:47 +01:00
****Retrieving binary(4000) data as PDO::PARAM_STR is supported****
****Retrieving binary(4000) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(1):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(1) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(1) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(8):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(8) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(8) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(64):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(64) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(64) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(512):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(512) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(512) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(4000):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(4000) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(4000) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(max):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(max):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(max):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(max):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****
2018-02-27 22:38:49 +01:00
Testing varbinary(max):
2018-03-03 01:34:47 +01:00
****Retrieving varbinary(max) data as PDO::PARAM_STR is supported****
****Retrieving varbinary(max) data as PDO::PARAM_LOB is supported****