php-sqlsrv/test/functional/sqlsrv/TC86_InsertNulls.phpt

78 lines
1.8 KiB
Plaintext
Raw Normal View History

2017-05-04 01:00:31 +02:00
--TEST--
PHP - Insert Nulls
--DESCRIPTION--
Test inserting nulls into nullable columns
--ENV--
PHPT_EXEC=true
--SKIPIF--
2017-10-27 18:44:46 +02:00
<?php require('skipif_versions_old.inc'); ?>
2017-05-04 01:00:31 +02:00
--FILE--
<?php
require_once('MsCommon.inc');
2017-05-04 01:00:31 +02:00
2017-10-11 01:54:20 +02:00
function insertNullsTest($phptype, $sqltype)
2017-05-04 01:00:31 +02:00
{
$outvar = null;
$failed = false;
setup();
2017-05-04 01:00:31 +02:00
$conn = AE\connect();
2017-05-04 01:00:31 +02:00
$tableName = 'TC86test';
dropTable($conn, $tableName);
2017-05-04 01:00:31 +02:00
AE\createTestTable($conn, $tableName);
2017-05-04 01:00:31 +02:00
2017-10-11 01:54:20 +02:00
$stmt = sqlsrv_query($conn, "SELECT [TABLE_NAME],[COLUMN_NAME],[IS_NULLABLE] FROM [INFORMATION_SCHEMA].[COLUMNS] WHERE [TABLE_NAME] = '$tableName'");
2017-05-04 01:00:31 +02:00
if ($stmt === false) {
fatalError("Could not query for column information on table $tableName");
2017-05-04 01:00:31 +02:00
}
while ($row = sqlsrv_fetch($stmt)) {
2017-05-04 01:00:31 +02:00
$tableName = sqlsrv_get_field($stmt, 0);
$columnName = sqlsrv_get_field($stmt, 1);
$nullable = sqlsrv_get_field($stmt, 2);
trace($columnName . ": " . $nullable . "\n");
if (($nullable == 'YES') && (strpos($columnName, "binary") !== false)) {
2017-10-11 01:54:20 +02:00
$stmt2 = sqlsrv_prepare($conn, "INSERT INTO [$tableName] ([" . $columnName . "]) VALUES (?)", array(array( null, SQLSRV_PARAM_IN, $phptype, $sqltype)));
2017-05-04 01:00:31 +02:00
if (!sqlsrv_execute($stmt2)) {
2017-05-04 01:00:31 +02:00
print_r(sqlsrv_errors(SQLSRV_ERR_ALL));
$failed = true;
}
}
}
dropTable($conn, $tableName);
2017-05-04 01:00:31 +02:00
return $failed;
}
2017-10-11 01:54:20 +02:00
$failed = null;
2017-05-04 01:00:31 +02:00
2017-10-11 01:54:20 +02:00
$testName = "PHP - Insert Nulls";
2017-05-04 01:00:31 +02:00
2017-10-11 01:54:20 +02:00
startTest($testName);
2017-05-04 01:00:31 +02:00
2017-10-11 01:54:20 +02:00
try {
$failed |= insertNullsTest(SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_BINARY), null);
$failed |= insertNullsTest(null, SQLSRV_SQLTYPE_VARBINARY('10'));
} catch (Exception $e) {
echo $e->getMessage();
}
2017-10-11 01:54:20 +02:00
if ($failed) {
fatalError("Possible Regression: Could not insert NULL");
2017-05-04 01:00:31 +02:00
}
2017-10-11 01:54:20 +02:00
endTest($testName);
2017-05-04 01:00:31 +02:00
?>
--EXPECT--
Test "PHP - Insert Nulls" completed successfully.