2017-03-31 00:20:42 +02:00
|
|
|
|
--TEST--
|
2017-03-31 01:30:54 +02:00
|
|
|
|
Insert with query params but with wrong parameters or types
|
2017-11-29 01:40:49 +01:00
|
|
|
|
--SKIPIF--
|
|
|
|
|
<?php require('skipif_versions_old.inc'); ?>
|
2017-03-31 00:20:42 +02:00
|
|
|
|
--FILE--
|
|
|
|
|
<?php
|
2017-10-04 23:22:56 +02:00
|
|
|
|
require_once('MsCommon.inc');
|
2017-03-31 00:20:42 +02:00
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
function createTableForTesting($conn, $tableName)
|
2017-03-31 00:20:42 +02:00
|
|
|
|
{
|
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-03-31 00:20:42 +02:00
|
|
|
|
sqlsrv_free_stmt($stmt);
|
2017-11-29 01:40:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getFirstInputParam()
|
|
|
|
|
{
|
|
|
|
|
$intType = AE\isColEncrypted() ? SQLSRV_SQLTYPE_INT : null;
|
|
|
|
|
return array(1, null, null, $intType);
|
|
|
|
|
}
|
2017-03-31 00:20:42 +02:00
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
function phpTypeMismatch($conn)
|
|
|
|
|
{
|
|
|
|
|
$tableName = 'phpTypeMismatch';
|
|
|
|
|
createTableForTesting($conn, $tableName);
|
|
|
|
|
|
|
|
|
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array(1.5, SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_FLOAT, SQLSRV_SQLTYPE_VARCHAR('max'))));
|
2017-03-31 00:20:42 +02:00
|
|
|
|
sqlsrv_free_stmt($stmt);
|
2017-10-04 23:22:56 +02:00
|
|
|
|
|
2017-03-31 00:20:42 +02:00
|
|
|
|
$stmt = sqlsrv_query($conn, "SELECT * FROM $tableName");
|
|
|
|
|
$result = sqlsrv_fetch($stmt);
|
2017-10-04 23:22:56 +02:00
|
|
|
|
if (! $result) {
|
2017-03-31 00:20:42 +02:00
|
|
|
|
echo "Fetch should succeed\n";
|
|
|
|
|
}
|
2017-03-31 23:19:12 +02:00
|
|
|
|
$value0 = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
|
|
|
|
$value1 = sqlsrv_get_field($stmt, 1, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
|
2017-10-04 23:22:56 +02:00
|
|
|
|
if ($value0 != "1" || $value1 != "1.5") {
|
2017-03-31 23:19:12 +02:00
|
|
|
|
echo "Data $value0 or $value1 unexpected\n";
|
|
|
|
|
}
|
2017-11-29 01:40:49 +01:00
|
|
|
|
|
|
|
|
|
dropTable($conn, $tableName);
|
2017-03-31 00:20:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
function dirInvalid($conn)
|
2017-03-31 00:20:42 +02:00
|
|
|
|
{
|
2017-11-29 01:40:49 +01:00
|
|
|
|
$tableName = 'dirInvalid';
|
|
|
|
|
createTableForTesting($conn, $tableName);
|
2017-03-31 00:20:42 +02:00
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", 32, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
|
2017-10-04 23:22:56 +02:00
|
|
|
|
printErrors();
|
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", 'SQLSRV_PARAM_INTERNAL', SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), SQLSRV_SQLTYPE_VARCHAR('max'))));
|
2017-03-31 00:20:42 +02:00
|
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
|
printErrors();
|
2017-11-29 01:40:49 +01:00
|
|
|
|
dropTable($conn, $tableName);
|
2017-03-31 00:20:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
function phpTypeEncoding($conn)
|
2017-03-31 00:20:42 +02:00
|
|
|
|
{
|
2017-11-29 01:40:49 +01:00
|
|
|
|
$tableName = 'phpTypeEncoding';
|
|
|
|
|
createTableForTesting($conn, $tableName);
|
2017-03-31 00:20:42 +02:00
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", SQLSRV_PARAM_IN, SQLSRV_PHPTYPE_STRING('SQLSRV_ENC_UNKNOWN'), null)));
|
2017-05-02 02:01:30 +02:00
|
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
|
printErrors();
|
2017-11-29 01:40:49 +01:00
|
|
|
|
dropTable($conn, $tableName);
|
2017-03-31 00:20:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
function phpTypeInvalid($conn)
|
2017-03-31 00:20:42 +02:00
|
|
|
|
{
|
2017-11-29 01:40:49 +01:00
|
|
|
|
$tableName = 'phpTypeInvalid';
|
|
|
|
|
createTableForTesting($conn, $tableName);
|
|
|
|
|
|
|
|
|
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", SQLSRV_PARAM_IN, 'SQLSRV_PHPTYPE_UNKNOWN', SQLSRV_SQLTYPE_VARCHAR('max'))));
|
2017-10-04 23:22:56 +02:00
|
|
|
|
printErrors();
|
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
$stmt = sqlsrv_query($conn, "INSERT INTO $tableName (c1_int, c2_varchar_max) VALUES (?, ?)", array(getFirstInputParam(), array("Test Data", SQLSRV_PARAM_IN, 6, SQLSRV_SQLTYPE_VARCHAR('max'))));
|
|
|
|
|
|
2017-10-04 23:22:56 +02:00
|
|
|
|
printErrors();
|
2017-11-29 01:40:49 +01:00
|
|
|
|
dropTable($conn, $tableName);
|
2017-03-31 00:20:42 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
echo "\nTest begins...\n";
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
sqlsrv_configure('WarningsReturnAsErrors', 1);
|
2017-03-31 00:20:42 +02:00
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
// connect
|
|
|
|
|
$conn = AE\connect();
|
2017-03-31 00:20:42 +02:00
|
|
|
|
|
2017-11-29 01:40:49 +01:00
|
|
|
|
phpTypeMismatch($conn);
|
|
|
|
|
dirInvalid($conn);
|
|
|
|
|
phpTypeEncoding($conn);
|
|
|
|
|
phpTypeInvalid($conn);
|
|
|
|
|
|
|
|
|
|
sqlsrv_close($conn);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
echo $e->getMessage();
|
|
|
|
|
}
|
|
|
|
|
echo "\nDone\n";
|
|
|
|
|
|
2017-03-31 00:20:42 +02:00
|
|
|
|
?>
|
|
|
|
|
--EXPECT--
|
|
|
|
|
|
2017-05-02 02:01:30 +02:00
|
|
|
|
Test begins...
|
2017-03-31 00:20:42 +02:00
|
|
|
|
An invalid direction for parameter 2 was specified. SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, and SQLSRV_PARAM_INOUT are valid values.
|
|
|
|
|
An invalid direction for parameter 2 was specified. SQLSRV_PARAM_IN, SQLSRV_PARAM_OUT, and SQLSRV_PARAM_INOUT are valid values.
|
|
|
|
|
An invalid PHP type for parameter 2 was specified.
|
|
|
|
|
An invalid PHP type for parameter 2 was specified.
|
|
|
|
|
An invalid PHP type for parameter 2 was specified.
|
|
|
|
|
|
|
|
|
|
Done
|