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

61 lines
1.9 KiB
Plaintext
Raw Normal View History

--TEST--
Test for inserting encrypted nvarchar data of variable lengths and retrieving encrypted and decrypted data
--SKIPIF--
2017-11-07 02:30:11 +01:00
<?php require('skipif_mid-refactor.inc'); ?>
--FILE--
<?php
2017-11-07 02:30:11 +01:00
require_once("MsCommon_mid-refactor.inc");
$testPass = true;
2017-11-07 02:30:11 +01:00
try {
$conn = connect();
// Create the table
$tbname = 'NVarcharAnalysis';
2017-11-07 02:30:11 +01:00
$colMetaArr = array( new ColumnMeta("int", "CharCount", "IDENTITY(0,1)"), new columnMeta("nvarchar(1000)"));
createTable($conn, $tbname, $colMetaArr);
// insert 1000 rows
2017-11-07 02:30:11 +01:00
for ($i = 0; $i < 1000; $i++) {
$data = str_repeat("*", $i);
$stmt = insertRow($conn, $tbname, array(getDefaultColName("nvarchar(1000)") => $data));
}
2017-11-07 02:30:11 +01:00
$selectSql = "SELECT * FROM $tbname";
2017-11-07 02:30:11 +01:00
$stmt = $conn->query($selectSql);
while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($decrypted_row['CharCount'] != strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) {
$rowInd = $decrypted_row['CharCount'] + 1;
echo "Failed to decrypted at row $rowInd\n";
$testPass = false;
}
}
2017-11-07 02:30:11 +01:00
unset($stmt);
} catch (PDOException $e) {
echo $e->getMessage();
}
// for AE only
2017-11-07 02:30:11 +01:00
if (isColEncrypted()) {
try {
$conn1 = connect('', array(), PDO::ERRMODE_EXCEPTION, true);
$stmt = $conn1->query($selectSql);
while ($decrypted_row = $stmt->fetch(PDO::FETCH_ASSOC)) {
2017-11-08 02:12:43 +01:00
if ($decrypted_row['CharCount'] == strlen($decrypted_row[getDefaultColName("nvarchar(1000)")])) {
$rowInd = $decrypted_row[ 'CharCount' ] + 1;
echo "Failed to encrypted at row $rowInd\n";
$testPass = false;
}
}
2017-11-07 02:30:11 +01:00
unset($stmt);
unset($conn1);
} catch (PDOException $e) {
echo $e->getMessage();
}
}
2017-11-07 02:30:11 +01:00
dropTable($conn, $tbname);
unset($conn);
if ($testPass) {
2017-09-14 18:47:40 +02:00
echo "Test successfully done.\n";
}
?>
--EXPECT--
2017-11-07 02:30:11 +01:00
Test successfully done.