2017-05-04 02:09:36 +02:00
|
|
|
--TEST--
|
|
|
|
test input param with unknown encoding
|
2020-07-09 04:45:00 +02:00
|
|
|
--DESCRIPTION--
|
|
|
|
When running this test with PHP 7.x, PHP warnings like the one below are expected
|
|
|
|
"Warning: Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed 'SQLSRV_ENC_UNKNOWN'
|
|
|
|
(this will throw an Error in a future version of PHP)"
|
|
|
|
When running this test with PHP 8.0, the previous warnings are now errors directly from PHP
|
|
|
|
Because PHP warnings are intercepted, no need to check sqlsrv errors for those.
|
|
|
|
Add a new test case to check the error message 'An invalid PHP type for parameter 2 was specified.'
|
2017-05-04 02:09:36 +02:00
|
|
|
--SKIPIF--
|
2017-11-29 01:40:49 +01:00
|
|
|
<?php require('skipif_versions_old.inc'); ?>
|
2017-05-04 02:09:36 +02:00
|
|
|
--FILE--
|
|
|
|
<?php
|
|
|
|
|
2020-07-09 04:45:00 +02:00
|
|
|
set_error_handler("warningHandler", E_WARNING);
|
|
|
|
|
|
|
|
function warningHandler($errno, $errstr)
|
|
|
|
{
|
|
|
|
throw new Error($errstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
function compareMessages($err)
|
|
|
|
{
|
2020-07-22 18:52:16 +02:00
|
|
|
$exp8x = 'Undefined constant "SQLSRV_ENC_UNKNOWN"';
|
2020-07-09 04:45:00 +02:00
|
|
|
$exp7x = "Use of undefined constant SQLSRV_ENC_UNKNOWN - assumed 'SQLSRV_ENC_UNKNOWN' (this will throw an Error in a future version of PHP)";
|
|
|
|
|
|
|
|
$expected = (PHP_MAJOR_VERSION == 8) ? $exp8x : $exp7x;
|
|
|
|
if ($err->getMessage() !== $expected) {
|
|
|
|
echo $err->getMessage() . PHP_EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 02:09:36 +02:00
|
|
|
set_time_limit(0);
|
2017-11-29 01:40:49 +01:00
|
|
|
sqlsrv_configure('WarningsReturnAsErrors', 0);
|
|
|
|
sqlsrv_configure('LogSeverity', SQLSRV_LOG_SEVERITY_ALL);
|
|
|
|
sqlsrv_configure('LogSubsystems', SQLSRV_LOG_SYSTEM_OFF);
|
|
|
|
|
|
|
|
require_once('MsCommon.inc');
|
|
|
|
|
|
|
|
$conn = AE\connect();
|
2020-07-09 04:45:00 +02:00
|
|
|
$tableName = 'table_unknown_encoding';
|
2017-11-29 01:40:49 +01:00
|
|
|
$columns = array(new AE\ColumnMeta('int', 'c1_int'),
|
|
|
|
new AE\ColumnMeta('varchar(max)', 'c2_varchar_max'));
|
|
|
|
$stmt = AE\createTable($conn, $tableName, $columns);
|
|
|
|
if (!$stmt) {
|
|
|
|
fatalError("Failed to create table $tableName\n");
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
|
|
|
|
2020-07-09 04:45:00 +02:00
|
|
|
try {
|
|
|
|
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
|
|
|
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(array(1, null, null, $intType),
|
|
|
|
array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
|
|
|
|
if ($stmt !== false) {
|
|
|
|
sqlsrv_free_stmt($stmt);
|
|
|
|
die("sqlsrv_query shouldn't have succeeded.");
|
|
|
|
}
|
|
|
|
} catch (Error $err) {
|
|
|
|
compareMessages($err);
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
|
|
|
|
2020-07-09 04:45:00 +02:00
|
|
|
try {
|
|
|
|
$stmt = sqlsrv_prepare($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(1, array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_UNKNOWN), null)));
|
|
|
|
} catch (Error $err) {
|
|
|
|
compareMessages($err);
|
2017-05-04 02:09:36 +02:00
|
|
|
}
|
2017-11-29 01:40:49 +01:00
|
|
|
|
2020-07-09 04:45:00 +02:00
|
|
|
restore_error_handler();
|
|
|
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(array(1, null, null, $intType),
|
|
|
|
array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING(SQLSRV_PHPTYPE_INT), null)));
|
|
|
|
|
|
|
|
$errState = 'IMSSP';
|
|
|
|
$errMessage = 'An invalid PHP type for parameter 2 was specified.';
|
2017-11-29 01:40:49 +01:00
|
|
|
verifyError(sqlsrv_errors()[0], $errState, $errMessage);
|
2020-07-09 04:45:00 +02:00
|
|
|
|
|
|
|
echo "Done\n";
|
2017-05-04 02:09:36 +02:00
|
|
|
|
2020-07-09 04:45:00 +02:00
|
|
|
sqlsrv_query($conn, "DROP TABLE $tableName");
|
2017-05-04 02:09:36 +02:00
|
|
|
|
|
|
|
sqlsrv_close($conn);
|
|
|
|
|
|
|
|
?>
|
2020-07-09 04:45:00 +02:00
|
|
|
--EXPECT--
|
|
|
|
Done
|