From 012cee3fba5a492b5ce83501cbf9b76f98cd3d2a Mon Sep 17 00:00:00 2001 From: Adam Baratz Date: Mon, 9 Jan 2017 11:13:13 -0500 Subject: [PATCH] Explicitly allow NULL values for dblib compatibility MSSQL won't necessarily default columns to NULL, see: https://msdn.microsoft.com/en-us/library/ms174979.aspx#Nullability Rules Within a Table Definition --- ext/pdo/tests/pdo_018.phpt | 13 ++++++++++++- ext/pdo/tests/pdo_024.phpt | 12 +++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/ext/pdo/tests/pdo_018.phpt b/ext/pdo/tests/pdo_018.phpt index 57430ae20d..f656d085c6 100644 --- a/ext/pdo/tests/pdo_018.phpt +++ b/ext/pdo/tests/pdo_018.phpt @@ -71,7 +71,18 @@ $db->exec('CREATE TABLE classtypes(id int NOT NULL PRIMARY KEY, name VARCHAR(20) $db->exec('INSERT INTO classtypes VALUES(0, \'stdClass\')'); $db->exec('INSERT INTO classtypes VALUES(1, \'TestBase\')'); $db->exec('INSERT INTO classtypes VALUES(2, \'TestDerived\')'); -$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(255))'); + +switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) { + case 'dblib': + // environment settings can influence how the table is created if specifics are missing + // https://msdn.microsoft.com/en-us/library/ms174979.aspx#Nullability Rules Within a Table Definition + $sql = 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int NULL, val VARCHAR(255) NULL)'; + break; + default: + $sql = 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(255))'; + break; +} +$db->exec($sql); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); diff --git a/ext/pdo/tests/pdo_024.phpt b/ext/pdo/tests/pdo_024.phpt index a70e924d49..5f4baf243d 100644 --- a/ext/pdo/tests/pdo_024.phpt +++ b/ext/pdo/tests/pdo_024.phpt @@ -14,7 +14,17 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE_ require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc'; $db = PDOTest::factory(); -$db->exec('create table test (id int, name varchar(10) null)'); +switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) { + case 'dblib': + // environment settings can influence how the table is created if specifics are missing + // https://msdn.microsoft.com/en-us/library/ms174979.aspx#Nullability Rules Within a Table Definition + $sql = 'create table test (id int, name varchar(10) null)'; + break; + default: + $sql = 'create table test (id int, name varchar(10))'; + break; +} +$db->exec($sql); $stmt = $db->prepare('insert into test (id, name) values(0, :name)'); $name = NULL; -- 2.50.1