Skip to content

Commit 012cee3

Browse files
committed
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
1 parent 14282b2 commit 012cee3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

ext/pdo/tests/pdo_018.phpt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,18 @@ $db->exec('CREATE TABLE classtypes(id int NOT NULL PRIMARY KEY, name VARCHAR(20)
7171
$db->exec('INSERT INTO classtypes VALUES(0, \'stdClass\')');
7272
$db->exec('INSERT INTO classtypes VALUES(1, \'TestBase\')');
7373
$db->exec('INSERT INTO classtypes VALUES(2, \'TestDerived\')');
74-
$db->exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(255))');
74+
75+
switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
76+
case 'dblib':
77+
// environment settings can influence how the table is created if specifics are missing
78+
// https://msdn.microsoft.com/en-us/library/ms174979.aspx#Nullability Rules Within a Table Definition
79+
$sql = 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int NULL, val VARCHAR(255) NULL)';
80+
break;
81+
default:
82+
$sql = 'CREATE TABLE test(id int NOT NULL PRIMARY KEY, classtype int, val VARCHAR(255))';
83+
break;
84+
}
85+
$db->exec($sql);
7586

7687
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
7788

ext/pdo/tests/pdo_024.phpt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE_
1414
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
1515
$db = PDOTest::factory();
1616

17-
$db->exec('create table test (id int, name varchar(10) null)');
17+
switch ($db->getAttribute(PDO::ATTR_DRIVER_NAME)) {
18+
case 'dblib':
19+
// environment settings can influence how the table is created if specifics are missing
20+
// https://msdn.microsoft.com/en-us/library/ms174979.aspx#Nullability Rules Within a Table Definition
21+
$sql = 'create table test (id int, name varchar(10) null)';
22+
break;
23+
default:
24+
$sql = 'create table test (id int, name varchar(10))';
25+
break;
26+
}
27+
$db->exec($sql);
1828

1929
$stmt = $db->prepare('insert into test (id, name) values(0, :name)');
2030
$name = NULL;

0 commit comments

Comments
 (0)